[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; |
| 572 | ssl_.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 573 | ASSERT_TRUE(ssl_.cert); |
| 574 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_); |
| 575 | } |
| 576 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 577 | void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
| 578 | int expected_status); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 579 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 580 | void ConnectStatusHelper(const MockRead& status); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 581 | |
| 582 | void BypassHostCacheOnRefreshHelper(int load_flags); |
| 583 | |
| 584 | void CheckErrorIsPassedBack(int error, IoMode mode); |
| 585 | |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 586 | SpdyTestUtil spdy_util_; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 587 | SpdySessionDependencies session_deps_; |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 588 | SSLSocketDataProvider ssl_; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 589 | |
| 590 | // Original socket limits. Some tests set these. Safest to always restore |
| 591 | // them once each test has been run. |
| 592 | int old_max_group_sockets_; |
| 593 | int old_max_pool_sockets_; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 594 | }; |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 595 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 596 | namespace { |
| 597 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 598 | class BeforeHeadersSentHandler { |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 599 | public: |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 600 | BeforeHeadersSentHandler() |
| 601 | : observed_before_headers_sent_with_proxy_(false), |
| 602 | observed_before_headers_sent_(false) {} |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 603 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 604 | void OnBeforeHeadersSent(const ProxyInfo& proxy_info, |
| 605 | HttpRequestHeaders* request_headers) { |
| 606 | observed_before_headers_sent_ = true; |
| 607 | if (!proxy_info.is_http() && !proxy_info.is_https() && |
| 608 | !proxy_info.is_quic()) { |
| 609 | return; |
| 610 | } |
| 611 | observed_before_headers_sent_with_proxy_ = true; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 612 | observed_proxy_server_uri_ = proxy_info.proxy_server().ToURI(); |
| 613 | } |
| 614 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 615 | bool observed_before_headers_sent_with_proxy() const { |
| 616 | return observed_before_headers_sent_with_proxy_; |
| 617 | } |
| 618 | |
| 619 | bool observed_before_headers_sent() const { |
| 620 | return observed_before_headers_sent_; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 621 | } |
| 622 | |
| 623 | std::string observed_proxy_server_uri() const { |
| 624 | return observed_proxy_server_uri_; |
| 625 | } |
| 626 | |
| 627 | private: |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 628 | bool observed_before_headers_sent_with_proxy_; |
| 629 | bool observed_before_headers_sent_; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 630 | std::string observed_proxy_server_uri_; |
| 631 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 632 | DISALLOW_COPY_AND_ASSIGN(BeforeHeadersSentHandler); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 633 | }; |
| 634 | |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 635 | // Fill |str| with a long header list that consumes >= |size| bytes. |
| 636 | void FillLargeHeadersString(std::string* str, int size) { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 637 | const char row[] = |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 638 | "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"; |
| 639 | const int sizeof_row = strlen(row); |
| 640 | const int num_rows = static_cast<int>( |
| 641 | ceil(static_cast<float>(size) / sizeof_row)); |
| 642 | const int sizeof_data = num_rows * sizeof_row; |
| 643 | DCHECK(sizeof_data >= size); |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 644 | str->reserve(sizeof_data); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 645 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 646 | for (int i = 0; i < num_rows; ++i) |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 647 | str->append(row, sizeof_row); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 648 | } |
| 649 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 650 | #if defined(NTLM_PORTABLE) |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 651 | uint64_t MockGetMSTime() { |
| 652 | // Tue, 23 May 2017 20:13:07 +0000 |
| 653 | return 131400439870000000; |
| 654 | } |
| 655 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 656 | // Alternative functions that eliminate randomness and dependency on the local |
| 657 | // host name so that the generated NTLM messages are reproducible. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 658 | void MockGenerateRandom(uint8_t* output, size_t n) { |
| 659 | // This is set to 0xaa because the client challenge for testing in |
| 660 | // [MS-NLMP] Section 4.2.1 is 8 bytes of 0xaa. |
| 661 | memset(output, 0xaa, n); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 662 | } |
| 663 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 664 | std::string MockGetHostName() { |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 665 | return ntlm::test::kHostnameAscii; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 666 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 667 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 668 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 669 | template<typename ParentPool> |
| 670 | class CaptureGroupNameSocketPool : public ParentPool { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 671 | public: |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 672 | CaptureGroupNameSocketPool(HostResolver* host_resolver, |
| 673 | CertVerifier* cert_verifier); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 674 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 675 | const std::string last_group_name_received() const { |
| 676 | return last_group_name_; |
| 677 | } |
| 678 | |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 679 | int RequestSocket(const std::string& group_name, |
| 680 | const void* socket_params, |
| 681 | RequestPriority priority, |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 682 | ClientSocketPool::RespectLimits respect_limits, |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 683 | ClientSocketHandle* handle, |
| 684 | const CompletionCallback& callback, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 685 | const NetLogWithSource& net_log) override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 686 | last_group_name_ = group_name; |
| 687 | return ERR_IO_PENDING; |
| 688 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 689 | void CancelRequest(const std::string& group_name, |
| 690 | ClientSocketHandle* handle) override {} |
| 691 | void ReleaseSocket(const std::string& group_name, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 692 | std::unique_ptr<StreamSocket> socket, |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 693 | int id) override {} |
| 694 | void CloseIdleSockets() override {} |
xunjieli | 92feb33 | 2017-03-03 17:19:23 | [diff] [blame] | 695 | void CloseIdleSocketsInGroup(const std::string& group_name) override {} |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 696 | int IdleSocketCount() const override { return 0; } |
| 697 | int IdleSocketCountInGroup(const std::string& group_name) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 698 | return 0; |
| 699 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 700 | LoadState GetLoadState(const std::string& group_name, |
| 701 | const ClientSocketHandle* handle) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 702 | return LOAD_STATE_IDLE; |
| 703 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 704 | base::TimeDelta ConnectionTimeout() const override { |
[email protected] | a796bcec | 2010-03-22 17:17:26 | [diff] [blame] | 705 | return base::TimeDelta(); |
| 706 | } |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 707 | |
| 708 | private: |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 709 | std::string last_group_name_; |
| 710 | }; |
| 711 | |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 712 | typedef CaptureGroupNameSocketPool<TransportClientSocketPool> |
| 713 | CaptureGroupNameTransportSocketPool; |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 714 | typedef CaptureGroupNameSocketPool<HttpProxyClientSocketPool> |
| 715 | CaptureGroupNameHttpProxySocketPool; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 716 | typedef CaptureGroupNameSocketPool<SOCKSClientSocketPool> |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 717 | CaptureGroupNameSOCKSSocketPool; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 718 | typedef CaptureGroupNameSocketPool<SSLClientSocketPool> |
| 719 | CaptureGroupNameSSLSocketPool; |
| 720 | |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 721 | template <typename ParentPool> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 722 | CaptureGroupNameSocketPool<ParentPool>::CaptureGroupNameSocketPool( |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 723 | HostResolver* host_resolver, |
| 724 | CertVerifier* /* cert_verifier */) |
tbansal | 7b403bcc | 2016-04-13 22:33:21 | [diff] [blame] | 725 | : ParentPool(0, 0, host_resolver, NULL, NULL, NULL) {} |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 726 | |
hashimoto | 0d3e4fb | 2015-01-09 05:02:50 | [diff] [blame] | 727 | template <> |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 728 | CaptureGroupNameHttpProxySocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 729 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 730 | CertVerifier* /* cert_verifier */) |
tbansal | 16196a1e | 2017-06-09 01:50:09 | [diff] [blame] | 731 | : HttpProxyClientSocketPool(0, 0, NULL, NULL, NULL, NULL) {} |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 732 | |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 733 | template <> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 734 | CaptureGroupNameSSLSocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 735 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 736 | CertVerifier* cert_verifier) |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 737 | : SSLClientSocketPool(0, |
| 738 | 0, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 739 | cert_verifier, |
| 740 | NULL, |
| 741 | NULL, |
[email protected] | 284303b6 | 2013-11-28 15:11:54 | [diff] [blame] | 742 | NULL, |
eranm | 6571b2b | 2014-12-03 15:53:23 | [diff] [blame] | 743 | NULL, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 744 | std::string(), |
| 745 | NULL, |
| 746 | NULL, |
| 747 | NULL, |
| 748 | NULL, |
| 749 | NULL, |
[email protected] | 8e45855 | 2014-08-05 00:02:15 | [diff] [blame] | 750 | NULL) { |
| 751 | } |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 752 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 753 | //----------------------------------------------------------------------------- |
| 754 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 755 | // Helper functions for validating that AuthChallengeInfo's are correctly |
| 756 | // configured for common cases. |
| 757 | bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 758 | if (!auth_challenge) |
| 759 | return false; |
| 760 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 761 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 762 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 763 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 764 | return true; |
| 765 | } |
| 766 | |
| 767 | bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 768 | if (!auth_challenge) |
| 769 | return false; |
| 770 | EXPECT_TRUE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 771 | EXPECT_EQ("http://myproxy:70", auth_challenge->challenger.Serialize()); |
| 772 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 773 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
| 774 | return true; |
| 775 | } |
| 776 | |
| 777 | bool CheckBasicSecureProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 778 | if (!auth_challenge) |
| 779 | return false; |
| 780 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 781 | EXPECT_EQ("https://myproxy:70", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 782 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 783 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 784 | return true; |
| 785 | } |
| 786 | |
| 787 | bool CheckDigestServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 788 | if (!auth_challenge) |
| 789 | return false; |
| 790 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 791 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 792 | EXPECT_EQ("digestive", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 793 | EXPECT_EQ(kDigestAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 794 | return true; |
| 795 | } |
| 796 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 797 | #if defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 798 | bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 799 | if (!auth_challenge) |
| 800 | return false; |
| 801 | EXPECT_FALSE(auth_challenge->is_proxy); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 802 | EXPECT_EQ("https://172.22.68.17", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 803 | EXPECT_EQ(std::string(), auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 804 | EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 805 | return true; |
| 806 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 807 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 808 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 809 | } // namespace |
| 810 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 811 | TEST_F(HttpNetworkTransactionTest, Basic) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 812 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 813 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 814 | } |
| 815 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 816 | TEST_F(HttpNetworkTransactionTest, SimpleGET) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 817 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 818 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 819 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 820 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 821 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 822 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 823 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 824 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 825 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 826 | EXPECT_EQ("hello world", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 827 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 828 | EXPECT_EQ(reads_size, out.total_received_bytes); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 829 | EXPECT_EQ(0u, out.connection_attempts.size()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 830 | |
| 831 | EXPECT_FALSE(out.remote_endpoint_after_start.address().empty()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 832 | } |
| 833 | |
| 834 | // Response with no status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 835 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeaders) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 836 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 837 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 838 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 839 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 840 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 841 | arraysize(data_reads)); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 842 | EXPECT_THAT(out.rv, IsOk()); |
| 843 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 844 | EXPECT_EQ("hello world", out.response_data); |
| 845 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 846 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 847 | } |
| 848 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 849 | // Response with no status line, and a weird port. Should fail by default. |
| 850 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPort) { |
| 851 | MockRead data_reads[] = { |
| 852 | MockRead("hello world"), MockRead(SYNCHRONOUS, OK), |
| 853 | }; |
| 854 | |
| 855 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 856 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 857 | |
| 858 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 859 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 860 | HttpRequestInfo request; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 861 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 862 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 863 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 864 | request.method = "GET"; |
| 865 | request.url = GURL("http://www.example.com:2000/"); |
| 866 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 867 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 868 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_INVALID_HTTP_RESPONSE)); |
| 869 | } |
| 870 | |
| 871 | // Response with no status line, and a weird port. Option to allow weird ports |
| 872 | // enabled. |
| 873 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPortAllowed) { |
| 874 | MockRead data_reads[] = { |
| 875 | MockRead("hello world"), MockRead(SYNCHRONOUS, OK), |
| 876 | }; |
| 877 | |
| 878 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 879 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 880 | session_deps_.http_09_on_non_default_ports_enabled = true; |
| 881 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 882 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 883 | HttpRequestInfo request; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 884 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 885 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 886 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 887 | request.method = "GET"; |
| 888 | request.url = GURL("http://www.example.com:2000/"); |
| 889 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 890 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 891 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 892 | |
| 893 | const HttpResponseInfo* info = trans->GetResponseInfo(); |
| 894 | ASSERT_TRUE(info->headers); |
| 895 | EXPECT_EQ("HTTP/0.9 200 OK", info->headers->GetStatusLine()); |
| 896 | |
| 897 | // Don't bother to read the body - that's verified elsewhere, important thing |
| 898 | // is that the option to allow HTTP/0.9 on non-default ports is respected. |
| 899 | } |
| 900 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 901 | // Allow up to 4 bytes of junk to precede status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 902 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk3Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 903 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 904 | MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 905 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 906 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 907 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 908 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 909 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 910 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 911 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 912 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 913 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 914 | } |
| 915 | |
| 916 | // Allow up to 4 bytes of junk to precede status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 917 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 918 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 919 | MockRead("\n\nQJHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 920 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 921 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 922 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 923 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 924 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 925 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 926 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 927 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 928 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 929 | } |
| 930 | |
| 931 | // Beyond 4 bytes of slop and it should fail to find a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 932 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk5Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 933 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 934 | MockRead("xxxxxHTTP/1.1 404 Not Found\nServer: blah"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 935 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 936 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 937 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 938 | arraysize(data_reads)); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 939 | EXPECT_THAT(out.rv, IsOk()); |
| 940 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 941 | EXPECT_EQ("xxxxxHTTP/1.1 404 Not Found\nServer: blah", out.response_data); |
| 942 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 943 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 944 | } |
| 945 | |
| 946 | // Same as StatusLineJunk4Bytes, except the read chunks are smaller. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 947 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes_Slow) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 948 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 949 | MockRead("\n"), |
| 950 | MockRead("\n"), |
| 951 | MockRead("Q"), |
| 952 | MockRead("J"), |
| 953 | MockRead("HTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 954 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 955 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 956 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 957 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 958 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 959 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 960 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 961 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 962 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 963 | } |
| 964 | |
| 965 | // Close the connection before enough bytes to have a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 966 | TEST_F(HttpNetworkTransactionTest, StatusLinePartial) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 967 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 968 | MockRead("HTT"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 969 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 970 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 971 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 972 | arraysize(data_reads)); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 973 | EXPECT_THAT(out.rv, IsOk()); |
| 974 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 975 | EXPECT_EQ("HTT", out.response_data); |
| 976 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 977 | EXPECT_EQ(reads_size, out.total_received_bytes); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 978 | } |
| 979 | |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 980 | // Simulate a 204 response, lacking a Content-Length header, sent over a |
| 981 | // persistent connection. The response should still terminate since a 204 |
| 982 | // cannot have a response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 983 | TEST_F(HttpNetworkTransactionTest, StopsReading204) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 984 | char junk[] = "junk"; |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 985 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 986 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 987 | MockRead(junk), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 988 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 989 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 990 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 991 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 992 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 993 | EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); |
| 994 | EXPECT_EQ("", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 995 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 996 | int64_t response_size = reads_size - strlen(junk); |
| 997 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 998 | } |
| 999 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1000 | // A simple request using chunked encoding with some extra data after. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1001 | TEST_F(HttpNetworkTransactionTest, ChunkedEncoding) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1002 | std::string final_chunk = "0\r\n\r\n"; |
| 1003 | std::string extra_data = "HTTP/1.1 200 OK\r\n"; |
| 1004 | std::string last_read = final_chunk + extra_data; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1005 | MockRead data_reads[] = { |
| 1006 | MockRead("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"), |
| 1007 | MockRead("5\r\nHello\r\n"), |
| 1008 | MockRead("1\r\n"), |
| 1009 | MockRead(" \r\n"), |
| 1010 | MockRead("5\r\nworld\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1011 | MockRead(last_read.data()), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1012 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1013 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1014 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1015 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1016 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1017 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1018 | EXPECT_EQ("Hello world", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 1019 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 1020 | int64_t response_size = reads_size - extra_data.size(); |
| 1021 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1022 | } |
| 1023 | |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1024 | // Next tests deal with http://crbug.com/56344. |
| 1025 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1026 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1027 | MultipleContentLengthHeadersNoTransferEncoding) { |
| 1028 | MockRead data_reads[] = { |
| 1029 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1030 | MockRead("Content-Length: 10\r\n"), |
| 1031 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1032 | }; |
| 1033 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1034 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1035 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1036 | } |
| 1037 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1038 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1039 | DuplicateContentLengthHeadersNoTransferEncoding) { |
| 1040 | MockRead data_reads[] = { |
| 1041 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1042 | MockRead("Content-Length: 5\r\n"), |
| 1043 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1044 | MockRead("Hello"), |
| 1045 | }; |
| 1046 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1047 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1048 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1049 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1050 | EXPECT_EQ("Hello", out.response_data); |
| 1051 | } |
| 1052 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1053 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1054 | ComplexContentLengthHeadersNoTransferEncoding) { |
| 1055 | // More than 2 dupes. |
| 1056 | { |
| 1057 | MockRead data_reads[] = { |
| 1058 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1059 | MockRead("Content-Length: 5\r\n"), |
| 1060 | MockRead("Content-Length: 5\r\n"), |
| 1061 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1062 | MockRead("Hello"), |
| 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, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1067 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1068 | EXPECT_EQ("Hello", out.response_data); |
| 1069 | } |
| 1070 | // HTTP/1.0 |
| 1071 | { |
| 1072 | MockRead data_reads[] = { |
| 1073 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1074 | MockRead("Content-Length: 5\r\n"), |
| 1075 | MockRead("Content-Length: 5\r\n"), |
| 1076 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1077 | MockRead("Hello"), |
| 1078 | }; |
| 1079 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1080 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1081 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1082 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 1083 | EXPECT_EQ("Hello", out.response_data); |
| 1084 | } |
| 1085 | // 2 dupes and one mismatched. |
| 1086 | { |
| 1087 | MockRead data_reads[] = { |
| 1088 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1089 | MockRead("Content-Length: 10\r\n"), |
| 1090 | MockRead("Content-Length: 10\r\n"), |
| 1091 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1092 | }; |
| 1093 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1094 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1095 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1096 | } |
| 1097 | } |
| 1098 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1099 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1100 | MultipleContentLengthHeadersTransferEncoding) { |
| 1101 | MockRead data_reads[] = { |
| 1102 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1103 | MockRead("Content-Length: 666\r\n"), |
| 1104 | MockRead("Content-Length: 1337\r\n"), |
| 1105 | MockRead("Transfer-Encoding: chunked\r\n\r\n"), |
| 1106 | MockRead("5\r\nHello\r\n"), |
| 1107 | MockRead("1\r\n"), |
| 1108 | MockRead(" \r\n"), |
| 1109 | MockRead("5\r\nworld\r\n"), |
| 1110 | MockRead("0\r\n\r\nHTTP/1.1 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1111 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1112 | }; |
| 1113 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1114 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1115 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1116 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1117 | EXPECT_EQ("Hello world", out.response_data); |
| 1118 | } |
| 1119 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1120 | // Next tests deal with http://crbug.com/98895. |
| 1121 | |
| 1122 | // Checks that a single Content-Disposition header results in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1123 | TEST_F(HttpNetworkTransactionTest, SingleContentDispositionHeader) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1124 | MockRead data_reads[] = { |
| 1125 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1126 | MockRead("Content-Disposition: attachment;filename=\"salutations.txt\"r\n"), |
| 1127 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1128 | MockRead("Hello"), |
| 1129 | }; |
| 1130 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1131 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1132 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1133 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1134 | EXPECT_EQ("Hello", out.response_data); |
| 1135 | } |
| 1136 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1137 | // Checks that two identical Content-Disposition headers result in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1138 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1139 | MockRead data_reads[] = { |
| 1140 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1141 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1142 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1143 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1144 | MockRead("Hello"), |
| 1145 | }; |
| 1146 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1147 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1148 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1149 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1150 | EXPECT_EQ("Hello", out.response_data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1151 | } |
| 1152 | |
| 1153 | // Checks that two distinct Content-Disposition headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1154 | TEST_F(HttpNetworkTransactionTest, TwoDistinctContentDispositionHeaders) { |
[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=\"greetings.txt\"r\n"), |
| 1158 | MockRead("Content-Disposition: attachment;filename=\"hi.txt\"r\n"), |
| 1159 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1160 | MockRead("Hello"), |
| 1161 | }; |
| 1162 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1163 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1164 | EXPECT_THAT(out.rv, |
| 1165 | IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1166 | } |
| 1167 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1168 | // Checks that two identical Location headers result in no error. |
| 1169 | // Also tests Location header behavior. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1170 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1171 | MockRead data_reads[] = { |
| 1172 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1173 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1174 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1175 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1176 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1177 | }; |
| 1178 | |
| 1179 | HttpRequestInfo request; |
| 1180 | request.method = "GET"; |
| 1181 | request.url = GURL("http://redirect.com/"); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1182 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1183 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1184 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1185 | |
| 1186 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1187 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1188 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1189 | TestCompletionCallback callback; |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1190 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1191 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1192 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1193 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1194 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1195 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1196 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1197 | ASSERT_TRUE(response); |
| 1198 | ASSERT_TRUE(response->headers); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1199 | EXPECT_EQ("HTTP/1.1 302 Redirect", response->headers->GetStatusLine()); |
| 1200 | std::string url; |
| 1201 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 1202 | EXPECT_EQ("http://good.com/", url); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1203 | EXPECT_TRUE(response->proxy_server.is_direct()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1204 | } |
| 1205 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1206 | // Checks that two distinct Location headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1207 | TEST_F(HttpNetworkTransactionTest, TwoDistinctLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1208 | MockRead data_reads[] = { |
| 1209 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1210 | MockRead("Location: http://good.com/\r\n"), |
| 1211 | MockRead("Location: http://evil.com/\r\n"), |
| 1212 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1213 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1214 | }; |
| 1215 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1216 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1217 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1218 | } |
| 1219 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1220 | // Do a request using the HEAD method. Verify that we don't try to read the |
| 1221 | // message body (since HEAD has none). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1222 | TEST_F(HttpNetworkTransactionTest, Head) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1223 | HttpRequestInfo request; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1224 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1225 | request.url = GURL("http://www.example.org/"); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1226 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1227 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1228 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1229 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1230 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1231 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 1232 | base::Unretained(&headers_handler))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1233 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1234 | MockWrite data_writes1[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 1235 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 1236 | "Host: www.example.org\r\n" |
| 1237 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1238 | }; |
| 1239 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1240 | MockRead("HTTP/1.1 404 Not Found\r\n"), MockRead("Server: Blah\r\n"), |
| 1241 | MockRead("Content-Length: 1234\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1242 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1243 | // No response body because the test stops reading here. |
| 1244 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1245 | }; |
| 1246 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1247 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 1248 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1249 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1250 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1251 | TestCompletionCallback callback1; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1252 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1253 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1254 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1255 | |
| 1256 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1257 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1258 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1259 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1260 | ASSERT_TRUE(response); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1261 | |
| 1262 | // Check that the headers got parsed. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1263 | EXPECT_TRUE(response->headers); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1264 | EXPECT_EQ(1234, response->headers->GetContentLength()); |
| 1265 | EXPECT_EQ("HTTP/1.1 404 Not Found", response->headers->GetStatusLine()); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1266 | EXPECT_TRUE(response->proxy_server.is_direct()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1267 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 1268 | EXPECT_FALSE(headers_handler.observed_before_headers_sent_with_proxy()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1269 | |
| 1270 | std::string server_header; |
olli.raula | ee489a5 | 2016-01-25 08:37:10 | [diff] [blame] | 1271 | size_t iter = 0; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1272 | bool has_server_header = response->headers->EnumerateHeader( |
| 1273 | &iter, "Server", &server_header); |
| 1274 | EXPECT_TRUE(has_server_header); |
| 1275 | EXPECT_EQ("Blah", server_header); |
| 1276 | |
| 1277 | // Reading should give EOF right away, since there is no message body |
| 1278 | // (despite non-zero content-length). |
| 1279 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1280 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1281 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1282 | EXPECT_EQ("", response_data); |
| 1283 | } |
| 1284 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1285 | TEST_F(HttpNetworkTransactionTest, ReuseConnection) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1286 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1287 | |
| 1288 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1289 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1290 | MockRead("hello"), |
| 1291 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1292 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1293 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1294 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1295 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1296 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1297 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1298 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1299 | "hello", "world" |
| 1300 | }; |
| 1301 | |
| 1302 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1303 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1304 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1305 | request.url = GURL("http://www.example.org/"); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1306 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1307 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1308 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1309 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1310 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1311 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1312 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1313 | |
| 1314 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1315 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1316 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1317 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1318 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1319 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1320 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1321 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1322 | EXPECT_TRUE(response->proxy_server.is_direct()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1323 | |
| 1324 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1325 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1326 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1327 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1328 | } |
| 1329 | } |
| 1330 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1331 | TEST_F(HttpNetworkTransactionTest, Ignores100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1332 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1333 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 1334 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1335 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1336 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1337 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1338 | request.method = "POST"; |
| 1339 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1340 | request.upload_data_stream = &upload_data_stream; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1341 | |
shivanisha | b9a14395 | 2016-09-19 17:23:41 | [diff] [blame] | 1342 | // Check the upload progress returned before initialization is correct. |
| 1343 | UploadProgress progress = request.upload_data_stream->GetUploadProgress(); |
| 1344 | EXPECT_EQ(0u, progress.size()); |
| 1345 | EXPECT_EQ(0u, progress.position()); |
| 1346 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1347 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1348 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1349 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1350 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1351 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 1352 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 1353 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1354 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1355 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1356 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1357 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1358 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1359 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1360 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1361 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1362 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1363 | |
| 1364 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1365 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1366 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1367 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1368 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1369 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1370 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1371 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1372 | |
| 1373 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1374 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1375 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1376 | EXPECT_EQ("hello world", response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1377 | } |
| 1378 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1379 | // This test is almost the same as Ignores100 above, but the response contains |
| 1380 | // 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] | 1381 | // HTTP/1.1 and the two status headers are read in one read. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1382 | TEST_F(HttpNetworkTransactionTest, Ignores1xx) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1383 | HttpRequestInfo request; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1384 | request.method = "GET"; |
| 1385 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1386 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1387 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1388 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1389 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1390 | MockRead data_reads[] = { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1391 | MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n" |
| 1392 | "HTTP/1.1 200 OK\r\n\r\n"), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1393 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1394 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1395 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1396 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1397 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1398 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1399 | TestCompletionCallback callback; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1400 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1401 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1402 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1403 | |
| 1404 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1405 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1406 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1407 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1408 | ASSERT_TRUE(response); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1409 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1410 | EXPECT_TRUE(response->headers); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1411 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1412 | |
| 1413 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1414 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1415 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1416 | EXPECT_EQ("hello world", response_data); |
| 1417 | } |
| 1418 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1419 | TEST_F(HttpNetworkTransactionTest, Incomplete100ThenEOF) { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1420 | HttpRequestInfo request; |
| 1421 | request.method = "POST"; |
| 1422 | request.url = GURL("http://www.foo.com/"); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1423 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1424 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1425 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1426 | |
| 1427 | MockRead data_reads[] = { |
| 1428 | MockRead(SYNCHRONOUS, "HTTP/1.0 100 Continue\r\n"), |
| 1429 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1430 | }; |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1431 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 1432 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1433 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1434 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1435 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1436 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1437 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1438 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1439 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1440 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1441 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1442 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1443 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1444 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1445 | EXPECT_EQ("", response_data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1446 | } |
| 1447 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1448 | TEST_F(HttpNetworkTransactionTest, EmptyResponse) { |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1449 | HttpRequestInfo request; |
| 1450 | request.method = "POST"; |
| 1451 | request.url = GURL("http://www.foo.com/"); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1452 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1453 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1454 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1455 | |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1456 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1457 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1458 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1459 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1460 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1461 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1462 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1463 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1464 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1465 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1466 | |
| 1467 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1468 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1469 | } |
| 1470 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1471 | void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest( |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1472 | const MockWrite* write_failure, |
| 1473 | const MockRead* read_failure) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1474 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1475 | request.method = "GET"; |
| 1476 | request.url = GURL("http://www.foo.com/"); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1477 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1478 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1479 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1480 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1481 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1482 | // Written data for successfully sending both requests. |
| 1483 | MockWrite data1_writes[] = { |
| 1484 | MockWrite("GET / HTTP/1.1\r\n" |
| 1485 | "Host: www.foo.com\r\n" |
| 1486 | "Connection: keep-alive\r\n\r\n"), |
| 1487 | MockWrite("GET / HTTP/1.1\r\n" |
| 1488 | "Host: www.foo.com\r\n" |
| 1489 | "Connection: keep-alive\r\n\r\n") |
| 1490 | }; |
| 1491 | |
| 1492 | // Read results for the first request. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1493 | MockRead data1_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1494 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1495 | MockRead("hello"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1496 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1497 | }; |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1498 | |
| 1499 | if (write_failure) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1500 | ASSERT_FALSE(read_failure); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1501 | data1_writes[1] = *write_failure; |
| 1502 | } else { |
| 1503 | ASSERT_TRUE(read_failure); |
| 1504 | data1_reads[2] = *read_failure; |
| 1505 | } |
| 1506 | |
| 1507 | StaticSocketDataProvider data1(data1_reads, arraysize(data1_reads), |
| 1508 | data1_writes, arraysize(data1_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1509 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1510 | |
| 1511 | MockRead data2_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1512 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1513 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1514 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1515 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1516 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1517 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1518 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 1519 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1520 | "hello", "world" |
| 1521 | }; |
| 1522 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 1523 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1524 | for (int i = 0; i < 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1525 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1526 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1527 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1528 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1529 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1530 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1531 | |
| 1532 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1533 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1534 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1535 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1536 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1537 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1538 | if (i == 0) { |
| 1539 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1540 | } else { |
| 1541 | // The second request should be using a new socket. |
| 1542 | EXPECT_NE(first_socket_log_id, load_timing_info.socket_log_id); |
| 1543 | } |
| 1544 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1545 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1546 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1547 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1548 | EXPECT_TRUE(response->headers); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1549 | EXPECT_TRUE(response->proxy_server.is_direct()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1550 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1551 | |
| 1552 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1553 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1554 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1555 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1556 | } |
| 1557 | } |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1558 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1559 | void HttpNetworkTransactionTest::PreconnectErrorResendRequestTest( |
| 1560 | const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1561 | const MockRead* read_failure, |
| 1562 | bool use_spdy) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1563 | HttpRequestInfo request; |
| 1564 | request.method = "GET"; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1565 | request.url = GURL("https://www.foo.com/"); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1566 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1567 | TestNetLog net_log; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1568 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1569 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1570 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1571 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 1572 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 1573 | if (use_spdy) { |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 1574 | ssl1.next_proto = kProtoHTTP2; |
| 1575 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1576 | } |
| 1577 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 1578 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1579 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1580 | // SPDY versions of the request and response. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1581 | SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1582 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1583 | SpdySerializedFrame spdy_response( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1584 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1585 | SpdySerializedFrame spdy_data( |
| 1586 | spdy_util_.ConstructSpdyDataFrame(1, "hello", 5, true)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1587 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1588 | // HTTP/1.1 versions of the request and response. |
| 1589 | const char kHttpRequest[] = "GET / HTTP/1.1\r\n" |
| 1590 | "Host: www.foo.com\r\n" |
| 1591 | "Connection: keep-alive\r\n\r\n"; |
| 1592 | const char kHttpResponse[] = "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"; |
| 1593 | const char kHttpData[] = "hello"; |
| 1594 | |
| 1595 | std::vector<MockRead> data1_reads; |
| 1596 | std::vector<MockWrite> data1_writes; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1597 | if (write_failure) { |
| 1598 | ASSERT_FALSE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1599 | data1_writes.push_back(*write_failure); |
| 1600 | data1_reads.push_back(MockRead(ASYNC, OK)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1601 | } else { |
| 1602 | ASSERT_TRUE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1603 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1604 | data1_writes.push_back(CreateMockWrite(spdy_request)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1605 | } else { |
| 1606 | data1_writes.push_back(MockWrite(kHttpRequest)); |
| 1607 | } |
| 1608 | data1_reads.push_back(*read_failure); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1609 | } |
| 1610 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1611 | StaticSocketDataProvider data1(&data1_reads[0], data1_reads.size(), |
| 1612 | &data1_writes[0], data1_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1613 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1614 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1615 | std::vector<MockRead> data2_reads; |
| 1616 | std::vector<MockWrite> data2_writes; |
| 1617 | |
| 1618 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1619 | data2_writes.push_back(CreateMockWrite(spdy_request, 0, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1620 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1621 | data2_reads.push_back(CreateMockRead(spdy_response, 1, ASYNC)); |
| 1622 | data2_reads.push_back(CreateMockRead(spdy_data, 2, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1623 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1624 | } else { |
| 1625 | data2_writes.push_back( |
| 1626 | MockWrite(ASYNC, kHttpRequest, strlen(kHttpRequest), 0)); |
| 1627 | |
| 1628 | data2_reads.push_back( |
| 1629 | MockRead(ASYNC, kHttpResponse, strlen(kHttpResponse), 1)); |
| 1630 | data2_reads.push_back(MockRead(ASYNC, kHttpData, strlen(kHttpData), 2)); |
| 1631 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1632 | } |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 1633 | SequencedSocketData data2(&data2_reads[0], data2_reads.size(), |
| 1634 | &data2_writes[0], data2_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1635 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1636 | |
| 1637 | // Preconnect a socket. |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 1638 | session->http_stream_factory()->PreconnectStreams(1, request); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1639 | // Wait for the preconnect to complete. |
| 1640 | // TODO(davidben): Some way to wait for an idle socket count might be handy. |
| 1641 | base::RunLoop().RunUntilIdle(); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1642 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1643 | |
| 1644 | // Make the request. |
| 1645 | TestCompletionCallback callback; |
| 1646 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1647 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1648 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1649 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1650 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1651 | |
| 1652 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1653 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1654 | |
| 1655 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1656 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1657 | TestLoadTimingNotReused( |
| 1658 | load_timing_info, |
| 1659 | CONNECT_TIMING_HAS_DNS_TIMES|CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1660 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1661 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1662 | ASSERT_TRUE(response); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1663 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1664 | EXPECT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1665 | if (response->was_fetched_via_spdy) { |
| 1666 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 1667 | } else { |
| 1668 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1669 | } |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1670 | |
| 1671 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1672 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1673 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1674 | EXPECT_EQ(kHttpData, response_data); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1675 | } |
| 1676 | |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1677 | // Test that we do not retry indefinitely when a server sends an error like |
| 1678 | // ERR_SPDY_PING_FAILED, ERR_SPDY_SERVER_REFUSED_STREAM, |
| 1679 | // ERR_QUIC_HANDSHAKE_FAILED or ERR_QUIC_PROTOCOL_ERROR. |
| 1680 | TEST_F(HttpNetworkTransactionTest, FiniteRetriesOnIOError) { |
| 1681 | HttpRequestInfo request; |
| 1682 | request.method = "GET"; |
| 1683 | request.url = GURL("https://www.foo.com/"); |
| 1684 | |
| 1685 | // Check whether we give up after the third try. |
| 1686 | |
| 1687 | // Construct an HTTP2 request and a "Go away" response. |
| 1688 | SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
| 1689 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
| 1690 | SpdySerializedFrame spdy_response_go_away(spdy_util_.ConstructSpdyGoAway()); |
| 1691 | MockRead data_read1 = CreateMockRead(spdy_response_go_away); |
| 1692 | MockWrite data_write = CreateMockWrite(spdy_request, 0); |
| 1693 | |
| 1694 | // Three go away responses. |
| 1695 | StaticSocketDataProvider data1(&data_read1, 1, &data_write, 1); |
| 1696 | StaticSocketDataProvider data2(&data_read1, 1, &data_write, 1); |
| 1697 | StaticSocketDataProvider data3(&data_read1, 1, &data_write, 1); |
| 1698 | |
| 1699 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1700 | AddSSLSocketData(); |
| 1701 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1702 | AddSSLSocketData(); |
| 1703 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 1704 | AddSSLSocketData(); |
| 1705 | |
| 1706 | TestCompletionCallback callback; |
| 1707 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1708 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1709 | |
| 1710 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1711 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1712 | |
| 1713 | rv = callback.WaitForResult(); |
| 1714 | EXPECT_THAT(rv, IsError(ERR_SPDY_SERVER_REFUSED_STREAM)); |
| 1715 | } |
| 1716 | |
| 1717 | TEST_F(HttpNetworkTransactionTest, RetryTwiceOnIOError) { |
| 1718 | HttpRequestInfo request; |
| 1719 | request.method = "GET"; |
| 1720 | request.url = GURL("https://www.foo.com/"); |
| 1721 | |
| 1722 | // Check whether we try atleast thrice before giving up. |
| 1723 | |
| 1724 | // Construct an HTTP2 request and a "Go away" response. |
| 1725 | SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
| 1726 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
| 1727 | SpdySerializedFrame spdy_response_go_away(spdy_util_.ConstructSpdyGoAway()); |
| 1728 | MockRead data_read1 = CreateMockRead(spdy_response_go_away); |
| 1729 | MockWrite data_write = CreateMockWrite(spdy_request, 0); |
| 1730 | |
| 1731 | // Construct a non error HTTP2 response. |
| 1732 | SpdySerializedFrame spdy_response_no_error( |
| 1733 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 1734 | SpdySerializedFrame spdy_data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 1735 | MockRead data_read2[] = {CreateMockRead(spdy_response_no_error, 1), |
| 1736 | CreateMockRead(spdy_data, 2)}; |
| 1737 | |
| 1738 | // Two error responses. |
| 1739 | StaticSocketDataProvider data1(&data_read1, 1, &data_write, 1); |
| 1740 | StaticSocketDataProvider data2(&data_read1, 1, &data_write, 1); |
| 1741 | // Followed by a success response. |
| 1742 | SequencedSocketData data3(data_read2, 2, &data_write, 1); |
| 1743 | |
| 1744 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1745 | AddSSLSocketData(); |
| 1746 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1747 | AddSSLSocketData(); |
| 1748 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 1749 | AddSSLSocketData(); |
| 1750 | |
| 1751 | TestCompletionCallback callback; |
| 1752 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1753 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1754 | |
| 1755 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1756 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1757 | |
| 1758 | rv = callback.WaitForResult(); |
| 1759 | EXPECT_THAT(rv, IsOk()); |
| 1760 | } |
| 1761 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1762 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionNotConnectedOnWrite) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1763 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1764 | KeepAliveConnectionResendRequestTest(&write_failure, NULL); |
| 1765 | } |
| 1766 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1767 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionReset) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1768 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1769 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1770 | } |
| 1771 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1772 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1773 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1774 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1775 | } |
| 1776 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1777 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1778 | // if the socket was a reused keep alive socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1779 | TEST_F(HttpNetworkTransactionTest, KeepAlive408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1780 | MockRead read_failure(SYNCHRONOUS, |
| 1781 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1782 | "Connection: Keep-Alive\r\n" |
| 1783 | "Content-Length: 6\r\n\r\n" |
| 1784 | "Pickle"); |
| 1785 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1786 | } |
| 1787 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1788 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorNotConnectedOnWrite) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1789 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1790 | PreconnectErrorResendRequestTest(&write_failure, NULL, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1791 | } |
| 1792 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1793 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorReset) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1794 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1795 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1796 | } |
| 1797 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1798 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorEOF) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1799 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1800 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1801 | } |
| 1802 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1803 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1804 | MockRead read_failure(ASYNC, OK); // EOF |
| 1805 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 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 preconnected (UNUSED_IDLE) socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1810 | TEST_F(HttpNetworkTransactionTest, RetryOnIdle408) { |
[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 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1818 | } |
| 1819 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1820 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorNotConnectedOnWrite) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1821 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
| 1822 | PreconnectErrorResendRequestTest(&write_failure, NULL, true); |
| 1823 | } |
| 1824 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1825 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorReset) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1826 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
| 1827 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1828 | } |
| 1829 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1830 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1831 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
| 1832 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1833 | } |
| 1834 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1835 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1836 | MockRead read_failure(ASYNC, OK); // EOF |
| 1837 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1838 | } |
| 1839 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1840 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1841 | HttpRequestInfo request; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1842 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1843 | request.url = GURL("http://www.example.org/"); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1844 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1845 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1846 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1847 | |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1848 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1849 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1850 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1851 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1852 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1853 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1854 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1855 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1856 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1857 | TestCompletionCallback callback; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1858 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1859 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1860 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1861 | |
| 1862 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1863 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 1864 | |
| 1865 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1866 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 1867 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1868 | } |
| 1869 | |
| 1870 | // What do various browsers do when the server closes a non-keepalive |
| 1871 | // connection without sending any response header or body? |
| 1872 | // |
| 1873 | // IE7: error page |
| 1874 | // Safari 3.1.2 (Windows): error page |
| 1875 | // Firefox 3.0.1: blank page |
| 1876 | // Opera 9.52: after five attempts, blank page |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1877 | // Us with WinHTTP: error page (ERR_INVALID_RESPONSE) |
| 1878 | // Us: error page (EMPTY_RESPONSE) |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1879 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionEOF) { |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1880 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1881 | MockRead(SYNCHRONOUS, OK), // EOF |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1882 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1883 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1884 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1885 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1886 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1887 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1888 | EXPECT_THAT(out.rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1889 | } |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1890 | |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1891 | // Next 2 cases (KeepAliveEarlyClose and KeepAliveEarlyClose2) are regression |
| 1892 | // tests. There was a bug causing HttpNetworkTransaction to hang in the |
| 1893 | // destructor in such situations. |
| 1894 | // See http://crbug.com/154712 and http://crbug.com/156609. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1895 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1896 | HttpRequestInfo request; |
| 1897 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1898 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1899 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1900 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 1901 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 1902 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1903 | |
| 1904 | MockRead data_reads[] = { |
| 1905 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1906 | MockRead("Connection: keep-alive\r\n"), |
| 1907 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1908 | MockRead("hello"), |
| 1909 | MockRead(SYNCHRONOUS, 0), |
| 1910 | }; |
| 1911 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1912 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1913 | |
| 1914 | TestCompletionCallback callback; |
| 1915 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1916 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1917 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1918 | |
| 1919 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1920 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1921 | |
| 1922 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1923 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1924 | if (rv == ERR_IO_PENDING) |
| 1925 | rv = callback.WaitForResult(); |
| 1926 | EXPECT_EQ(5, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1927 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1928 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1929 | |
| 1930 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 1931 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1932 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1933 | } |
| 1934 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1935 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose2) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1936 | HttpRequestInfo request; |
| 1937 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1938 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1939 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1940 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 1941 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 1942 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1943 | |
| 1944 | MockRead data_reads[] = { |
| 1945 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1946 | MockRead("Connection: keep-alive\r\n"), |
| 1947 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1948 | MockRead(SYNCHRONOUS, 0), |
| 1949 | }; |
| 1950 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1951 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1952 | |
| 1953 | TestCompletionCallback callback; |
| 1954 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1955 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1956 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1957 | |
| 1958 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1959 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1960 | |
| 1961 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1962 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1963 | if (rv == ERR_IO_PENDING) |
| 1964 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1965 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1966 | |
| 1967 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 1968 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1969 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1970 | } |
| 1971 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1972 | // Test that we correctly reuse a keep-alive connection after not explicitly |
| 1973 | // reading the body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1974 | TEST_F(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) { |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1975 | HttpRequestInfo request; |
| 1976 | request.method = "GET"; |
| 1977 | request.url = GURL("http://www.foo.com/"); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1978 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1979 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1980 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1981 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1982 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1983 | const char* request_data = |
| 1984 | "GET / HTTP/1.1\r\n" |
| 1985 | "Host: www.foo.com\r\n" |
| 1986 | "Connection: keep-alive\r\n\r\n"; |
| 1987 | MockWrite data_writes[] = { |
| 1988 | MockWrite(ASYNC, 0, request_data), MockWrite(ASYNC, 2, request_data), |
| 1989 | MockWrite(ASYNC, 4, request_data), MockWrite(ASYNC, 6, request_data), |
| 1990 | MockWrite(ASYNC, 8, request_data), MockWrite(ASYNC, 10, request_data), |
| 1991 | MockWrite(ASYNC, 12, request_data), MockWrite(ASYNC, 14, request_data), |
| 1992 | MockWrite(ASYNC, 17, request_data), MockWrite(ASYNC, 20, request_data), |
| 1993 | }; |
| 1994 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1995 | // Note that because all these reads happen in the same |
| 1996 | // StaticSocketDataProvider, it shows that the same socket is being reused for |
| 1997 | // all transactions. |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1998 | MockRead data_reads[] = { |
| 1999 | MockRead(ASYNC, 1, "HTTP/1.1 204 No Content\r\n\r\n"), |
| 2000 | MockRead(ASYNC, 3, "HTTP/1.1 205 Reset Content\r\n\r\n"), |
| 2001 | MockRead(ASYNC, 5, "HTTP/1.1 304 Not Modified\r\n\r\n"), |
| 2002 | MockRead(ASYNC, 7, |
| 2003 | "HTTP/1.1 302 Found\r\n" |
| 2004 | "Content-Length: 0\r\n\r\n"), |
| 2005 | MockRead(ASYNC, 9, |
| 2006 | "HTTP/1.1 302 Found\r\n" |
| 2007 | "Content-Length: 5\r\n\r\n" |
| 2008 | "hello"), |
| 2009 | MockRead(ASYNC, 11, |
| 2010 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 2011 | "Content-Length: 0\r\n\r\n"), |
| 2012 | MockRead(ASYNC, 13, |
| 2013 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 2014 | "Content-Length: 5\r\n\r\n" |
| 2015 | "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2016 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2017 | // In the next two rounds, IsConnectedAndIdle returns false, due to |
| 2018 | // the set_busy_before_sync_reads(true) call, while the |
| 2019 | // HttpNetworkTransaction is being shut down, but the socket is still |
| 2020 | // reuseable. See http://crbug.com/544255. |
| 2021 | MockRead(ASYNC, 15, |
| 2022 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 2023 | "Content-Length: 5\r\n\r\n"), |
| 2024 | MockRead(SYNCHRONOUS, 16, "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2025 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2026 | MockRead(ASYNC, 18, |
| 2027 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 2028 | "Content-Length: 5\r\n\r\n" |
| 2029 | "he"), |
| 2030 | MockRead(SYNCHRONOUS, 19, "llo"), |
| 2031 | |
| 2032 | // The body of the final request is actually read. |
| 2033 | MockRead(ASYNC, 21, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 2034 | MockRead(ASYNC, 22, "hello"), |
| 2035 | }; |
| 2036 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 2037 | arraysize(data_writes)); |
| 2038 | data.set_busy_before_sync_reads(true); |
| 2039 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 2040 | |
| 2041 | const int kNumUnreadBodies = arraysize(data_writes) - 1; |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2042 | std::string response_lines[kNumUnreadBodies]; |
| 2043 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 2044 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2045 | for (size_t i = 0; i < kNumUnreadBodies; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2046 | TestCompletionCallback callback; |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2047 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2048 | auto trans = std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2049 | session.get()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2050 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2051 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2052 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2053 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2054 | LoadTimingInfo load_timing_info; |
| 2055 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2056 | if (i == 0) { |
| 2057 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2058 | first_socket_log_id = load_timing_info.socket_log_id; |
| 2059 | } else { |
| 2060 | TestLoadTimingReused(load_timing_info); |
| 2061 | EXPECT_EQ(first_socket_log_id, load_timing_info.socket_log_id); |
| 2062 | } |
| 2063 | |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2064 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2065 | ASSERT_TRUE(response); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2066 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2067 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2068 | response_lines[i] = response->headers->GetStatusLine(); |
| 2069 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2070 | // Delete the transaction without reading the response bodies. Then spin |
| 2071 | // the message loop, so the response bodies are drained. |
| 2072 | trans.reset(); |
| 2073 | base::RunLoop().RunUntilIdle(); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2074 | } |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2075 | |
| 2076 | const char* const kStatusLines[] = { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2077 | "HTTP/1.1 204 No Content", |
| 2078 | "HTTP/1.1 205 Reset Content", |
| 2079 | "HTTP/1.1 304 Not Modified", |
| 2080 | "HTTP/1.1 302 Found", |
| 2081 | "HTTP/1.1 302 Found", |
| 2082 | "HTTP/1.1 301 Moved Permanently", |
| 2083 | "HTTP/1.1 301 Moved Permanently", |
| 2084 | "HTTP/1.1 200 Hunky-Dory", |
| 2085 | "HTTP/1.1 200 Hunky-Dory", |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2086 | }; |
| 2087 | |
mostynb | 91e0da98 | 2015-01-20 19:17:27 | [diff] [blame] | 2088 | static_assert(kNumUnreadBodies == arraysize(kStatusLines), |
| 2089 | "forgot to update kStatusLines"); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2090 | |
| 2091 | for (int i = 0; i < kNumUnreadBodies; ++i) |
| 2092 | EXPECT_EQ(kStatusLines[i], response_lines[i]); |
| 2093 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2094 | TestCompletionCallback callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2095 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2096 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2097 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2098 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2099 | ASSERT_TRUE(response); |
| 2100 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2101 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 2102 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2103 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2104 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2105 | EXPECT_EQ("hello", response_data); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2106 | } |
| 2107 | |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2108 | // Sockets that receive extra data after a response is complete should not be |
| 2109 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2110 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData1) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2111 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2112 | MockWrite data_writes1[] = { |
| 2113 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 2114 | "Host: www.borked.com\r\n" |
| 2115 | "Connection: keep-alive\r\n\r\n"), |
| 2116 | }; |
| 2117 | |
| 2118 | MockRead data_reads1[] = { |
| 2119 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2120 | "Connection: keep-alive\r\n" |
| 2121 | "Content-Length: 22\r\n\r\n" |
| 2122 | "This server is borked."), |
| 2123 | }; |
| 2124 | |
| 2125 | MockWrite data_writes2[] = { |
| 2126 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2127 | "Host: www.borked.com\r\n" |
| 2128 | "Connection: keep-alive\r\n\r\n"), |
| 2129 | }; |
| 2130 | |
| 2131 | MockRead data_reads2[] = { |
| 2132 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2133 | "Content-Length: 3\r\n\r\n" |
| 2134 | "foo"), |
| 2135 | }; |
| 2136 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2137 | data_writes1, arraysize(data_writes1)); |
| 2138 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2139 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2140 | data_writes2, arraysize(data_writes2)); |
| 2141 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2142 | |
| 2143 | TestCompletionCallback callback; |
| 2144 | HttpRequestInfo request1; |
| 2145 | request1.method = "HEAD"; |
| 2146 | request1.url = GURL("http://www.borked.com/"); |
| 2147 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2148 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2149 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2150 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2151 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2152 | |
| 2153 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2154 | ASSERT_TRUE(response1); |
| 2155 | ASSERT_TRUE(response1->headers); |
| 2156 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2157 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2158 | |
| 2159 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2160 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2161 | EXPECT_EQ("", response_data1); |
| 2162 | // Deleting the transaction attempts to release the socket back into the |
| 2163 | // socket pool. |
| 2164 | trans1.reset(); |
| 2165 | |
| 2166 | HttpRequestInfo request2; |
| 2167 | request2.method = "GET"; |
| 2168 | request2.url = GURL("http://www.borked.com/foo"); |
| 2169 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2170 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2171 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2172 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2173 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2174 | |
| 2175 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2176 | ASSERT_TRUE(response2); |
| 2177 | ASSERT_TRUE(response2->headers); |
| 2178 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2179 | |
| 2180 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2181 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2182 | EXPECT_EQ("foo", response_data2); |
| 2183 | } |
| 2184 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2185 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData2) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2186 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2187 | MockWrite data_writes1[] = { |
| 2188 | MockWrite("GET / HTTP/1.1\r\n" |
| 2189 | "Host: www.borked.com\r\n" |
| 2190 | "Connection: keep-alive\r\n\r\n"), |
| 2191 | }; |
| 2192 | |
| 2193 | MockRead data_reads1[] = { |
| 2194 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2195 | "Connection: keep-alive\r\n" |
| 2196 | "Content-Length: 22\r\n\r\n" |
| 2197 | "This server is borked." |
| 2198 | "Bonus data!"), |
| 2199 | }; |
| 2200 | |
| 2201 | MockWrite data_writes2[] = { |
| 2202 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2203 | "Host: www.borked.com\r\n" |
| 2204 | "Connection: keep-alive\r\n\r\n"), |
| 2205 | }; |
| 2206 | |
| 2207 | MockRead data_reads2[] = { |
| 2208 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2209 | "Content-Length: 3\r\n\r\n" |
| 2210 | "foo"), |
| 2211 | }; |
| 2212 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2213 | data_writes1, arraysize(data_writes1)); |
| 2214 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2215 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2216 | data_writes2, arraysize(data_writes2)); |
| 2217 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2218 | |
| 2219 | TestCompletionCallback callback; |
| 2220 | HttpRequestInfo request1; |
| 2221 | request1.method = "GET"; |
| 2222 | request1.url = GURL("http://www.borked.com/"); |
| 2223 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2224 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2225 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2226 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2227 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2228 | |
| 2229 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2230 | ASSERT_TRUE(response1); |
| 2231 | ASSERT_TRUE(response1->headers); |
| 2232 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2233 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2234 | |
| 2235 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2236 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2237 | EXPECT_EQ("This server is borked.", response_data1); |
| 2238 | // Deleting the transaction attempts to release the socket back into the |
| 2239 | // socket pool. |
| 2240 | trans1.reset(); |
| 2241 | |
| 2242 | HttpRequestInfo request2; |
| 2243 | request2.method = "GET"; |
| 2244 | request2.url = GURL("http://www.borked.com/foo"); |
| 2245 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2246 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2247 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2248 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2249 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2250 | |
| 2251 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2252 | ASSERT_TRUE(response2); |
| 2253 | ASSERT_TRUE(response2->headers); |
| 2254 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2255 | |
| 2256 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2257 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2258 | EXPECT_EQ("foo", response_data2); |
| 2259 | } |
| 2260 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2261 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData3) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2262 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2263 | MockWrite data_writes1[] = { |
| 2264 | MockWrite("GET / HTTP/1.1\r\n" |
| 2265 | "Host: www.borked.com\r\n" |
| 2266 | "Connection: keep-alive\r\n\r\n"), |
| 2267 | }; |
| 2268 | |
| 2269 | MockRead data_reads1[] = { |
| 2270 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2271 | "Connection: keep-alive\r\n" |
| 2272 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2273 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2274 | MockRead("0\r\n\r\nBonus data!"), |
| 2275 | }; |
| 2276 | |
| 2277 | MockWrite data_writes2[] = { |
| 2278 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2279 | "Host: www.borked.com\r\n" |
| 2280 | "Connection: keep-alive\r\n\r\n"), |
| 2281 | }; |
| 2282 | |
| 2283 | MockRead data_reads2[] = { |
| 2284 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2285 | "Content-Length: 3\r\n\r\n" |
| 2286 | "foo"), |
| 2287 | }; |
| 2288 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2289 | data_writes1, arraysize(data_writes1)); |
| 2290 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2291 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2292 | data_writes2, arraysize(data_writes2)); |
| 2293 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2294 | |
| 2295 | TestCompletionCallback callback; |
| 2296 | HttpRequestInfo request1; |
| 2297 | request1.method = "GET"; |
| 2298 | request1.url = GURL("http://www.borked.com/"); |
| 2299 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2300 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2301 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2302 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2303 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2304 | |
| 2305 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2306 | ASSERT_TRUE(response1); |
| 2307 | ASSERT_TRUE(response1->headers); |
| 2308 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2309 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2310 | |
| 2311 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2312 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2313 | EXPECT_EQ("This server is borked.", response_data1); |
| 2314 | // Deleting the transaction attempts to release the socket back into the |
| 2315 | // socket pool. |
| 2316 | trans1.reset(); |
| 2317 | |
| 2318 | HttpRequestInfo request2; |
| 2319 | request2.method = "GET"; |
| 2320 | request2.url = GURL("http://www.borked.com/foo"); |
| 2321 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2322 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2323 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2324 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2325 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2326 | |
| 2327 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2328 | ASSERT_TRUE(response2); |
| 2329 | ASSERT_TRUE(response2->headers); |
| 2330 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2331 | |
| 2332 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2333 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2334 | EXPECT_EQ("foo", response_data2); |
| 2335 | } |
| 2336 | |
| 2337 | // This is a little different from the others - it tests the case that the |
| 2338 | // HttpStreamParser doesn't know if there's extra data on a socket or not when |
| 2339 | // the HttpNetworkTransaction is torn down, because the response body hasn't |
| 2340 | // been read from yet, but the request goes through the HttpResponseBodyDrainer. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2341 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData4) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2342 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2343 | MockWrite data_writes1[] = { |
| 2344 | MockWrite("GET / HTTP/1.1\r\n" |
| 2345 | "Host: www.borked.com\r\n" |
| 2346 | "Connection: keep-alive\r\n\r\n"), |
| 2347 | }; |
| 2348 | |
| 2349 | MockRead data_reads1[] = { |
| 2350 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2351 | "Connection: keep-alive\r\n" |
| 2352 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2353 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2354 | MockRead("0\r\n\r\nBonus data!"), |
| 2355 | }; |
| 2356 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2357 | data_writes1, arraysize(data_writes1)); |
| 2358 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2359 | |
| 2360 | TestCompletionCallback callback; |
| 2361 | HttpRequestInfo request1; |
| 2362 | request1.method = "GET"; |
| 2363 | request1.url = GURL("http://www.borked.com/"); |
| 2364 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2365 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2366 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2367 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2368 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2369 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2370 | const HttpResponseInfo* response1 = trans->GetResponseInfo(); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2371 | ASSERT_TRUE(response1); |
| 2372 | ASSERT_TRUE(response1->headers); |
| 2373 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2374 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2375 | |
| 2376 | // Deleting the transaction creates an HttpResponseBodyDrainer to read the |
| 2377 | // response body. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2378 | trans.reset(); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2379 | |
| 2380 | // Let the HttpResponseBodyDrainer drain the socket. It should determine the |
| 2381 | // socket can't be reused, rather than returning it to the socket pool. |
| 2382 | base::RunLoop().RunUntilIdle(); |
| 2383 | |
| 2384 | // There should be no idle sockets in the pool. |
| 2385 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2386 | } |
| 2387 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2388 | // Test the request-challenge-retry sequence for basic auth. |
| 2389 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2390 | TEST_F(HttpNetworkTransactionTest, BasicAuth) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2391 | HttpRequestInfo request; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2392 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2393 | request.url = GURL("http://www.example.org/"); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2394 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2395 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2396 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2397 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2398 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2399 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2400 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2401 | MockWrite( |
| 2402 | "GET / HTTP/1.1\r\n" |
| 2403 | "Host: www.example.org\r\n" |
| 2404 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2405 | }; |
| 2406 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2407 | MockRead data_reads1[] = { |
| 2408 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2409 | // Give a couple authenticate options (only the middle one is actually |
| 2410 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 2411 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2412 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2413 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2414 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2415 | // Large content-length -- won't matter, as connection will be reset. |
| 2416 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2417 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2418 | }; |
| 2419 | |
| 2420 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2421 | // be issuing -- the final header line contains the credentials. |
| 2422 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2423 | MockWrite( |
| 2424 | "GET / HTTP/1.1\r\n" |
| 2425 | "Host: www.example.org\r\n" |
| 2426 | "Connection: keep-alive\r\n" |
| 2427 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2428 | }; |
| 2429 | |
| 2430 | // Lastly, the server responds with the actual content. |
| 2431 | MockRead data_reads2[] = { |
| 2432 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2433 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2434 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2435 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2436 | }; |
| 2437 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2438 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2439 | data_writes1, arraysize(data_writes1)); |
| 2440 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2441 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2442 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2443 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2444 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2445 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2446 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2447 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2448 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2449 | |
| 2450 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2451 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2452 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2453 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2454 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2455 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2456 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2457 | int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2458 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2459 | int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2460 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2461 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2462 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2463 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2464 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2465 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2466 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2467 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2468 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2469 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2470 | |
| 2471 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2472 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2473 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2474 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2475 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2476 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2477 | // The load timing after restart should have a new socket ID, and times after |
| 2478 | // those of the first load timing. |
| 2479 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2480 | load_timing_info2.connect_timing.connect_start); |
| 2481 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2482 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2483 | int64_t writes_size2 = CountWriteBytes(data_writes2, arraysize(data_writes2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2484 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2485 | int64_t reads_size2 = CountReadBytes(data_reads2, arraysize(data_reads2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2486 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2487 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2488 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2489 | ASSERT_TRUE(response); |
| 2490 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2491 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2492 | } |
| 2493 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2494 | // Test the request-challenge-retry sequence for basic auth. |
| 2495 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2496 | TEST_F(HttpNetworkTransactionTest, BasicAuthWithAddressChange) { |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2497 | HttpRequestInfo request; |
| 2498 | request.method = "GET"; |
| 2499 | request.url = GURL("http://www.example.org/"); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2500 | |
| 2501 | TestNetLog log; |
| 2502 | MockHostResolver* resolver = new MockHostResolver(); |
| 2503 | session_deps_.net_log = &log; |
| 2504 | session_deps_.host_resolver.reset(resolver); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2505 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2506 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2507 | |
| 2508 | resolver->rules()->ClearRules(); |
| 2509 | resolver->rules()->AddRule("www.example.org", "127.0.0.1"); |
| 2510 | |
| 2511 | MockWrite data_writes1[] = { |
| 2512 | MockWrite("GET / HTTP/1.1\r\n" |
| 2513 | "Host: www.example.org\r\n" |
| 2514 | "Connection: keep-alive\r\n\r\n"), |
| 2515 | }; |
| 2516 | |
| 2517 | MockRead data_reads1[] = { |
| 2518 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2519 | // Give a couple authenticate options (only the middle one is actually |
| 2520 | // supported). |
| 2521 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 2522 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2523 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2524 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2525 | // Large content-length -- won't matter, as connection will be reset. |
| 2526 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 2527 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 2528 | }; |
| 2529 | |
| 2530 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2531 | // be issuing -- the final header line contains the credentials. |
| 2532 | MockWrite data_writes2[] = { |
| 2533 | MockWrite("GET / HTTP/1.1\r\n" |
| 2534 | "Host: www.example.org\r\n" |
| 2535 | "Connection: keep-alive\r\n" |
| 2536 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2537 | }; |
| 2538 | |
| 2539 | // Lastly, the server responds with the actual content. |
| 2540 | MockRead data_reads2[] = { |
| 2541 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2542 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2543 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, OK), |
| 2544 | }; |
| 2545 | |
| 2546 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2547 | data_writes1, arraysize(data_writes1)); |
| 2548 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2549 | data_writes2, arraysize(data_writes2)); |
| 2550 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2551 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2552 | |
| 2553 | TestCompletionCallback callback1; |
| 2554 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2555 | EXPECT_EQ(OK, callback1.GetResult(trans.Start(&request, callback1.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2556 | NetLogWithSource()))); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2557 | |
| 2558 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2559 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2560 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2561 | |
| 2562 | int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2563 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2564 | int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2565 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2566 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2567 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2568 | ASSERT_TRUE(response); |
| 2569 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 2570 | |
| 2571 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2572 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2573 | ASSERT_FALSE(endpoint.address().empty()); |
| 2574 | EXPECT_EQ("127.0.0.1:80", endpoint.ToString()); |
| 2575 | |
| 2576 | resolver->rules()->ClearRules(); |
| 2577 | resolver->rules()->AddRule("www.example.org", "127.0.0.2"); |
| 2578 | |
| 2579 | TestCompletionCallback callback2; |
| 2580 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2581 | EXPECT_EQ(OK, callback2.GetResult(trans.RestartWithAuth( |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2582 | AuthCredentials(kFoo, kBar), callback2.callback()))); |
| 2583 | |
| 2584 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2585 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2586 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2587 | // The load timing after restart should have a new socket ID, and times after |
| 2588 | // those of the first load timing. |
| 2589 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2590 | load_timing_info2.connect_timing.connect_start); |
| 2591 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2592 | |
| 2593 | int64_t writes_size2 = CountWriteBytes(data_writes2, arraysize(data_writes2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2594 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2595 | int64_t reads_size2 = CountReadBytes(data_reads2, arraysize(data_reads2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2596 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2597 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2598 | response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2599 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2600 | EXPECT_FALSE(response->auth_challenge); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2601 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 2602 | |
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.2:80", endpoint.ToString()); |
| 2606 | } |
| 2607 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2608 | TEST_F(HttpNetworkTransactionTest, DoNotSendAuth) { |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2609 | HttpRequestInfo request; |
| 2610 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2611 | request.url = GURL("http://www.example.org/"); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2612 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2613 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2614 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2615 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2616 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2617 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2618 | MockWrite( |
| 2619 | "GET / HTTP/1.1\r\n" |
| 2620 | "Host: www.example.org\r\n" |
| 2621 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2622 | }; |
| 2623 | |
| 2624 | MockRead data_reads[] = { |
| 2625 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2626 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2627 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2628 | // Large content-length -- won't matter, as connection will be reset. |
| 2629 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2630 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2631 | }; |
| 2632 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2633 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 2634 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2635 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2636 | TestCompletionCallback callback; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2637 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2638 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2639 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2640 | |
| 2641 | rv = callback.WaitForResult(); |
| 2642 | EXPECT_EQ(0, rv); |
| 2643 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2644 | int64_t writes_size = CountWriteBytes(data_writes, arraysize(data_writes)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2645 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2646 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2647 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2648 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2649 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2650 | ASSERT_TRUE(response); |
| 2651 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2652 | } |
| 2653 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2654 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2655 | // connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2656 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAlive) { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2657 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 2658 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 2659 | // reused. See http://crbug.com/544255. |
| 2660 | for (int i = 0; i < 2; ++i) { |
| 2661 | HttpRequestInfo request; |
| 2662 | request.method = "GET"; |
| 2663 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2664 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2665 | TestNetLog log; |
| 2666 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2667 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2668 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2669 | MockWrite data_writes[] = { |
| 2670 | MockWrite(ASYNC, 0, |
| 2671 | "GET / HTTP/1.1\r\n" |
| 2672 | "Host: www.example.org\r\n" |
| 2673 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2674 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2675 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2676 | // be issuing -- the final header line contains the credentials. |
| 2677 | MockWrite(ASYNC, 6, |
| 2678 | "GET / HTTP/1.1\r\n" |
| 2679 | "Host: www.example.org\r\n" |
| 2680 | "Connection: keep-alive\r\n" |
| 2681 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2682 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2683 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2684 | MockRead data_reads[] = { |
| 2685 | MockRead(ASYNC, 1, "HTTP/1.1 401 Unauthorized\r\n"), |
| 2686 | MockRead(ASYNC, 2, "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2687 | MockRead(ASYNC, 3, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2688 | MockRead(ASYNC, 4, "Content-Length: 14\r\n\r\n"), |
| 2689 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 5, "Unauthorized\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2690 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2691 | // Lastly, the server responds with the actual content. |
| 2692 | MockRead(ASYNC, 7, "HTTP/1.1 200 OK\r\n"), |
| 2693 | MockRead(ASYNC, 8, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2694 | MockRead(ASYNC, 9, "Content-Length: 5\r\n\r\n"), |
| 2695 | MockRead(ASYNC, 10, "Hello"), |
| 2696 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2697 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2698 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 2699 | arraysize(data_writes)); |
| 2700 | data.set_busy_before_sync_reads(true); |
| 2701 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2702 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2703 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2704 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2705 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2706 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2707 | ASSERT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2708 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2709 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2710 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2711 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2712 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2713 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2714 | ASSERT_TRUE(response); |
| 2715 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2716 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2717 | TestCompletionCallback callback2; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2718 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2719 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 2720 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2721 | ASSERT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2722 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2723 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2724 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2725 | TestLoadTimingReused(load_timing_info2); |
| 2726 | // The load timing after restart should have the same socket ID, and times |
| 2727 | // those of the first load timing. |
| 2728 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2729 | load_timing_info2.send_start); |
| 2730 | 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] | 2731 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2732 | response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2733 | ASSERT_TRUE(response); |
| 2734 | EXPECT_FALSE(response->auth_challenge); |
| 2735 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2736 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2737 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2738 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2739 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2740 | int64_t writes_size = CountWriteBytes(data_writes, arraysize(data_writes)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2741 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2742 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2743 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2744 | } |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2745 | } |
| 2746 | |
| 2747 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2748 | // connection and with no response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2749 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2750 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2751 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2752 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2753 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2754 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2755 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2756 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2757 | MockWrite("GET / HTTP/1.1\r\n" |
| 2758 | "Host: www.example.org\r\n" |
| 2759 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2760 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2761 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2762 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2763 | MockWrite("GET / HTTP/1.1\r\n" |
| 2764 | "Host: www.example.org\r\n" |
| 2765 | "Connection: keep-alive\r\n" |
| 2766 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2767 | }; |
| 2768 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2769 | MockRead data_reads1[] = { |
| 2770 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2771 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2772 | MockRead("Content-Length: 0\r\n\r\n"), // No response body. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2773 | |
| 2774 | // Lastly, the server responds with the actual content. |
| 2775 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2776 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2777 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2778 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2779 | }; |
| 2780 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2781 | // An incorrect reconnect would cause this to be read. |
| 2782 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2783 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2784 | }; |
| 2785 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2786 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2787 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2788 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2789 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2790 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2791 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2792 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2793 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2794 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2795 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2796 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2797 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2798 | |
| 2799 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2800 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2801 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2802 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2803 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2804 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2805 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2806 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2807 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2808 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2809 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2810 | |
| 2811 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2812 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2813 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2814 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2815 | ASSERT_TRUE(response); |
| 2816 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2817 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2818 | } |
| 2819 | |
| 2820 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2821 | // connection and with a large response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2822 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2823 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2824 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2825 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2826 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2827 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2828 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2829 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2830 | MockWrite("GET / HTTP/1.1\r\n" |
| 2831 | "Host: www.example.org\r\n" |
| 2832 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2833 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2834 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2835 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2836 | MockWrite("GET / HTTP/1.1\r\n" |
| 2837 | "Host: www.example.org\r\n" |
| 2838 | "Connection: keep-alive\r\n" |
| 2839 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2840 | }; |
| 2841 | |
| 2842 | // Respond with 5 kb of response body. |
| 2843 | std::string large_body_string("Unauthorized"); |
| 2844 | large_body_string.append(5 * 1024, ' '); |
| 2845 | large_body_string.append("\r\n"); |
| 2846 | |
| 2847 | MockRead data_reads1[] = { |
| 2848 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2849 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2850 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2851 | // 5134 = 12 + 5 * 1024 + 2 |
| 2852 | MockRead("Content-Length: 5134\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2853 | MockRead(ASYNC, large_body_string.data(), large_body_string.size()), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2854 | |
| 2855 | // Lastly, the server responds with the actual content. |
| 2856 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2857 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2858 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2859 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2860 | }; |
| 2861 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2862 | // An incorrect reconnect would cause this to be read. |
| 2863 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2864 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2865 | }; |
| 2866 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2867 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2868 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2869 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2870 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2871 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2872 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2873 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2874 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2875 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2876 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2877 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2878 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2879 | |
| 2880 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2881 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2882 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2883 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2884 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2885 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2886 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2887 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2888 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2889 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2890 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2891 | |
| 2892 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2893 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2894 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2895 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2896 | ASSERT_TRUE(response); |
| 2897 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2898 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2899 | } |
| 2900 | |
| 2901 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2902 | // connection, but the server gets impatient and closes the connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2903 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) { |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2904 | HttpRequestInfo request; |
| 2905 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2906 | request.url = GURL("http://www.example.org/"); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2907 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2908 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2909 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2910 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2911 | MockWrite( |
| 2912 | "GET / HTTP/1.1\r\n" |
| 2913 | "Host: www.example.org\r\n" |
| 2914 | "Connection: keep-alive\r\n\r\n"), |
| 2915 | // This simulates the seemingly successful write to a closed connection |
| 2916 | // if the bug is not fixed. |
| 2917 | MockWrite( |
| 2918 | "GET / HTTP/1.1\r\n" |
| 2919 | "Host: www.example.org\r\n" |
| 2920 | "Connection: keep-alive\r\n" |
| 2921 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2922 | }; |
| 2923 | |
| 2924 | MockRead data_reads1[] = { |
| 2925 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2926 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2927 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2928 | MockRead("Content-Length: 14\r\n\r\n"), |
| 2929 | // Tell MockTCPClientSocket to simulate the server closing the connection. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2930 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2931 | MockRead("Unauthorized\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2932 | MockRead(SYNCHRONOUS, OK), // The server closes the connection. |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2933 | }; |
| 2934 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2935 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2936 | // be issuing -- the final header line contains the credentials. |
| 2937 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2938 | MockWrite( |
| 2939 | "GET / HTTP/1.1\r\n" |
| 2940 | "Host: www.example.org\r\n" |
| 2941 | "Connection: keep-alive\r\n" |
| 2942 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2943 | }; |
| 2944 | |
| 2945 | // Lastly, the server responds with the actual content. |
| 2946 | MockRead data_reads2[] = { |
| 2947 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2948 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2949 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2950 | MockRead("hello"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2951 | }; |
| 2952 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2953 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2954 | data_writes1, arraysize(data_writes1)); |
| 2955 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2956 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2957 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2958 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2959 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2960 | TestCompletionCallback callback1; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2961 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2962 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2963 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2964 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2965 | |
| 2966 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2967 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2968 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2969 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2970 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2971 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2972 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2973 | TestCompletionCallback callback2; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2974 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2975 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2976 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2977 | |
| 2978 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2979 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2980 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2981 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2982 | ASSERT_TRUE(response); |
| 2983 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2984 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2985 | } |
| 2986 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2987 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 2988 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2989 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp10) { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2990 | HttpRequestInfo request; |
| 2991 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2992 | request.url = GURL("https://www.example.org/"); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2993 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2994 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2995 | |
| 2996 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 2997 | session_deps_.proxy_service = |
| 2998 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2999 | BoundTestNetLog log; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3000 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3001 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3002 | |
| 3003 | // Since we have proxy, should try to establish tunnel. |
| 3004 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3005 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3006 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3007 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3008 | }; |
| 3009 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3010 | // The proxy responds to the connect with a 407, using a non-persistent |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3011 | // connection. |
| 3012 | MockRead data_reads1[] = { |
| 3013 | // No credentials. |
| 3014 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 3015 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3016 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3017 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3018 | // Since the first connection couldn't be reused, need to establish another |
| 3019 | // once given credentials. |
| 3020 | MockWrite data_writes2[] = { |
| 3021 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3022 | // be issuing -- the final header line contains the credentials. |
| 3023 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3024 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3025 | "Proxy-Connection: keep-alive\r\n" |
| 3026 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3027 | |
| 3028 | MockWrite("GET / HTTP/1.1\r\n" |
| 3029 | "Host: www.example.org\r\n" |
| 3030 | "Connection: keep-alive\r\n\r\n"), |
| 3031 | }; |
| 3032 | |
| 3033 | MockRead data_reads2[] = { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3034 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3035 | |
| 3036 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3037 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3038 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3039 | MockRead(SYNCHRONOUS, "hello"), |
| 3040 | }; |
| 3041 | |
| 3042 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3043 | data_writes1, arraysize(data_writes1)); |
| 3044 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3045 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3046 | data_writes2, arraysize(data_writes2)); |
| 3047 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3048 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3049 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3050 | |
| 3051 | TestCompletionCallback callback1; |
| 3052 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3053 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3054 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3055 | |
| 3056 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3057 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3058 | |
| 3059 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3060 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3061 | TestNetLogEntry::List entries; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3062 | log.GetEntries(&entries); |
| 3063 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3064 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3065 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3066 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3067 | entries, pos, |
| 3068 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3069 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3070 | |
| 3071 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3072 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3073 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3074 | ASSERT_TRUE(response->headers); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3075 | EXPECT_EQ(407, response->headers->response_code()); |
| 3076 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3077 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3078 | |
| 3079 | LoadTimingInfo load_timing_info; |
| 3080 | // CONNECT requests and responses are handled at the connect job level, so |
| 3081 | // the transaction does not yet have a connection. |
| 3082 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3083 | |
| 3084 | TestCompletionCallback callback2; |
| 3085 | |
| 3086 | rv = |
| 3087 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
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 = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3091 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3092 | |
| 3093 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3094 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3095 | |
| 3096 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3097 | EXPECT_EQ(200, response->headers->response_code()); |
| 3098 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 3099 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3100 | |
| 3101 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3102 | EXPECT_FALSE(response->auth_challenge); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3103 | |
| 3104 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3105 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3106 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3107 | |
| 3108 | trans.reset(); |
| 3109 | session->CloseAllConnections(); |
| 3110 | } |
| 3111 | |
| 3112 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 3113 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3114 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp11) { |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3115 | HttpRequestInfo request; |
| 3116 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3117 | request.url = GURL("https://www.example.org/"); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3118 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3119 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3120 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3121 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3122 | session_deps_.proxy_service = |
| 3123 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3124 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3125 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3126 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3127 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3128 | // Since we have proxy, should try to establish tunnel. |
| 3129 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3130 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3131 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3132 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3133 | }; |
| 3134 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3135 | // The proxy responds to the connect with a 407, using a non-persistent |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3136 | // connection. |
| 3137 | MockRead data_reads1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3138 | // No credentials. |
| 3139 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3140 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3141 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3142 | }; |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3143 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3144 | MockWrite data_writes2[] = { |
| 3145 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3146 | // be issuing -- the final header line contains the credentials. |
| 3147 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3148 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3149 | "Proxy-Connection: keep-alive\r\n" |
| 3150 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3151 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3152 | MockWrite("GET / HTTP/1.1\r\n" |
| 3153 | "Host: www.example.org\r\n" |
| 3154 | "Connection: keep-alive\r\n\r\n"), |
| 3155 | }; |
| 3156 | |
| 3157 | MockRead data_reads2[] = { |
| 3158 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3159 | |
| 3160 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3161 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3162 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3163 | MockRead(SYNCHRONOUS, "hello"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3164 | }; |
| 3165 | |
| 3166 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3167 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3168 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3169 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3170 | data_writes2, arraysize(data_writes2)); |
| 3171 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3172 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3173 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3174 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3175 | TestCompletionCallback callback1; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3176 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3177 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3178 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3179 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3180 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3181 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3182 | |
| 3183 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3184 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3185 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3186 | log.GetEntries(&entries); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3187 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3188 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3189 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3190 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3191 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3192 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3193 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3194 | |
| 3195 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3196 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3197 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3198 | ASSERT_TRUE(response->headers); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3199 | EXPECT_EQ(407, response->headers->response_code()); |
| 3200 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3201 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3202 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3203 | LoadTimingInfo load_timing_info; |
| 3204 | // CONNECT requests and responses are handled at the connect job level, so |
| 3205 | // the transaction does not yet have a connection. |
| 3206 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3207 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3208 | TestCompletionCallback callback2; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3209 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3210 | rv = trans->RestartWithAuth( |
| 3211 | AuthCredentials(kFoo, kBar), callback2.callback()); |
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 = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3215 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3216 | |
| 3217 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3218 | ASSERT_TRUE(response); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3219 | |
| 3220 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3221 | EXPECT_EQ(200, response->headers->response_code()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3222 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3223 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3224 | |
| 3225 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3226 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3227 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3228 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3229 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3230 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3231 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3232 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3233 | session->CloseAllConnections(); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3234 | } |
| 3235 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3236 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3237 | // proxy connection with HTTP/1.0 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3238 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp10) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3239 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3240 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3241 | // reused. See http://crbug.com/544255. |
| 3242 | for (int i = 0; i < 2; ++i) { |
| 3243 | HttpRequestInfo request; |
| 3244 | request.method = "GET"; |
| 3245 | request.url = GURL("https://www.example.org/"); |
| 3246 | // Ensure that proxy authentication is attempted even |
| 3247 | // when the no authentication data flag is set. |
| 3248 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3249 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3250 | // Configure against proxy server "myproxy:70". |
| 3251 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
| 3252 | BoundTestNetLog log; |
| 3253 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3254 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3255 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3256 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3257 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3258 | // Since we have proxy, should try to establish tunnel. |
| 3259 | MockWrite data_writes1[] = { |
| 3260 | MockWrite(ASYNC, 0, |
| 3261 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3262 | "Host: www.example.org:443\r\n" |
| 3263 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3264 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3265 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3266 | // be issuing -- the final header line contains the credentials. |
| 3267 | MockWrite(ASYNC, 3, |
| 3268 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3269 | "Host: www.example.org:443\r\n" |
| 3270 | "Proxy-Connection: keep-alive\r\n" |
| 3271 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3272 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3273 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3274 | // The proxy responds to the connect with a 407, using a persistent |
| 3275 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3276 | MockRead data_reads1[] = { |
| 3277 | // No credentials. |
| 3278 | MockRead(ASYNC, 1, |
| 3279 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3280 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3281 | "Proxy-Connection: keep-alive\r\n" |
| 3282 | "Content-Length: 10\r\n\r\n"), |
| 3283 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3284 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3285 | // Wrong credentials (wrong password). |
| 3286 | MockRead(ASYNC, 4, |
| 3287 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3288 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3289 | "Proxy-Connection: keep-alive\r\n" |
| 3290 | "Content-Length: 10\r\n\r\n"), |
| 3291 | // No response body because the test stops reading here. |
| 3292 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3293 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3294 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3295 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3296 | arraysize(data_writes1)); |
| 3297 | data1.set_busy_before_sync_reads(true); |
| 3298 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3299 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3300 | TestCompletionCallback callback1; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3301 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3302 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3303 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3304 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3305 | TestNetLogEntry::List entries; |
| 3306 | log.GetEntries(&entries); |
| 3307 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3308 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3309 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3310 | ExpectLogContainsSomewhere( |
| 3311 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3312 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3313 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3314 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3315 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3316 | ASSERT_TRUE(response); |
| 3317 | ASSERT_TRUE(response->headers); |
| 3318 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3319 | EXPECT_EQ(407, response->headers->response_code()); |
| 3320 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3321 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3322 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3323 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3324 | TestCompletionCallback callback2; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3325 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3326 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3327 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3328 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3329 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3330 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3331 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3332 | ASSERT_TRUE(response); |
| 3333 | ASSERT_TRUE(response->headers); |
| 3334 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3335 | EXPECT_EQ(407, response->headers->response_code()); |
| 3336 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3337 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3338 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3339 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3340 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3341 | // out of scope. |
| 3342 | session->CloseAllConnections(); |
| 3343 | } |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3344 | } |
| 3345 | |
| 3346 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3347 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3348 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp11) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3349 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3350 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3351 | // reused. See http://crbug.com/544255. |
| 3352 | for (int i = 0; i < 2; ++i) { |
| 3353 | HttpRequestInfo request; |
| 3354 | request.method = "GET"; |
| 3355 | request.url = GURL("https://www.example.org/"); |
| 3356 | // Ensure that proxy authentication is attempted even |
| 3357 | // when the no authentication data flag is set. |
| 3358 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
| 3359 | |
| 3360 | // Configure against proxy server "myproxy:70". |
| 3361 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
| 3362 | BoundTestNetLog log; |
| 3363 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3364 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3365 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3366 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3367 | |
| 3368 | // Since we have proxy, should try to establish tunnel. |
| 3369 | MockWrite data_writes1[] = { |
| 3370 | MockWrite(ASYNC, 0, |
| 3371 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3372 | "Host: www.example.org:443\r\n" |
| 3373 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3374 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3375 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3376 | // be issuing -- the final header line contains the credentials. |
| 3377 | MockWrite(ASYNC, 3, |
| 3378 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3379 | "Host: www.example.org:443\r\n" |
| 3380 | "Proxy-Connection: keep-alive\r\n" |
| 3381 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3382 | }; |
| 3383 | |
| 3384 | // The proxy responds to the connect with a 407, using a persistent |
| 3385 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3386 | MockRead data_reads1[] = { |
| 3387 | // No credentials. |
| 3388 | MockRead(ASYNC, 1, |
| 3389 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3390 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3391 | "Content-Length: 10\r\n\r\n"), |
| 3392 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
| 3393 | |
| 3394 | // Wrong credentials (wrong password). |
| 3395 | MockRead(ASYNC, 4, |
| 3396 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3397 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3398 | "Content-Length: 10\r\n\r\n"), |
| 3399 | // No response body because the test stops reading here. |
| 3400 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3401 | }; |
| 3402 | |
| 3403 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3404 | arraysize(data_writes1)); |
| 3405 | data1.set_busy_before_sync_reads(true); |
| 3406 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3407 | |
| 3408 | TestCompletionCallback callback1; |
| 3409 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3410 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3411 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3412 | |
| 3413 | TestNetLogEntry::List entries; |
| 3414 | log.GetEntries(&entries); |
| 3415 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3416 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3417 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3418 | ExpectLogContainsSomewhere( |
| 3419 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3420 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3421 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3422 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3423 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3424 | ASSERT_TRUE(response); |
| 3425 | ASSERT_TRUE(response->headers); |
| 3426 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3427 | EXPECT_EQ(407, response->headers->response_code()); |
| 3428 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3429 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3430 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3431 | |
| 3432 | TestCompletionCallback callback2; |
| 3433 | |
| 3434 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3435 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3436 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3437 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3438 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3439 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3440 | ASSERT_TRUE(response); |
| 3441 | ASSERT_TRUE(response->headers); |
| 3442 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3443 | EXPECT_EQ(407, response->headers->response_code()); |
| 3444 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3445 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3446 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3447 | |
| 3448 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3449 | // out of scope. |
| 3450 | session->CloseAllConnections(); |
| 3451 | } |
| 3452 | } |
| 3453 | |
| 3454 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3455 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel, in |
| 3456 | // the case the server sends extra data on the original socket, so it can't be |
| 3457 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3458 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveExtraData) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3459 | HttpRequestInfo request; |
| 3460 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3461 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3462 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3463 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3464 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3465 | // Configure against proxy server "myproxy:70". |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3466 | session_deps_.proxy_service = |
| 3467 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3468 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3469 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3470 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3471 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3472 | // Since we have proxy, should try to establish tunnel. |
| 3473 | MockWrite data_writes1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3474 | MockWrite(ASYNC, 0, |
| 3475 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3476 | "Host: www.example.org:443\r\n" |
| 3477 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3478 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3479 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3480 | // The proxy responds to the connect with a 407, using a persistent, but sends |
| 3481 | // extra data, so the socket cannot be reused. |
| 3482 | MockRead data_reads1[] = { |
| 3483 | // No credentials. |
| 3484 | MockRead(ASYNC, 1, |
| 3485 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3486 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3487 | "Content-Length: 10\r\n\r\n"), |
| 3488 | MockRead(SYNCHRONOUS, 2, "0123456789"), |
| 3489 | MockRead(SYNCHRONOUS, 3, "I'm broken!"), |
| 3490 | }; |
| 3491 | |
| 3492 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3493 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3494 | // be issuing -- the final header line contains the credentials. |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3495 | MockWrite(ASYNC, 0, |
| 3496 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3497 | "Host: www.example.org:443\r\n" |
| 3498 | "Proxy-Connection: keep-alive\r\n" |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3499 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3500 | |
| 3501 | MockWrite(ASYNC, 2, |
| 3502 | "GET / HTTP/1.1\r\n" |
| 3503 | "Host: www.example.org\r\n" |
| 3504 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3505 | }; |
| 3506 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3507 | MockRead data_reads2[] = { |
| 3508 | MockRead(ASYNC, 1, "HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3509 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3510 | MockRead(ASYNC, 3, |
| 3511 | "HTTP/1.1 200 OK\r\n" |
| 3512 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 3513 | "Content-Length: 5\r\n\r\n"), |
| 3514 | // No response body because the test stops reading here. |
| 3515 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 4), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3516 | }; |
| 3517 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3518 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3519 | arraysize(data_writes1)); |
| 3520 | data1.set_busy_before_sync_reads(true); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3521 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3522 | SequencedSocketData data2(data_reads2, arraysize(data_reads2), data_writes2, |
| 3523 | arraysize(data_writes2)); |
| 3524 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3525 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3526 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3527 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3528 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3529 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3530 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3531 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3532 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3533 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3534 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3535 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3536 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3537 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3538 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3539 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3540 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3541 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3542 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3543 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3544 | NetLogEventPhase::NONE); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3545 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3546 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3547 | ASSERT_TRUE(response); |
| 3548 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3549 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3550 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3551 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3552 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3553 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3554 | LoadTimingInfo load_timing_info; |
| 3555 | // CONNECT requests and responses are handled at the connect job level, so |
| 3556 | // the transaction does not yet have a connection. |
| 3557 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3558 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3559 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3560 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3561 | rv = |
| 3562 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3563 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3564 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3565 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3566 | EXPECT_EQ(200, response->headers->response_code()); |
| 3567 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3568 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 3569 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3570 | // The password prompt info should not be set. |
| 3571 | EXPECT_FALSE(response->auth_challenge); |
| 3572 | |
| 3573 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3574 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3575 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3576 | |
| 3577 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3578 | session->CloseAllConnections(); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3579 | } |
| 3580 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3581 | // Test the case a proxy closes a socket while the challenge body is being |
| 3582 | // drained. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3583 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHangupDuringBody) { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3584 | HttpRequestInfo request; |
| 3585 | request.method = "GET"; |
| 3586 | request.url = GURL("https://www.example.org/"); |
| 3587 | // Ensure that proxy authentication is attempted even |
| 3588 | // when the no authentication data flag is set. |
| 3589 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
| 3590 | |
| 3591 | // Configure against proxy server "myproxy:70". |
| 3592 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3593 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3594 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3595 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3596 | |
| 3597 | // Since we have proxy, should try to establish tunnel. |
| 3598 | MockWrite data_writes1[] = { |
| 3599 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3600 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3601 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3602 | }; |
| 3603 | |
| 3604 | // The proxy responds to the connect with a 407, using a persistent |
| 3605 | // connection. |
| 3606 | MockRead data_reads1[] = { |
| 3607 | // No credentials. |
| 3608 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3609 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3610 | MockRead("Content-Length: 10\r\n\r\n"), MockRead("spam!"), |
| 3611 | // Server hands up in the middle of the body. |
| 3612 | MockRead(ASYNC, ERR_CONNECTION_CLOSED), |
| 3613 | }; |
| 3614 | |
| 3615 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3616 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3617 | // be issuing -- the final header line contains the credentials. |
| 3618 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3619 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3620 | "Proxy-Connection: keep-alive\r\n" |
| 3621 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3622 | |
| 3623 | MockWrite("GET / HTTP/1.1\r\n" |
| 3624 | "Host: www.example.org\r\n" |
| 3625 | "Connection: keep-alive\r\n\r\n"), |
| 3626 | }; |
| 3627 | |
| 3628 | MockRead data_reads2[] = { |
| 3629 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3630 | |
| 3631 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3632 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3633 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3634 | MockRead(SYNCHRONOUS, "hello"), |
| 3635 | }; |
| 3636 | |
| 3637 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3638 | data_writes1, arraysize(data_writes1)); |
| 3639 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3640 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3641 | data_writes2, arraysize(data_writes2)); |
| 3642 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3643 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3644 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3645 | |
| 3646 | TestCompletionCallback callback; |
| 3647 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3648 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3649 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3650 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3651 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3652 | ASSERT_TRUE(response); |
| 3653 | ASSERT_TRUE(response->headers); |
| 3654 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3655 | EXPECT_EQ(407, response->headers->response_code()); |
| 3656 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3657 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3658 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3659 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3660 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3661 | response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3662 | ASSERT_TRUE(response); |
| 3663 | ASSERT_TRUE(response->headers); |
| 3664 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3665 | EXPECT_EQ(200, response->headers->response_code()); |
| 3666 | std::string body; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3667 | EXPECT_THAT(ReadTransaction(&trans, &body), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3668 | EXPECT_EQ("hello", body); |
| 3669 | } |
| 3670 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3671 | // Test that we don't read the response body when we fail to establish a tunnel, |
| 3672 | // even if the user cancels the proxy's auth attempt. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3673 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3674 | HttpRequestInfo request; |
| 3675 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3676 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3677 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3678 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3679 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3680 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3681 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3682 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3683 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3684 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3685 | // Since we have proxy, should try to establish tunnel. |
| 3686 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3687 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3688 | "Host: www.example.org:443\r\n" |
| 3689 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3690 | }; |
| 3691 | |
| 3692 | // The proxy responds to the connect with a 407. |
| 3693 | MockRead data_reads[] = { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3694 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3695 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3696 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3697 | MockRead("0123456789"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3698 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3699 | }; |
| 3700 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 3701 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 3702 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3703 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3704 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3705 | TestCompletionCallback callback; |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3706 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3707 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3708 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3709 | |
| 3710 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3711 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3712 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3713 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3714 | ASSERT_TRUE(response); |
| 3715 | ASSERT_TRUE(response->headers); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3716 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3717 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3718 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3719 | |
| 3720 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3721 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3722 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 3723 | |
| 3724 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3725 | session->CloseAllConnections(); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3726 | } |
| 3727 | |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3728 | // Test that we don't pass extraneous headers from the proxy's response to the |
| 3729 | // caller when the proxy responds to CONNECT with 407. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3730 | TEST_F(HttpNetworkTransactionTest, SanitizeProxyAuthHeaders) { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3731 | HttpRequestInfo request; |
| 3732 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3733 | request.url = GURL("https://www.example.org/"); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3734 | |
| 3735 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3736 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3737 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3738 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3739 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3740 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3741 | |
| 3742 | // Since we have proxy, should try to establish tunnel. |
| 3743 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3744 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3745 | "Host: www.example.org:443\r\n" |
| 3746 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3747 | }; |
| 3748 | |
| 3749 | // The proxy responds to the connect with a 407. |
| 3750 | MockRead data_reads[] = { |
| 3751 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3752 | MockRead("X-Foo: bar\r\n"), |
| 3753 | MockRead("Set-Cookie: foo=bar\r\n"), |
| 3754 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3755 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3756 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3757 | }; |
| 3758 | |
| 3759 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 3760 | arraysize(data_writes)); |
| 3761 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 3762 | |
| 3763 | TestCompletionCallback callback; |
| 3764 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3765 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3766 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3767 | |
| 3768 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3769 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3770 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3771 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3772 | ASSERT_TRUE(response); |
| 3773 | ASSERT_TRUE(response->headers); |
| 3774 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3775 | EXPECT_EQ(407, response->headers->response_code()); |
| 3776 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3777 | EXPECT_FALSE(response->headers->HasHeader("X-Foo")); |
| 3778 | EXPECT_FALSE(response->headers->HasHeader("Set-Cookie")); |
| 3779 | |
| 3780 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3781 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3782 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3783 | |
| 3784 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
| 3785 | session->CloseAllConnections(); |
| 3786 | } |
| 3787 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3788 | // Test when a server (non-proxy) returns a 407 (proxy-authenticate). |
| 3789 | // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3790 | TEST_F(HttpNetworkTransactionTest, UnexpectedProxyAuth) { |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3791 | HttpRequestInfo request; |
| 3792 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3793 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3794 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3795 | // We are using a DIRECT connection (i.e. no proxy) for this session. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3796 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3797 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3798 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3799 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3800 | MockWrite( |
| 3801 | "GET / HTTP/1.1\r\n" |
| 3802 | "Host: www.example.org\r\n" |
| 3803 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3804 | }; |
| 3805 | |
| 3806 | MockRead data_reads1[] = { |
| 3807 | MockRead("HTTP/1.0 407 Proxy Auth required\r\n"), |
| 3808 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3809 | // Large content-length -- won't matter, as connection will be reset. |
| 3810 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3811 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3812 | }; |
| 3813 | |
| 3814 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3815 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3816 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3817 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3818 | TestCompletionCallback callback; |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3819 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3820 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3821 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3822 | |
| 3823 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3824 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3825 | } |
| 3826 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3827 | // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) |
| 3828 | // through a non-authenticating proxy. The request should fail with |
| 3829 | // ERR_UNEXPECTED_PROXY_AUTH. |
| 3830 | // Note that it is impossible to detect if an HTTP server returns a 407 through |
| 3831 | // a non-authenticating proxy - there is nothing to indicate whether the |
| 3832 | // response came from the proxy or the server, so it is treated as if the proxy |
| 3833 | // issued the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3834 | TEST_F(HttpNetworkTransactionTest, HttpsServerRequestsProxyAuthThroughProxy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3835 | HttpRequestInfo request; |
| 3836 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3837 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3838 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3839 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3840 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3841 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3842 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3843 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3844 | // Since we have proxy, should try to establish tunnel. |
| 3845 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3846 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3847 | "Host: www.example.org:443\r\n" |
| 3848 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3849 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3850 | MockWrite("GET / HTTP/1.1\r\n" |
| 3851 | "Host: www.example.org\r\n" |
| 3852 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3853 | }; |
| 3854 | |
| 3855 | MockRead data_reads1[] = { |
| 3856 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3857 | |
| 3858 | MockRead("HTTP/1.1 407 Unauthorized\r\n"), |
| 3859 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3860 | MockRead("\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3861 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3862 | }; |
| 3863 | |
| 3864 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3865 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3866 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3867 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3868 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3869 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3870 | TestCompletionCallback callback1; |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3871 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3872 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3873 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3874 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3875 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3876 | |
| 3877 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3878 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3879 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3880 | log.GetEntries(&entries); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3881 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3882 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3883 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3884 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3885 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3886 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3887 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3888 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3889 | |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3890 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 3891 | // that uses non-persistent connections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3892 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3893 | AuthAllowsDefaultCredentialsTunnelConnectionClose) { |
| 3894 | HttpRequestInfo request; |
| 3895 | request.method = "GET"; |
| 3896 | request.url = GURL("https://www.example.org/"); |
| 3897 | |
| 3898 | // Configure against proxy server "myproxy:70". |
| 3899 | session_deps_.proxy_service = |
| 3900 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 3901 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3902 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3903 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3904 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3905 | mock_handler->set_allows_default_credentials(true); |
| 3906 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3907 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 3908 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3909 | |
| 3910 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 3911 | NetLog net_log; |
| 3912 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3913 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3914 | |
| 3915 | // Since we have proxy, should try to establish tunnel. |
| 3916 | MockWrite data_writes1[] = { |
| 3917 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3918 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3919 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3920 | }; |
| 3921 | |
| 3922 | // The proxy responds to the connect with a 407, using a non-persistent |
| 3923 | // connection. |
| 3924 | MockRead data_reads1[] = { |
| 3925 | // No credentials. |
| 3926 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3927 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 3928 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3929 | }; |
| 3930 | |
| 3931 | // Since the first connection couldn't be reused, need to establish another |
| 3932 | // once given credentials. |
| 3933 | MockWrite data_writes2[] = { |
| 3934 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3935 | // be issuing -- the final header line contains the credentials. |
| 3936 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3937 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3938 | "Proxy-Connection: keep-alive\r\n" |
| 3939 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3940 | |
| 3941 | MockWrite("GET / HTTP/1.1\r\n" |
| 3942 | "Host: www.example.org\r\n" |
| 3943 | "Connection: keep-alive\r\n\r\n"), |
| 3944 | }; |
| 3945 | |
| 3946 | MockRead data_reads2[] = { |
| 3947 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3948 | |
| 3949 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3950 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3951 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3952 | MockRead(SYNCHRONOUS, "hello"), |
| 3953 | }; |
| 3954 | |
| 3955 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3956 | data_writes1, arraysize(data_writes1)); |
| 3957 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3958 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3959 | data_writes2, arraysize(data_writes2)); |
| 3960 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3961 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3962 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3963 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3964 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3965 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3966 | |
| 3967 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3968 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3969 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3970 | |
| 3971 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3972 | ASSERT_TRUE(response); |
| 3973 | ASSERT_TRUE(response->headers); |
| 3974 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
| 3975 | EXPECT_EQ(407, response->headers->response_code()); |
| 3976 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3977 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3978 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3979 | |
| 3980 | LoadTimingInfo load_timing_info; |
| 3981 | // CONNECT requests and responses are handled at the connect job level, so |
| 3982 | // the transaction does not yet have a connection. |
| 3983 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3984 | |
| 3985 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3986 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3987 | response = trans->GetResponseInfo(); |
| 3988 | ASSERT_TRUE(response); |
| 3989 | ASSERT_TRUE(response->headers); |
| 3990 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3991 | EXPECT_EQ(200, response->headers->response_code()); |
| 3992 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 3993 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3994 | |
| 3995 | // The password prompt info should not be set. |
| 3996 | EXPECT_FALSE(response->auth_challenge); |
| 3997 | |
| 3998 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3999 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4000 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4001 | |
| 4002 | trans.reset(); |
| 4003 | session->CloseAllConnections(); |
| 4004 | } |
| 4005 | |
| 4006 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4007 | // that hangs up when credentials are initially sent. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4008 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4009 | AuthAllowsDefaultCredentialsTunnelServerClosesConnection) { |
| 4010 | HttpRequestInfo request; |
| 4011 | request.method = "GET"; |
| 4012 | request.url = GURL("https://www.example.org/"); |
| 4013 | |
| 4014 | // Configure against proxy server "myproxy:70". |
| 4015 | session_deps_.proxy_service = |
| 4016 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 4017 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4018 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4019 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4020 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4021 | mock_handler->set_allows_default_credentials(true); |
| 4022 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4023 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4024 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4025 | |
| 4026 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4027 | NetLog net_log; |
| 4028 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4029 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4030 | |
| 4031 | // Should try to establish tunnel. |
| 4032 | MockWrite data_writes1[] = { |
| 4033 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4034 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4035 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4036 | |
| 4037 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4038 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4039 | "Proxy-Connection: keep-alive\r\n" |
| 4040 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4041 | }; |
| 4042 | |
| 4043 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4044 | // connection. |
| 4045 | MockRead data_reads1[] = { |
| 4046 | // No credentials. |
| 4047 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4048 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4049 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4050 | }; |
| 4051 | |
| 4052 | // Since the first connection was closed, need to establish another once given |
| 4053 | // credentials. |
| 4054 | MockWrite data_writes2[] = { |
| 4055 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4056 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4057 | "Proxy-Connection: keep-alive\r\n" |
| 4058 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4059 | |
| 4060 | MockWrite("GET / HTTP/1.1\r\n" |
| 4061 | "Host: www.example.org\r\n" |
| 4062 | "Connection: keep-alive\r\n\r\n"), |
| 4063 | }; |
| 4064 | |
| 4065 | MockRead data_reads2[] = { |
| 4066 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 4067 | |
| 4068 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4069 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4070 | MockRead("Content-Length: 5\r\n\r\n"), |
| 4071 | MockRead(SYNCHRONOUS, "hello"), |
| 4072 | }; |
| 4073 | |
| 4074 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4075 | data_writes1, arraysize(data_writes1)); |
| 4076 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4077 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4078 | data_writes2, arraysize(data_writes2)); |
| 4079 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4080 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4081 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4082 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4083 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4084 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4085 | |
| 4086 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4087 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4088 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4089 | |
| 4090 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4091 | ASSERT_TRUE(response); |
| 4092 | ASSERT_TRUE(response->headers); |
| 4093 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4094 | EXPECT_EQ(407, response->headers->response_code()); |
| 4095 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4096 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4097 | EXPECT_FALSE(response->auth_challenge); |
| 4098 | |
| 4099 | LoadTimingInfo load_timing_info; |
| 4100 | // CONNECT requests and responses are handled at the connect job level, so |
| 4101 | // the transaction does not yet have a connection. |
| 4102 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4103 | |
| 4104 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4105 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4106 | |
| 4107 | response = trans->GetResponseInfo(); |
| 4108 | ASSERT_TRUE(response); |
| 4109 | ASSERT_TRUE(response->headers); |
| 4110 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4111 | EXPECT_EQ(200, response->headers->response_code()); |
| 4112 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 4113 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4114 | |
| 4115 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4116 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4117 | |
| 4118 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4119 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4120 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4121 | |
| 4122 | trans.reset(); |
| 4123 | session->CloseAllConnections(); |
| 4124 | } |
| 4125 | |
| 4126 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4127 | // that hangs up when credentials are initially sent, and hangs up again when |
| 4128 | // they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4129 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4130 | AuthAllowsDefaultCredentialsTunnelServerClosesConnectionTwice) { |
| 4131 | HttpRequestInfo request; |
| 4132 | request.method = "GET"; |
| 4133 | request.url = GURL("https://www.example.org/"); |
| 4134 | |
| 4135 | // Configure against proxy server "myproxy:70". |
| 4136 | session_deps_.proxy_service = |
| 4137 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 4138 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4139 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4140 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4141 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4142 | mock_handler->set_allows_default_credentials(true); |
| 4143 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4144 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4145 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4146 | |
| 4147 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4148 | NetLog net_log; |
| 4149 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4150 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4151 | |
| 4152 | // Should try to establish tunnel. |
| 4153 | MockWrite data_writes1[] = { |
| 4154 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4155 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4156 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4157 | |
| 4158 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4159 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4160 | "Proxy-Connection: keep-alive\r\n" |
| 4161 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4162 | }; |
| 4163 | |
| 4164 | // The proxy responds to the connect with a 407, and then hangs up after the |
| 4165 | // second request is sent. |
| 4166 | MockRead data_reads1[] = { |
| 4167 | // No credentials. |
| 4168 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4169 | MockRead("Content-Length: 0\r\n"), |
| 4170 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4171 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4172 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4173 | }; |
| 4174 | |
| 4175 | // HttpNetworkTransaction sees a reused connection that was closed with |
| 4176 | // ERR_CONNECTION_CLOSED, realized it might have been a race, so retries the |
| 4177 | // request. |
| 4178 | MockWrite data_writes2[] = { |
| 4179 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4180 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4181 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4182 | }; |
| 4183 | |
| 4184 | // The proxy, having had more than enough of us, just hangs up. |
| 4185 | MockRead data_reads2[] = { |
| 4186 | // No credentials. |
| 4187 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4188 | }; |
| 4189 | |
| 4190 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4191 | data_writes1, arraysize(data_writes1)); |
| 4192 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4193 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4194 | data_writes2, arraysize(data_writes2)); |
| 4195 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4196 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4197 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4198 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4199 | |
| 4200 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4201 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4202 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4203 | |
| 4204 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4205 | ASSERT_TRUE(response); |
| 4206 | ASSERT_TRUE(response->headers); |
| 4207 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4208 | EXPECT_EQ(407, response->headers->response_code()); |
| 4209 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4210 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4211 | EXPECT_FALSE(response->auth_challenge); |
| 4212 | |
| 4213 | LoadTimingInfo load_timing_info; |
| 4214 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4215 | |
| 4216 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4217 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4218 | |
| 4219 | trans.reset(); |
| 4220 | session->CloseAllConnections(); |
| 4221 | } |
| 4222 | |
| 4223 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4224 | // that hangs up when credentials are initially sent, and sends a challenge |
| 4225 | // again they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4226 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4227 | AuthAllowsDefaultCredentialsTunnelServerChallengesTwice) { |
| 4228 | HttpRequestInfo request; |
| 4229 | request.method = "GET"; |
| 4230 | request.url = GURL("https://www.example.org/"); |
| 4231 | |
| 4232 | // Configure against proxy server "myproxy:70". |
| 4233 | session_deps_.proxy_service = |
| 4234 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 4235 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4236 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4237 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4238 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4239 | mock_handler->set_allows_default_credentials(true); |
| 4240 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4241 | HttpAuth::AUTH_PROXY); |
| 4242 | // Add another handler for the second challenge. It supports default |
| 4243 | // credentials, but they shouldn't be used, since they were already tried. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4244 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4245 | mock_handler->set_allows_default_credentials(true); |
| 4246 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4247 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4248 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4249 | |
| 4250 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4251 | NetLog net_log; |
| 4252 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4253 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4254 | |
| 4255 | // Should try to establish tunnel. |
| 4256 | MockWrite data_writes1[] = { |
| 4257 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4258 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4259 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4260 | }; |
| 4261 | |
| 4262 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4263 | // connection. |
| 4264 | MockRead data_reads1[] = { |
| 4265 | // No credentials. |
| 4266 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4267 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4268 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4269 | }; |
| 4270 | |
| 4271 | // Since the first connection was closed, need to establish another once given |
| 4272 | // credentials. |
| 4273 | MockWrite data_writes2[] = { |
| 4274 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4275 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4276 | "Proxy-Connection: keep-alive\r\n" |
| 4277 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4278 | }; |
| 4279 | |
| 4280 | MockRead data_reads2[] = { |
| 4281 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4282 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4283 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4284 | }; |
| 4285 | |
| 4286 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4287 | data_writes1, arraysize(data_writes1)); |
| 4288 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4289 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4290 | data_writes2, arraysize(data_writes2)); |
| 4291 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4292 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4293 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4294 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4295 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4296 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4297 | |
| 4298 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4299 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4300 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4301 | |
| 4302 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4303 | ASSERT_TRUE(response); |
| 4304 | ASSERT_TRUE(response->headers); |
| 4305 | EXPECT_EQ(407, response->headers->response_code()); |
| 4306 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4307 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4308 | EXPECT_FALSE(response->auth_challenge); |
| 4309 | |
| 4310 | LoadTimingInfo load_timing_info; |
| 4311 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4312 | |
| 4313 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4314 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4315 | response = trans->GetResponseInfo(); |
| 4316 | ASSERT_TRUE(response); |
| 4317 | ASSERT_TRUE(response->headers); |
| 4318 | EXPECT_EQ(407, response->headers->response_code()); |
| 4319 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4320 | EXPECT_TRUE(response->auth_challenge); |
| 4321 | |
| 4322 | trans.reset(); |
| 4323 | session->CloseAllConnections(); |
| 4324 | } |
| 4325 | |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4326 | // A more nuanced test than GenerateAuthToken test which asserts that |
| 4327 | // ERR_INVALID_AUTH_CREDENTIALS does not cause the auth scheme to be |
| 4328 | // unnecessarily invalidated, and that if the server co-operates, the |
| 4329 | // authentication handshake can continue with the same scheme but with a |
| 4330 | // different identity. |
| 4331 | TEST_F(HttpNetworkTransactionTest, NonPermanentGenerateAuthTokenError) { |
| 4332 | HttpRequestInfo request; |
| 4333 | request.method = "GET"; |
| 4334 | request.url = GURL("http://www.example.org/"); |
| 4335 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4336 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4337 | auth_handler_factory->set_do_init_from_challenge(true); |
| 4338 | |
| 4339 | // First handler. Uses default credentials, but barfs at generate auth token. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4340 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4341 | mock_handler->set_allows_default_credentials(true); |
| 4342 | mock_handler->set_allows_explicit_credentials(true); |
| 4343 | mock_handler->set_connection_based(true); |
| 4344 | mock_handler->SetGenerateExpectation(true, ERR_INVALID_AUTH_CREDENTIALS); |
| 4345 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4346 | HttpAuth::AUTH_SERVER); |
| 4347 | |
| 4348 | // Add another handler for the second challenge. It supports default |
| 4349 | // credentials, but they shouldn't be used, since they were already tried. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4350 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4351 | mock_handler->set_allows_default_credentials(true); |
| 4352 | mock_handler->set_allows_explicit_credentials(true); |
| 4353 | mock_handler->set_connection_based(true); |
| 4354 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4355 | HttpAuth::AUTH_SERVER); |
| 4356 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
| 4357 | |
| 4358 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4359 | |
| 4360 | MockWrite data_writes1[] = { |
| 4361 | MockWrite("GET / HTTP/1.1\r\n" |
| 4362 | "Host: www.example.org\r\n" |
| 4363 | "Connection: keep-alive\r\n\r\n"), |
| 4364 | }; |
| 4365 | |
| 4366 | MockRead data_reads1[] = { |
| 4367 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4368 | "WWW-Authenticate: Mock\r\n" |
| 4369 | "Connection: keep-alive\r\n\r\n"), |
| 4370 | }; |
| 4371 | |
| 4372 | // Identical to data_writes1[]. The AuthHandler encounters a |
| 4373 | // ERR_INVALID_AUTH_CREDENTIALS during the GenerateAuthToken stage, so the |
| 4374 | // transaction procceds without an authorization header. |
| 4375 | MockWrite data_writes2[] = { |
| 4376 | MockWrite("GET / HTTP/1.1\r\n" |
| 4377 | "Host: www.example.org\r\n" |
| 4378 | "Connection: keep-alive\r\n\r\n"), |
| 4379 | }; |
| 4380 | |
| 4381 | MockRead data_reads2[] = { |
| 4382 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4383 | "WWW-Authenticate: Mock\r\n" |
| 4384 | "Connection: keep-alive\r\n\r\n"), |
| 4385 | }; |
| 4386 | |
| 4387 | MockWrite data_writes3[] = { |
| 4388 | MockWrite("GET / HTTP/1.1\r\n" |
| 4389 | "Host: www.example.org\r\n" |
| 4390 | "Connection: keep-alive\r\n" |
| 4391 | "Authorization: auth_token\r\n\r\n"), |
| 4392 | }; |
| 4393 | |
| 4394 | MockRead data_reads3[] = { |
| 4395 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4396 | "Content-Length: 5\r\n" |
| 4397 | "Content-Type: text/plain\r\n" |
| 4398 | "Connection: keep-alive\r\n\r\n" |
| 4399 | "Hello"), |
| 4400 | }; |
| 4401 | |
| 4402 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4403 | data_writes1, arraysize(data_writes1)); |
| 4404 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4405 | |
| 4406 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4407 | data_writes2, arraysize(data_writes2)); |
| 4408 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4409 | |
| 4410 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 4411 | data_writes3, arraysize(data_writes3)); |
| 4412 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 4413 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4414 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4415 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4416 | |
| 4417 | TestCompletionCallback callback; |
| 4418 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 4419 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4420 | |
| 4421 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4422 | ASSERT_TRUE(response); |
| 4423 | ASSERT_TRUE(response->headers); |
| 4424 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4425 | |
| 4426 | // The following three tests assert that an authentication challenge was |
| 4427 | // received and that the stack is ready to respond to the challenge using |
| 4428 | // ambient credentials. |
| 4429 | EXPECT_EQ(401, response->headers->response_code()); |
| 4430 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4431 | EXPECT_FALSE(response->auth_challenge); |
| 4432 | |
| 4433 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4434 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4435 | response = trans->GetResponseInfo(); |
| 4436 | ASSERT_TRUE(response); |
| 4437 | ASSERT_TRUE(response->headers); |
| 4438 | |
| 4439 | // The following three tests assert that an authentication challenge was |
| 4440 | // received and that the stack needs explicit credentials before it is ready |
| 4441 | // to respond to the challenge. |
| 4442 | EXPECT_EQ(401, response->headers->response_code()); |
| 4443 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4444 | EXPECT_TRUE(response->auth_challenge); |
| 4445 | |
| 4446 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4447 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4448 | response = trans->GetResponseInfo(); |
| 4449 | ASSERT_TRUE(response); |
| 4450 | ASSERT_TRUE(response->headers); |
| 4451 | EXPECT_EQ(200, response->headers->response_code()); |
| 4452 | |
| 4453 | trans.reset(); |
| 4454 | session->CloseAllConnections(); |
| 4455 | } |
| 4456 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4457 | // Test the load timing for HTTPS requests with an HTTP proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4458 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingNoPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4459 | HttpRequestInfo request1; |
| 4460 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4461 | request1.url = GURL("https://www.example.org/1"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4462 | |
| 4463 | HttpRequestInfo request2; |
| 4464 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4465 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4466 | |
| 4467 | // Configure against proxy server "myproxy:70". |
brettw | c1213d9 | 2016-11-12 03:41:13 | [diff] [blame] | 4468 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4469 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4470 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4471 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4472 | |
| 4473 | // Since we have proxy, should try to establish tunnel. |
| 4474 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4475 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4476 | "Host: www.example.org:443\r\n" |
| 4477 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4478 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4479 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 4480 | "Host: www.example.org\r\n" |
| 4481 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4482 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4483 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 4484 | "Host: www.example.org\r\n" |
| 4485 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4486 | }; |
| 4487 | |
| 4488 | // The proxy responds to the connect with a 407, using a persistent |
| 4489 | // connection. |
| 4490 | MockRead data_reads1[] = { |
| 4491 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4492 | |
| 4493 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4494 | MockRead("Content-Length: 1\r\n\r\n"), |
| 4495 | MockRead(SYNCHRONOUS, "1"), |
| 4496 | |
| 4497 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4498 | MockRead("Content-Length: 2\r\n\r\n"), |
| 4499 | MockRead(SYNCHRONOUS, "22"), |
| 4500 | }; |
| 4501 | |
| 4502 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4503 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4504 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4505 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4506 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4507 | |
| 4508 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4509 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4510 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4511 | |
| 4512 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4513 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4514 | |
| 4515 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4516 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4517 | |
| 4518 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4519 | ASSERT_TRUE(response1); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4520 | EXPECT_TRUE(response1->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4521 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4522 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 4523 | |
| 4524 | LoadTimingInfo load_timing_info1; |
| 4525 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 4526 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4527 | |
| 4528 | trans1.reset(); |
| 4529 | |
| 4530 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4531 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4532 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4533 | |
| 4534 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4535 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4536 | |
| 4537 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4538 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4539 | |
| 4540 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4541 | ASSERT_TRUE(response2); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4542 | EXPECT_TRUE(response2->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4543 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4544 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 4545 | |
| 4546 | LoadTimingInfo load_timing_info2; |
| 4547 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4548 | TestLoadTimingReused(load_timing_info2); |
| 4549 | |
| 4550 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 4551 | |
| 4552 | trans2.reset(); |
| 4553 | session->CloseAllConnections(); |
| 4554 | } |
| 4555 | |
| 4556 | // 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] | 4557 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingWithPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4558 | HttpRequestInfo request1; |
| 4559 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4560 | request1.url = GURL("https://www.example.org/1"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4561 | |
| 4562 | HttpRequestInfo request2; |
| 4563 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4564 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4565 | |
| 4566 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4567 | session_deps_.proxy_service = |
| 4568 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4569 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4570 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4571 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4572 | |
| 4573 | // Since we have proxy, should try to establish tunnel. |
| 4574 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4575 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4576 | "Host: www.example.org:443\r\n" |
| 4577 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4578 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4579 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 4580 | "Host: www.example.org\r\n" |
| 4581 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4582 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4583 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 4584 | "Host: www.example.org\r\n" |
| 4585 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4586 | }; |
| 4587 | |
| 4588 | // The proxy responds to the connect with a 407, using a persistent |
| 4589 | // connection. |
| 4590 | MockRead data_reads1[] = { |
| 4591 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4592 | |
| 4593 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4594 | MockRead("Content-Length: 1\r\n\r\n"), |
| 4595 | MockRead(SYNCHRONOUS, "1"), |
| 4596 | |
| 4597 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4598 | MockRead("Content-Length: 2\r\n\r\n"), |
| 4599 | MockRead(SYNCHRONOUS, "22"), |
| 4600 | }; |
| 4601 | |
| 4602 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4603 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4604 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4605 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4606 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4607 | |
| 4608 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4609 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4610 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4611 | |
| 4612 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4613 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4614 | |
| 4615 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4616 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4617 | |
| 4618 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4619 | ASSERT_TRUE(response1); |
| 4620 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4621 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 4622 | |
| 4623 | LoadTimingInfo load_timing_info1; |
| 4624 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 4625 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 4626 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4627 | |
| 4628 | trans1.reset(); |
| 4629 | |
| 4630 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4631 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4632 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4633 | |
| 4634 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4635 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4636 | |
| 4637 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4638 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4639 | |
| 4640 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4641 | ASSERT_TRUE(response2); |
| 4642 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4643 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 4644 | |
| 4645 | LoadTimingInfo load_timing_info2; |
| 4646 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4647 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 4648 | |
| 4649 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 4650 | |
| 4651 | trans2.reset(); |
| 4652 | session->CloseAllConnections(); |
| 4653 | } |
| 4654 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4655 | // Test a simple get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4656 | TEST_F(HttpNetworkTransactionTest, HttpsProxyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4657 | HttpRequestInfo request; |
| 4658 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4659 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4660 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4661 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4662 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4663 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4664 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4665 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4666 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4667 | // Since we have proxy, should use full url |
| 4668 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4669 | MockWrite( |
| 4670 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 4671 | "Host: www.example.org\r\n" |
| 4672 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4673 | }; |
| 4674 | |
| 4675 | MockRead data_reads1[] = { |
| 4676 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4677 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4678 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4679 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4680 | }; |
| 4681 | |
| 4682 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4683 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4684 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4685 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4686 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4687 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4688 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4689 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4690 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4691 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4692 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4693 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4694 | |
| 4695 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4696 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4697 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4698 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4699 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4700 | TestLoadTimingNotReused(load_timing_info, |
| 4701 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4702 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4703 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4704 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4705 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4706 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4707 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4708 | EXPECT_EQ(200, response->headers->response_code()); |
| 4709 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 4710 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4711 | |
| 4712 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4713 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4714 | } |
| 4715 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4716 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4717 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4718 | HttpRequestInfo request; |
| 4719 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4720 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4721 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4722 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4723 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4724 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4725 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4726 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4727 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4728 | // fetch http://www.example.org/ via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4729 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 4730 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4731 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4732 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4733 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4734 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4735 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4736 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4737 | }; |
| 4738 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4739 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4740 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4741 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4742 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4743 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4744 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4745 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4746 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4747 | TestCompletionCallback callback1; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4748 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4749 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4750 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4751 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4752 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4753 | |
| 4754 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4755 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4756 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4757 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4758 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4759 | TestLoadTimingNotReused(load_timing_info, |
| 4760 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4761 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4762 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4763 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4764 | EXPECT_TRUE(response->proxy_server.is_https()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4765 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4766 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4767 | |
| 4768 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4769 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 4770 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4771 | } |
| 4772 | |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4773 | // Verifies that a session which races and wins against the owning transaction |
| 4774 | // (completing prior to host resolution), doesn't fail the transaction. |
| 4775 | // Regression test for crbug.com/334413. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4776 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithSessionRace) { |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4777 | HttpRequestInfo request; |
| 4778 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4779 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4780 | |
| 4781 | // Configure SPDY proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4782 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4783 | BoundTestNetLog log; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4784 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4785 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4786 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4787 | // Fetch http://www.example.org/ through the SPDY proxy. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4788 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 4789 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4790 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4791 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4792 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4793 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4794 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4795 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4796 | }; |
| 4797 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4798 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4799 | arraysize(spdy_writes)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4800 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 4801 | |
| 4802 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4803 | ssl.next_proto = kProtoHTTP2; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4804 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4805 | |
| 4806 | TestCompletionCallback callback1; |
| 4807 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4808 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4809 | |
| 4810 | // Stall the hostname resolution begun by the transaction. |
| 4811 | session_deps_.host_resolver->set_synchronous_mode(false); |
| 4812 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 4813 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4814 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4815 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4816 | |
| 4817 | // Race a session to the proxy, which completes first. |
| 4818 | session_deps_.host_resolver->set_ondemand_mode(false); |
| 4819 | SpdySessionKey key( |
| 4820 | HostPortPair("proxy", 70), ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
| 4821 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 4822 | CreateSpdySession(session.get(), key, log.bound()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4823 | |
| 4824 | // Unstall the resolution begun by the transaction. |
| 4825 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 4826 | session_deps_.host_resolver->ResolveAllPending(); |
| 4827 | |
| 4828 | EXPECT_FALSE(callback1.have_result()); |
| 4829 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4830 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4831 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4832 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4833 | ASSERT_TRUE(response); |
| 4834 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4835 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4836 | |
| 4837 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4838 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4839 | EXPECT_EQ(kUploadData, response_data); |
| 4840 | } |
| 4841 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4842 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4843 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4844 | HttpRequestInfo request; |
| 4845 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4846 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4847 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4848 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4849 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4850 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4851 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4852 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4853 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4854 | // The first request will be a bare GET, the second request will be a |
| 4855 | // GET with a Proxy-Authorization header. |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 4856 | spdy_util_.set_default_url(request.url); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4857 | SpdySerializedFrame req_get( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4858 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, false)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4859 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4860 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4861 | "proxy-authorization", "Basic Zm9vOmJhcg==" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4862 | }; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4863 | SpdySerializedFrame req_get_authorization(spdy_util_.ConstructSpdyGet( |
| 4864 | kExtraAuthorizationHeaders, arraysize(kExtraAuthorizationHeaders) / 2, 3, |
| 4865 | LOWEST, false)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4866 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4867 | CreateMockWrite(req_get, 0), CreateMockWrite(req_get_authorization, 3), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4868 | }; |
| 4869 | |
| 4870 | // The first response is a 407 proxy authentication challenge, and the second |
| 4871 | // response will be a 200 response since the second request includes a valid |
| 4872 | // Authorization header. |
| 4873 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4874 | "proxy-authenticate", "Basic realm=\"MyRealm1\"" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4875 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4876 | SpdySerializedFrame resp_authentication(spdy_util_.ConstructSpdyReplyError( |
bnc | c9f762a | 2016-12-06 20:38:23 | [diff] [blame] | 4877 | "407", kExtraAuthenticationHeaders, |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4878 | arraysize(kExtraAuthenticationHeaders) / 2, 1)); |
| 4879 | SpdySerializedFrame body_authentication( |
| 4880 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4881 | SpdySerializedFrame resp_data(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4882 | SpdySerializedFrame body_data(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4883 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4884 | CreateMockRead(resp_authentication, 1), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 4885 | CreateMockRead(body_authentication, 2, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4886 | CreateMockRead(resp_data, 4), |
| 4887 | CreateMockRead(body_data, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4888 | MockRead(ASYNC, 0, 6), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4889 | }; |
| 4890 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4891 | SequencedSocketData data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4892 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4893 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4894 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4895 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4896 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4897 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4898 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4899 | TestCompletionCallback callback1; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4900 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4901 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4902 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4903 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4904 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4905 | |
| 4906 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4907 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4908 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4909 | const HttpResponseInfo* const response = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4910 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4911 | ASSERT_TRUE(response); |
| 4912 | ASSERT_TRUE(response->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4913 | EXPECT_EQ(407, response->headers->response_code()); |
| 4914 | EXPECT_TRUE(response->was_fetched_via_spdy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 4915 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4916 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4917 | TestCompletionCallback callback2; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4918 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4919 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4920 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4921 | |
| 4922 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4923 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4924 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4925 | const HttpResponseInfo* const response_restart = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4926 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4927 | ASSERT_TRUE(response_restart); |
| 4928 | ASSERT_TRUE(response_restart->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4929 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 4930 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4931 | EXPECT_FALSE(response_restart->auth_challenge); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4932 | } |
| 4933 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4934 | // Test a SPDY CONNECT through an HTTPS Proxy to an HTTPS (non-SPDY) Server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4935 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4936 | HttpRequestInfo request; |
| 4937 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4938 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4939 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4940 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4941 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4942 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4943 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4944 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4945 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4946 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4947 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4948 | // CONNECT to www.example.org:443 via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4949 | SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4950 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 4951 | // fetch https://www.example.org/ via HTTP |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4952 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4953 | const char get[] = |
| 4954 | "GET / HTTP/1.1\r\n" |
| 4955 | "Host: www.example.org\r\n" |
| 4956 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4957 | SpdySerializedFrame wrapped_get( |
| 4958 | spdy_util_.ConstructSpdyDataFrame(1, get, strlen(get), false)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4959 | SpdySerializedFrame conn_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4960 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 4961 | "Content-Length: 10\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4962 | SpdySerializedFrame wrapped_get_resp( |
| 4963 | spdy_util_.ConstructSpdyDataFrame(1, resp, strlen(resp), false)); |
| 4964 | SpdySerializedFrame wrapped_body( |
| 4965 | spdy_util_.ConstructSpdyDataFrame(1, "1234567890", 10, false)); |
| 4966 | SpdySerializedFrame window_update( |
| 4967 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4968 | |
| 4969 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4970 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 4971 | CreateMockWrite(window_update, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4972 | }; |
| 4973 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4974 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4975 | CreateMockRead(conn_resp, 1, ASYNC), |
| 4976 | CreateMockRead(wrapped_get_resp, 3, ASYNC), |
| 4977 | CreateMockRead(wrapped_body, 4, ASYNC), |
| 4978 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4979 | MockRead(ASYNC, 0, 7), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4980 | }; |
| 4981 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4982 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4983 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4984 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4985 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4986 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4987 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4988 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4989 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4990 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4991 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4992 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4993 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4994 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4995 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4996 | |
| 4997 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4998 | ASSERT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4999 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5000 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5001 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5002 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5003 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5004 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5005 | ASSERT_TRUE(response); |
| 5006 | ASSERT_TRUE(response->headers); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5007 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5008 | |
| 5009 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5010 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5011 | EXPECT_EQ("1234567890", response_data); |
| 5012 | } |
| 5013 | |
| 5014 | // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5015 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) { |
| 5016 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5017 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5018 | HttpRequestInfo request; |
| 5019 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5020 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5021 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5022 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5023 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5024 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5025 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5026 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5027 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5028 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5029 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5030 | // CONNECT to www.example.org:443 via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5031 | SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5032 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 5033 | // fetch https://www.example.org/ via SPDY |
| 5034 | const char kMyUrl[] = "https://www.example.org/"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5035 | SpdySerializedFrame get( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 5036 | spdy_util_wrapped.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5037 | SpdySerializedFrame wrapped_get(spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5038 | SpdySerializedFrame conn_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5039 | SpdySerializedFrame get_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5040 | spdy_util_wrapped.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5041 | SpdySerializedFrame wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5042 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5043 | SpdySerializedFrame body(spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 5044 | SpdySerializedFrame wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5045 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5046 | SpdySerializedFrame window_update_get_resp( |
| 5047 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
| 5048 | SpdySerializedFrame window_update_body( |
| 5049 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5050 | |
| 5051 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5052 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 5053 | CreateMockWrite(window_update_get_resp, 6), |
| 5054 | CreateMockWrite(window_update_body, 7), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5055 | }; |
| 5056 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5057 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5058 | CreateMockRead(conn_resp, 1, ASYNC), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5059 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5060 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 5061 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5062 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5063 | }; |
| 5064 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5065 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5066 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5067 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5068 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5069 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5070 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5071 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5072 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5073 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5074 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5075 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5076 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5077 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5078 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5079 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5080 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5081 | // Allow the SpdyProxyClientSocket's write callback to complete. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 5082 | base::RunLoop().RunUntilIdle(); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5083 | // Now allow the read of the response to complete. |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 5084 | spdy_data.Resume(); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5085 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5086 | EXPECT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5087 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5088 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5089 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5090 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5091 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5092 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5093 | ASSERT_TRUE(response); |
| 5094 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5095 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5096 | |
| 5097 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5098 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5099 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5100 | } |
| 5101 | |
| 5102 | // Test a SPDY CONNECT failure through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5103 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5104 | HttpRequestInfo request; |
| 5105 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5106 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5107 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5108 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5109 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5110 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5111 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5112 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5113 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5114 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5115 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5116 | // CONNECT to www.example.org:443 via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5117 | SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5118 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5119 | SpdySerializedFrame get( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 5120 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5121 | |
| 5122 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5123 | CreateMockWrite(connect, 0), CreateMockWrite(get, 2), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5124 | }; |
| 5125 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5126 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError(1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5127 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5128 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5129 | CreateMockRead(resp, 1, ASYNC), MockRead(ASYNC, 0, 3), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5130 | }; |
| 5131 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5132 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5133 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5134 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5135 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5136 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5137 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5138 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5139 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5140 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5141 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5142 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5143 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5144 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5145 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5146 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5147 | |
| 5148 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5149 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5150 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 5151 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5152 | } |
| 5153 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5154 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 5155 | // HTTPS Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5156 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5157 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) { |
| 5158 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5159 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5160 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5161 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5162 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5163 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5164 | |
| 5165 | HttpRequestInfo request1; |
| 5166 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5167 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5168 | request1.load_flags = 0; |
| 5169 | |
| 5170 | HttpRequestInfo request2; |
| 5171 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5172 | request2.url = GURL("https://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5173 | request2.load_flags = 0; |
| 5174 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5175 | // CONNECT to www.example.org:443 via SPDY. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5176 | SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5177 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5178 | SpdySerializedFrame conn_resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5179 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5180 | // Fetch https://www.example.org/ via HTTP. |
| 5181 | const char get1[] = |
| 5182 | "GET / HTTP/1.1\r\n" |
| 5183 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5184 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5185 | SpdySerializedFrame wrapped_get1( |
| 5186 | spdy_util_.ConstructSpdyDataFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5187 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 5188 | "Content-Length: 1\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5189 | SpdySerializedFrame wrapped_get_resp1( |
| 5190 | spdy_util_.ConstructSpdyDataFrame(1, resp1, strlen(resp1), false)); |
| 5191 | SpdySerializedFrame wrapped_body1( |
| 5192 | spdy_util_.ConstructSpdyDataFrame(1, "1", 1, false)); |
| 5193 | SpdySerializedFrame window_update( |
| 5194 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5195 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5196 | // CONNECT to mail.example.org:443 via SPDY. |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 5197 | SpdyHeaderBlock connect2_block; |
Bence Béky | bda8295 | 2017-10-02 17:35:27 | [diff] [blame] | 5198 | connect2_block[kHttp2MethodHeader] = "CONNECT"; |
| 5199 | connect2_block[kHttp2AuthorityHeader] = "mail.example.org:443"; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5200 | SpdySerializedFrame connect2(spdy_util_.ConstructSpdyHeaders( |
| 5201 | 3, std::move(connect2_block), LOWEST, false)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 5202 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5203 | SpdySerializedFrame conn_resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5204 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5205 | // Fetch https://mail.example.org/ via HTTP. |
| 5206 | const char get2[] = |
| 5207 | "GET / HTTP/1.1\r\n" |
| 5208 | "Host: mail.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5209 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5210 | SpdySerializedFrame wrapped_get2( |
| 5211 | spdy_util_.ConstructSpdyDataFrame(3, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5212 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 5213 | "Content-Length: 2\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5214 | SpdySerializedFrame wrapped_get_resp2( |
| 5215 | spdy_util_.ConstructSpdyDataFrame(3, resp2, strlen(resp2), false)); |
| 5216 | SpdySerializedFrame wrapped_body2( |
| 5217 | spdy_util_.ConstructSpdyDataFrame(3, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5218 | |
| 5219 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5220 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 5221 | CreateMockWrite(connect2, 5), CreateMockWrite(wrapped_get2, 7), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5222 | }; |
| 5223 | |
| 5224 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5225 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 5226 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
| 5227 | CreateMockRead(wrapped_body1, 4, ASYNC), |
| 5228 | CreateMockRead(conn_resp2, 6, ASYNC), |
| 5229 | CreateMockRead(wrapped_get_resp2, 8, ASYNC), |
| 5230 | CreateMockRead(wrapped_body2, 9, ASYNC), |
| 5231 | MockRead(ASYNC, 0, 10), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5232 | }; |
| 5233 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5234 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5235 | arraysize(spdy_writes)); |
| 5236 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5237 | |
| 5238 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5239 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5240 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5241 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5242 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5243 | SSLSocketDataProvider ssl3(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5244 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5245 | |
| 5246 | TestCompletionCallback callback; |
| 5247 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5248 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5249 | int rv = trans.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5250 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5251 | |
| 5252 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5253 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5254 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5255 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5256 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5257 | ASSERT_TRUE(response); |
| 5258 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5259 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5260 | |
| 5261 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5262 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5263 | rv = trans.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5264 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5265 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5266 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5267 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5268 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5269 | |
| 5270 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5271 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5272 | // Even though the SPDY connection is reused, a new tunnelled connection has |
| 5273 | // to be created, so the socket's load timing looks like a fresh connection. |
| 5274 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5275 | |
| 5276 | // The requests should have different IDs, since they each are using their own |
| 5277 | // separate stream. |
| 5278 | EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5279 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5280 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5281 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5282 | } |
| 5283 | |
| 5284 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 5285 | // HTTPS Proxy to the same server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5286 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5287 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) { |
| 5288 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5289 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5290 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5291 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5292 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5293 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5294 | |
| 5295 | HttpRequestInfo request1; |
| 5296 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5297 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5298 | request1.load_flags = 0; |
| 5299 | |
| 5300 | HttpRequestInfo request2; |
| 5301 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5302 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5303 | request2.load_flags = 0; |
| 5304 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5305 | // CONNECT to www.example.org:443 via SPDY. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5306 | SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5307 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5308 | SpdySerializedFrame conn_resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5309 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5310 | // Fetch https://www.example.org/ via HTTP. |
| 5311 | const char get1[] = |
| 5312 | "GET / HTTP/1.1\r\n" |
| 5313 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5314 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5315 | SpdySerializedFrame wrapped_get1( |
| 5316 | spdy_util_.ConstructSpdyDataFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5317 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 5318 | "Content-Length: 1\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5319 | SpdySerializedFrame wrapped_get_resp1( |
| 5320 | spdy_util_.ConstructSpdyDataFrame(1, resp1, strlen(resp1), false)); |
| 5321 | SpdySerializedFrame wrapped_body1( |
| 5322 | spdy_util_.ConstructSpdyDataFrame(1, "1", 1, false)); |
| 5323 | SpdySerializedFrame window_update( |
| 5324 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5325 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5326 | // Fetch https://www.example.org/2 via HTTP. |
| 5327 | const char get2[] = |
| 5328 | "GET /2 HTTP/1.1\r\n" |
| 5329 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5330 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5331 | SpdySerializedFrame wrapped_get2( |
| 5332 | spdy_util_.ConstructSpdyDataFrame(1, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5333 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 5334 | "Content-Length: 2\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5335 | SpdySerializedFrame wrapped_get_resp2( |
| 5336 | spdy_util_.ConstructSpdyDataFrame(1, resp2, strlen(resp2), false)); |
| 5337 | SpdySerializedFrame wrapped_body2( |
| 5338 | spdy_util_.ConstructSpdyDataFrame(1, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5339 | |
| 5340 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5341 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 5342 | CreateMockWrite(wrapped_get2, 5), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5343 | }; |
| 5344 | |
| 5345 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5346 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 5347 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5348 | CreateMockRead(wrapped_body1, 4, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5349 | CreateMockRead(wrapped_get_resp2, 6, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5350 | CreateMockRead(wrapped_body2, 7, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5351 | MockRead(ASYNC, 0, 8), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5352 | }; |
| 5353 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5354 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5355 | arraysize(spdy_writes)); |
| 5356 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5357 | |
| 5358 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5359 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5360 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5361 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5362 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5363 | |
| 5364 | TestCompletionCallback callback; |
| 5365 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5366 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5367 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5368 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5369 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5370 | |
| 5371 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5372 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5373 | |
| 5374 | LoadTimingInfo load_timing_info; |
| 5375 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5376 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5377 | |
| 5378 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5379 | ASSERT_TRUE(response); |
| 5380 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5381 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5382 | |
| 5383 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5384 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5385 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5386 | trans.reset(); |
| 5387 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5388 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5389 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5390 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5391 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5392 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5393 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5394 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5395 | |
| 5396 | LoadTimingInfo load_timing_info2; |
| 5397 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 5398 | TestLoadTimingReused(load_timing_info2); |
| 5399 | |
| 5400 | // The requests should have the same ID. |
| 5401 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5402 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5403 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5404 | } |
| 5405 | |
| 5406 | // Test load timing in the case of of two HTTP requests through a SPDY HTTPS |
| 5407 | // Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5408 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyLoadTimingTwoHttpRequests) { |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5409 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5410 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5411 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5412 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5413 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5414 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5415 | |
| 5416 | HttpRequestInfo request1; |
| 5417 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5418 | request1.url = GURL("http://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5419 | request1.load_flags = 0; |
| 5420 | |
| 5421 | HttpRequestInfo request2; |
| 5422 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5423 | request2.url = GURL("http://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5424 | request2.load_flags = 0; |
| 5425 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5426 | // http://www.example.org/ |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 5427 | SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5428 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5429 | SpdySerializedFrame get1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5430 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
| 5431 | SpdySerializedFrame get_resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5432 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, "1", 1, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5433 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5434 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5435 | // http://mail.example.org/ |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 5436 | SpdyHeaderBlock headers2( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5437 | spdy_util_.ConstructGetHeaderBlockForProxy("http://mail.example.org/")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5438 | SpdySerializedFrame get2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5439 | spdy_util_.ConstructSpdyHeaders(3, std::move(headers2), LOWEST, true)); |
| 5440 | SpdySerializedFrame get_resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5441 | SpdySerializedFrame body2( |
| 5442 | spdy_util_.ConstructSpdyDataFrame(3, "22", 2, true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5443 | |
| 5444 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5445 | CreateMockWrite(get1, 0), CreateMockWrite(get2, 3), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5446 | }; |
| 5447 | |
| 5448 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5449 | CreateMockRead(get_resp1, 1, ASYNC), |
| 5450 | CreateMockRead(body1, 2, ASYNC), |
| 5451 | CreateMockRead(get_resp2, 4, ASYNC), |
| 5452 | CreateMockRead(body2, 5, ASYNC), |
| 5453 | MockRead(ASYNC, 0, 6), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5454 | }; |
| 5455 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5456 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5457 | arraysize(spdy_writes)); |
| 5458 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5459 | |
| 5460 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5461 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5462 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5463 | |
| 5464 | TestCompletionCallback callback; |
| 5465 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5466 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5467 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5468 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5469 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5470 | |
| 5471 | LoadTimingInfo load_timing_info; |
| 5472 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5473 | TestLoadTimingNotReused(load_timing_info, |
| 5474 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5475 | |
| 5476 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5477 | ASSERT_TRUE(response); |
| 5478 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5479 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5480 | |
| 5481 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5482 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5483 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 5484 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5485 | // Delete the first request, so the second one can reuse the socket. |
| 5486 | trans.reset(); |
| 5487 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5488 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5489 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5490 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5491 | |
| 5492 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5493 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5494 | TestLoadTimingReused(load_timing_info2); |
| 5495 | |
| 5496 | // The requests should have the same ID. |
| 5497 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5498 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5499 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5500 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5501 | } |
| 5502 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5503 | // Test the challenge-response-retry sequence through an HTTPS Proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5504 | TEST_F(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5505 | HttpRequestInfo request; |
| 5506 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5507 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5508 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5509 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5510 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5511 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5512 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5513 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5514 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5515 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5516 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5517 | // Since we have proxy, should use full url |
| 5518 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5519 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 5520 | "Host: www.example.org\r\n" |
| 5521 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5522 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5523 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5524 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5525 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 5526 | "Host: www.example.org\r\n" |
| 5527 | "Proxy-Connection: keep-alive\r\n" |
| 5528 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5529 | }; |
| 5530 | |
| 5531 | // The proxy responds to the GET with a 407, using a persistent |
| 5532 | // connection. |
| 5533 | MockRead data_reads1[] = { |
| 5534 | // No credentials. |
| 5535 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 5536 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5537 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 5538 | MockRead("Content-Length: 0\r\n\r\n"), |
| 5539 | |
| 5540 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5541 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5542 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5543 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5544 | }; |
| 5545 | |
| 5546 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5547 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5548 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5549 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5550 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5551 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5552 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5553 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5554 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5555 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5556 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5557 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5558 | |
| 5559 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5560 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5561 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5562 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5563 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5564 | TestLoadTimingNotReused(load_timing_info, |
| 5565 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5566 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5567 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5568 | ASSERT_TRUE(response); |
| 5569 | ASSERT_TRUE(response->headers); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5570 | EXPECT_EQ(407, response->headers->response_code()); |
| 5571 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 5572 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5573 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5574 | TestCompletionCallback callback2; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5575 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5576 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5577 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5578 | |
| 5579 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5580 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5581 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5582 | load_timing_info = LoadTimingInfo(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5583 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5584 | // Retrying with HTTP AUTH is considered to be reusing a socket. |
| 5585 | TestLoadTimingReused(load_timing_info); |
| 5586 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5587 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5588 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5589 | |
| 5590 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 5591 | EXPECT_EQ(200, response->headers->response_code()); |
| 5592 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5593 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5594 | |
| 5595 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5596 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5597 | } |
| 5598 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5599 | void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5600 | const MockRead& status, int expected_status) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5601 | HttpRequestInfo request; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5602 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5603 | request.url = GURL("https://www.example.org/"); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5604 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5605 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5606 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5607 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5608 | |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5609 | // Since we have proxy, should try to establish tunnel. |
| 5610 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5611 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5612 | "Host: www.example.org:443\r\n" |
| 5613 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5614 | }; |
| 5615 | |
| 5616 | MockRead data_reads[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 5617 | status, MockRead("Content-Length: 10\r\n\r\n"), |
| 5618 | // No response body because the test stops reading here. |
| 5619 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5620 | }; |
| 5621 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5622 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 5623 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5624 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5625 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5626 | TestCompletionCallback callback; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5627 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5628 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5629 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5630 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5631 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5632 | |
| 5633 | rv = callback.WaitForResult(); |
| 5634 | EXPECT_EQ(expected_status, rv); |
| 5635 | } |
| 5636 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5637 | void HttpNetworkTransactionTest::ConnectStatusHelper( |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5638 | const MockRead& status) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5639 | ConnectStatusHelperWithExpectedStatus( |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5640 | status, ERR_TUNNEL_CONNECTION_FAILED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5641 | } |
| 5642 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5643 | TEST_F(HttpNetworkTransactionTest, ConnectStatus100) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5644 | ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n")); |
| 5645 | } |
| 5646 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5647 | TEST_F(HttpNetworkTransactionTest, ConnectStatus101) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5648 | ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n")); |
| 5649 | } |
| 5650 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5651 | TEST_F(HttpNetworkTransactionTest, ConnectStatus201) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5652 | ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n")); |
| 5653 | } |
| 5654 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5655 | TEST_F(HttpNetworkTransactionTest, ConnectStatus202) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5656 | ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n")); |
| 5657 | } |
| 5658 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5659 | TEST_F(HttpNetworkTransactionTest, ConnectStatus203) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5660 | ConnectStatusHelper( |
| 5661 | MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n")); |
| 5662 | } |
| 5663 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5664 | TEST_F(HttpNetworkTransactionTest, ConnectStatus204) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5665 | ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n")); |
| 5666 | } |
| 5667 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5668 | TEST_F(HttpNetworkTransactionTest, ConnectStatus205) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5669 | ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n")); |
| 5670 | } |
| 5671 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5672 | TEST_F(HttpNetworkTransactionTest, ConnectStatus206) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5673 | ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n")); |
| 5674 | } |
| 5675 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5676 | TEST_F(HttpNetworkTransactionTest, ConnectStatus300) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5677 | ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n")); |
| 5678 | } |
| 5679 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5680 | TEST_F(HttpNetworkTransactionTest, ConnectStatus301) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5681 | ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n")); |
| 5682 | } |
| 5683 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5684 | TEST_F(HttpNetworkTransactionTest, ConnectStatus302) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5685 | ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n")); |
| 5686 | } |
| 5687 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5688 | TEST_F(HttpNetworkTransactionTest, ConnectStatus303) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5689 | ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n")); |
| 5690 | } |
| 5691 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5692 | TEST_F(HttpNetworkTransactionTest, ConnectStatus304) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5693 | ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n")); |
| 5694 | } |
| 5695 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5696 | TEST_F(HttpNetworkTransactionTest, ConnectStatus305) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5697 | ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n")); |
| 5698 | } |
| 5699 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5700 | TEST_F(HttpNetworkTransactionTest, ConnectStatus306) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5701 | ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n")); |
| 5702 | } |
| 5703 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5704 | TEST_F(HttpNetworkTransactionTest, ConnectStatus307) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5705 | ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n")); |
| 5706 | } |
| 5707 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5708 | TEST_F(HttpNetworkTransactionTest, ConnectStatus308) { |
[email protected] | 0a17aab3 | 2014-04-24 03:32:37 | [diff] [blame] | 5709 | ConnectStatusHelper(MockRead("HTTP/1.1 308 Permanent Redirect\r\n")); |
| 5710 | } |
| 5711 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5712 | TEST_F(HttpNetworkTransactionTest, ConnectStatus400) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5713 | ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n")); |
| 5714 | } |
| 5715 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5716 | TEST_F(HttpNetworkTransactionTest, ConnectStatus401) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5717 | ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n")); |
| 5718 | } |
| 5719 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5720 | TEST_F(HttpNetworkTransactionTest, ConnectStatus402) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5721 | ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n")); |
| 5722 | } |
| 5723 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5724 | TEST_F(HttpNetworkTransactionTest, ConnectStatus403) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5725 | ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n")); |
| 5726 | } |
| 5727 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5728 | TEST_F(HttpNetworkTransactionTest, ConnectStatus404) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5729 | ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n")); |
| 5730 | } |
| 5731 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5732 | TEST_F(HttpNetworkTransactionTest, ConnectStatus405) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5733 | ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n")); |
| 5734 | } |
| 5735 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5736 | TEST_F(HttpNetworkTransactionTest, ConnectStatus406) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5737 | ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n")); |
| 5738 | } |
| 5739 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5740 | TEST_F(HttpNetworkTransactionTest, ConnectStatus407) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5741 | ConnectStatusHelperWithExpectedStatus( |
| 5742 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
[email protected] | a7ea883 | 2010-07-12 17:54:54 | [diff] [blame] | 5743 | ERR_PROXY_AUTH_UNSUPPORTED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5744 | } |
| 5745 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5746 | TEST_F(HttpNetworkTransactionTest, ConnectStatus408) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5747 | ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n")); |
| 5748 | } |
| 5749 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5750 | TEST_F(HttpNetworkTransactionTest, ConnectStatus409) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5751 | ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n")); |
| 5752 | } |
| 5753 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5754 | TEST_F(HttpNetworkTransactionTest, ConnectStatus410) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5755 | ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n")); |
| 5756 | } |
| 5757 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5758 | TEST_F(HttpNetworkTransactionTest, ConnectStatus411) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5759 | ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n")); |
| 5760 | } |
| 5761 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5762 | TEST_F(HttpNetworkTransactionTest, ConnectStatus412) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5763 | ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n")); |
| 5764 | } |
| 5765 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5766 | TEST_F(HttpNetworkTransactionTest, ConnectStatus413) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5767 | ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n")); |
| 5768 | } |
| 5769 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5770 | TEST_F(HttpNetworkTransactionTest, ConnectStatus414) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5771 | ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n")); |
| 5772 | } |
| 5773 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5774 | TEST_F(HttpNetworkTransactionTest, ConnectStatus415) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5775 | ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n")); |
| 5776 | } |
| 5777 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5778 | TEST_F(HttpNetworkTransactionTest, ConnectStatus416) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5779 | ConnectStatusHelper( |
| 5780 | MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n")); |
| 5781 | } |
| 5782 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5783 | TEST_F(HttpNetworkTransactionTest, ConnectStatus417) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5784 | ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n")); |
| 5785 | } |
| 5786 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5787 | TEST_F(HttpNetworkTransactionTest, ConnectStatus500) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5788 | ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n")); |
| 5789 | } |
| 5790 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5791 | TEST_F(HttpNetworkTransactionTest, ConnectStatus501) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5792 | ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n")); |
| 5793 | } |
| 5794 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5795 | TEST_F(HttpNetworkTransactionTest, ConnectStatus502) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5796 | ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n")); |
| 5797 | } |
| 5798 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5799 | TEST_F(HttpNetworkTransactionTest, ConnectStatus503) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5800 | ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n")); |
| 5801 | } |
| 5802 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5803 | TEST_F(HttpNetworkTransactionTest, ConnectStatus504) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5804 | ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n")); |
| 5805 | } |
| 5806 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5807 | TEST_F(HttpNetworkTransactionTest, ConnectStatus505) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5808 | ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); |
| 5809 | } |
| 5810 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5811 | // Test the flow when both the proxy server AND origin server require |
| 5812 | // authentication. Again, this uses basic auth for both since that is |
| 5813 | // the simplest to mock. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5814 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5815 | HttpRequestInfo request; |
| 5816 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5817 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5818 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5819 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5820 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5821 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 5822 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5823 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5824 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5825 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5826 | MockWrite( |
| 5827 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5828 | "Host: www.example.org\r\n" |
| 5829 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5830 | }; |
| 5831 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5832 | MockRead data_reads1[] = { |
| 5833 | MockRead("HTTP/1.0 407 Unauthorized\r\n"), |
| 5834 | // Give a couple authenticate options (only the middle one is actually |
| 5835 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 5836 | MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5837 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5838 | MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 5839 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5840 | // Large content-length -- won't matter, as connection will be reset. |
| 5841 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5842 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5843 | }; |
| 5844 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5845 | // After calling trans.RestartWithAuth() the first time, this is the |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5846 | // request we should be issuing -- the final header line contains the |
| 5847 | // proxy's credentials. |
| 5848 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5849 | MockWrite( |
| 5850 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5851 | "Host: www.example.org\r\n" |
| 5852 | "Proxy-Connection: keep-alive\r\n" |
| 5853 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5854 | }; |
| 5855 | |
| 5856 | // Now the proxy server lets the request pass through to origin server. |
| 5857 | // The origin server responds with a 401. |
| 5858 | MockRead data_reads2[] = { |
| 5859 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5860 | // Note: We are using the same realm-name as the proxy server. This is |
| 5861 | // completely valid, as realms are unique across hosts. |
| 5862 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5863 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5864 | MockRead("Content-Length: 2000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5865 | MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5866 | }; |
| 5867 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5868 | // After calling trans.RestartWithAuth() the second time, we should send |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5869 | // the credentials for both the proxy and origin server. |
| 5870 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5871 | MockWrite( |
| 5872 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5873 | "Host: www.example.org\r\n" |
| 5874 | "Proxy-Connection: keep-alive\r\n" |
| 5875 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 5876 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5877 | }; |
| 5878 | |
| 5879 | // Lastly we get the desired content. |
| 5880 | MockRead data_reads3[] = { |
| 5881 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5882 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5883 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5884 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5885 | }; |
| 5886 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5887 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5888 | data_writes1, arraysize(data_writes1)); |
| 5889 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5890 | data_writes2, arraysize(data_writes2)); |
| 5891 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 5892 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5893 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5894 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 5895 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5896 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5897 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5898 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5899 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5900 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5901 | |
| 5902 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5903 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5904 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5905 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5906 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5907 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5908 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5909 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5910 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5911 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5912 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5913 | |
| 5914 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5915 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5916 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5917 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5918 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5919 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5920 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5921 | TestCompletionCallback callback3; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5922 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5923 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 5924 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5925 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5926 | |
| 5927 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5928 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5929 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5930 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5931 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5932 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5933 | } |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5934 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 5935 | // For the NTLM implementation using SSPI, we skip the NTLM tests since we |
| 5936 | // can't hook into its internals to cause it to generate predictable NTLM |
| 5937 | // authorization headers. |
| 5938 | #if defined(NTLM_PORTABLE) |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 5939 | // The NTLM authentication unit tests are based on known test data from the |
| 5940 | // [MS-NLMP] Specification [1]. These tests are primarily of the authentication |
| 5941 | // flow rather than the implementation of the NTLM protocol. See net/ntlm |
| 5942 | // for the implementation and testing of the protocol. |
| 5943 | // |
| 5944 | // [1] https://msdn.microsoft.com/en-us/library/cc236621.aspx |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5945 | |
| 5946 | // Enter the correct password and authenticate successfully. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 5947 | TEST_F(HttpNetworkTransactionTest, NTLMAuthV1) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5948 | HttpRequestInfo request; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5949 | request.method = "GET"; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 5950 | request.url = GURL("https://172.22.68.17/kids/login.aspx"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5951 | |
| 5952 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 5953 | // to other auth schemes. |
| 5954 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5955 | |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 5956 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 5957 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5958 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5959 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 5960 | // Generate the NTLM messages based on known test data. |
| 5961 | std::string negotiate_msg; |
| 5962 | std::string challenge_msg; |
| 5963 | std::string authenticate_msg; |
| 5964 | base::Base64Encode( |
| 5965 | base::StringPiece( |
| 5966 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
| 5967 | arraysize(ntlm::test::kExpectedNegotiateMsg)), |
| 5968 | &negotiate_msg); |
| 5969 | base::Base64Encode(base::StringPiece(reinterpret_cast<const char*>( |
| 5970 | ntlm::test::kChallengeMsgV1), |
| 5971 | arraysize(ntlm::test::kChallengeMsgV1)), |
| 5972 | &challenge_msg); |
| 5973 | base::Base64Encode( |
| 5974 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 5975 | reinterpret_cast<const char*>( |
| 5976 | ntlm::test::kExpectedAuthenticateMsgSpecResponseV1), |
| 5977 | arraysize(ntlm::test::kExpectedAuthenticateMsgSpecResponseV1)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 5978 | &authenticate_msg); |
| 5979 | |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5980 | MockWrite data_writes1[] = { |
| 5981 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5982 | "Host: 172.22.68.17\r\n" |
| 5983 | "Connection: keep-alive\r\n\r\n"), |
| 5984 | }; |
| 5985 | |
| 5986 | MockRead data_reads1[] = { |
| 5987 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 5988 | // Negotiate and NTLM are often requested together. However, we only want |
| 5989 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 5990 | // the header that requests Negotiate for this test. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5991 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 5992 | MockRead("Connection: close\r\n"), |
| 5993 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5994 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5995 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5996 | }; |
| 5997 | |
| 5998 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5999 | // After restarting with a null identity, this is the |
| 6000 | // request we should be issuing -- the final header line contains a Type |
| 6001 | // 1 message. |
| 6002 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6003 | "Host: 172.22.68.17\r\n" |
| 6004 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6005 | "Authorization: NTLM "), |
| 6006 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6007 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6008 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6009 | // (using correct credentials). The second request continues on the |
| 6010 | // same connection. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6011 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6012 | "Host: 172.22.68.17\r\n" |
| 6013 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6014 | "Authorization: NTLM "), |
| 6015 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6016 | }; |
| 6017 | |
| 6018 | MockRead data_reads2[] = { |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6019 | // The origin server responds with a Type 2 message. |
| 6020 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6021 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 6022 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6023 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6024 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6025 | |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6026 | // Lastly we get the desired content. |
| 6027 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6028 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 6029 | MockRead("Content-Length: 14\r\n\r\n"), MockRead("Please Login\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6030 | }; |
| 6031 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6032 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6033 | data_writes1, arraysize(data_writes1)); |
| 6034 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6035 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6036 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6037 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6038 | |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6039 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 6040 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 6041 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 6042 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 6043 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6044 | TestCompletionCallback callback1; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6045 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6046 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6047 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6048 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6049 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6050 | |
| 6051 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6052 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6053 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6054 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6055 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6056 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6057 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6058 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6059 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6060 | TestCompletionCallback callback2; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6061 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6062 | rv = trans.RestartWithAuth( |
| 6063 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 6064 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6065 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6066 | |
| 6067 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6068 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6069 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6070 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6071 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6072 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6073 | ASSERT_TRUE(response); |
| 6074 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6075 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6076 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6077 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6078 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6079 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6080 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6081 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6082 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6083 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6084 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6085 | ASSERT_TRUE(response); |
| 6086 | EXPECT_FALSE(response->auth_challenge); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6087 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 6088 | |
| 6089 | std::string response_data; |
| 6090 | rv = ReadTransaction(&trans, &response_data); |
| 6091 | EXPECT_THAT(rv, IsOk()); |
| 6092 | EXPECT_EQ("Please Login\r\n", response_data); |
| 6093 | |
| 6094 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 6095 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
| 6096 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 6097 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6098 | } |
| 6099 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6100 | // Enter a wrong password, and then the correct one. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6101 | TEST_F(HttpNetworkTransactionTest, NTLMAuthV1WrongThenRightPassword) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6102 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6103 | request.method = "GET"; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6104 | request.url = GURL("https://172.22.68.17/kids/login.aspx"); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6105 | |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6106 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 6107 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6108 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6109 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6110 | // Generate the NTLM messages based on known test data. |
| 6111 | std::string negotiate_msg; |
| 6112 | std::string challenge_msg; |
| 6113 | std::string authenticate_msg; |
| 6114 | base::Base64Encode( |
| 6115 | base::StringPiece( |
| 6116 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
| 6117 | arraysize(ntlm::test::kExpectedNegotiateMsg)), |
| 6118 | &negotiate_msg); |
| 6119 | base::Base64Encode(base::StringPiece(reinterpret_cast<const char*>( |
| 6120 | ntlm::test::kChallengeMsgV1), |
| 6121 | arraysize(ntlm::test::kChallengeMsgV1)), |
| 6122 | &challenge_msg); |
| 6123 | base::Base64Encode( |
| 6124 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6125 | reinterpret_cast<const char*>( |
| 6126 | ntlm::test::kExpectedAuthenticateMsgSpecResponseV1), |
| 6127 | arraysize(ntlm::test::kExpectedAuthenticateMsgSpecResponseV1)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6128 | &authenticate_msg); |
| 6129 | |
| 6130 | // The authenticate message when |kWrongPassword| is sent. |
| 6131 | std::string wrong_password_authenticate_msg( |
| 6132 | "TlRMTVNTUAADAAAAGAAYAEAAAAAYABgAWAAAAAwADABwAAAACAAIAHwAAAAQABAAhAAAAAAA" |
| 6133 | "AABAAAAAA4IIAKqqqqqqqqqqAAAAAAAAAAAAAAAAAAAAAF2npafgDxlql9qxEIhLlsuuJIEd" |
| 6134 | "NQHk7kQAbwBtAGEAaQBuAFUAcwBlAHIAQwBPAE0AUABVAFQARQBSAA=="); |
| 6135 | |
| 6136 | // Sanity check that this is the same as |authenticate_msg| except for the |
| 6137 | // 24 bytes (32 encoded chars) of the NTLM Response. |
| 6138 | ASSERT_EQ(authenticate_msg.length(), |
| 6139 | wrong_password_authenticate_msg.length()); |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6140 | ASSERT_EQ(authenticate_msg.length(), 200u); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6141 | ASSERT_EQ(base::StringPiece(authenticate_msg.data(), 117), |
| 6142 | base::StringPiece(wrong_password_authenticate_msg.data(), 117)); |
| 6143 | ASSERT_EQ( |
| 6144 | base::StringPiece(authenticate_msg.data() + 149, 51), |
| 6145 | base::StringPiece(wrong_password_authenticate_msg.data() + 149, 51)); |
| 6146 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6147 | MockWrite data_writes1[] = { |
| 6148 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6149 | "Host: 172.22.68.17\r\n" |
| 6150 | "Connection: keep-alive\r\n\r\n"), |
| 6151 | }; |
| 6152 | |
| 6153 | MockRead data_reads1[] = { |
| 6154 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 6155 | // Negotiate and NTLM are often requested together. However, we only want |
| 6156 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 6157 | // the header that requests Negotiate for this test. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6158 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 6159 | MockRead("Connection: close\r\n"), |
| 6160 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6161 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6162 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6163 | }; |
| 6164 | |
| 6165 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6166 | // After restarting with a null identity, this is the |
| 6167 | // request we should be issuing -- the final header line contains a Type |
| 6168 | // 1 message. |
| 6169 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6170 | "Host: 172.22.68.17\r\n" |
| 6171 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6172 | "Authorization: NTLM "), |
| 6173 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6174 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6175 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6176 | // (using incorrect credentials). The second request continues on the |
| 6177 | // same connection. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6178 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6179 | "Host: 172.22.68.17\r\n" |
| 6180 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6181 | "Authorization: NTLM "), |
| 6182 | MockWrite(wrong_password_authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6183 | }; |
| 6184 | |
| 6185 | MockRead data_reads2[] = { |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6186 | // The origin server responds with a Type 2 message. |
| 6187 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 6188 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 6189 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
| 6190 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6191 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6192 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6193 | // Wrong password. |
| 6194 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 6195 | MockRead("WWW-Authenticate: NTLM\r\n"), MockRead("Connection: close\r\n"), |
| 6196 | MockRead("Content-Length: 42\r\n"), |
| 6197 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6198 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6199 | }; |
| 6200 | |
| 6201 | MockWrite data_writes3[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6202 | // After restarting with a null identity, this is the |
| 6203 | // request we should be issuing -- the final header line contains a Type |
| 6204 | // 1 message. |
| 6205 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6206 | "Host: 172.22.68.17\r\n" |
| 6207 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6208 | "Authorization: NTLM "), |
| 6209 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6210 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6211 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 6212 | // (the credentials for the origin server). The second request continues |
| 6213 | // on the same connection. |
| 6214 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6215 | "Host: 172.22.68.17\r\n" |
| 6216 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6217 | "Authorization: NTLM "), |
| 6218 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6219 | }; |
| 6220 | |
| 6221 | MockRead data_reads3[] = { |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6222 | // The origin server responds with a Type 2 message. |
| 6223 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6224 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 6225 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6226 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6227 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6228 | |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6229 | // Lastly we get the desired content. |
| 6230 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6231 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 6232 | MockRead("Content-Length: 14\r\n\r\n"), MockRead("Please Login\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6233 | }; |
| 6234 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6235 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6236 | data_writes1, arraysize(data_writes1)); |
| 6237 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6238 | data_writes2, arraysize(data_writes2)); |
| 6239 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6240 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6241 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6242 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6243 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6244 | |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6245 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 6246 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 6247 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 6248 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 6249 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 6250 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 6251 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6252 | TestCompletionCallback callback1; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6253 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6254 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6255 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6256 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6257 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6258 | |
| 6259 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6260 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6261 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6262 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6263 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6264 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6265 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6266 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6267 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6268 | TestCompletionCallback callback2; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6269 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6270 | // Enter the wrong password. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6271 | rv = trans.RestartWithAuth( |
| 6272 | AuthCredentials(ntlm::test::kDomainUserCombined, kWrongPassword), |
| 6273 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6274 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6275 | |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6276 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6277 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6278 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6279 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6280 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6281 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6282 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6283 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6284 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6285 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6286 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6287 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6288 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6289 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6290 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6291 | TestCompletionCallback callback4; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6292 | |
| 6293 | // Now enter the right password. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6294 | rv = trans.RestartWithAuth( |
| 6295 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 6296 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6297 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6298 | |
| 6299 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6300 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6301 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6302 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6303 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6304 | TestCompletionCallback callback5; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6305 | |
| 6306 | // One more roundtrip |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6307 | rv = trans.RestartWithAuth(AuthCredentials(), callback5.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6308 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6309 | |
| 6310 | rv = callback5.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6311 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6312 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6313 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6314 | EXPECT_FALSE(response->auth_challenge); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6315 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 6316 | |
| 6317 | std::string response_data; |
| 6318 | rv = ReadTransaction(&trans, &response_data); |
| 6319 | EXPECT_THAT(rv, IsOk()); |
| 6320 | EXPECT_EQ("Please Login\r\n", response_data); |
| 6321 | |
| 6322 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 6323 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
| 6324 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 6325 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
| 6326 | EXPECT_TRUE(data3.AllReadDataConsumed()); |
| 6327 | EXPECT_TRUE(data3.AllWriteDataConsumed()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6328 | } |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6329 | |
Bence Béky | 3238f2e1 | 2017-09-22 22:44:49 | [diff] [blame] | 6330 | // Server requests NTLM authentication, which is not supported over HTTP/2. |
| 6331 | // Subsequent request with authorization header should be sent over HTTP/1.1. |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6332 | TEST_F(HttpNetworkTransactionTest, NTLMOverHttp2) { |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6333 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 6334 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6335 | |
| 6336 | const char* kUrl = "https://172.22.68.17/kids/login.aspx"; |
| 6337 | |
| 6338 | HttpRequestInfo request; |
| 6339 | request.method = "GET"; |
| 6340 | request.url = GURL(kUrl); |
| 6341 | |
| 6342 | // First request without credentials. |
| 6343 | SpdyHeaderBlock request_headers0(spdy_util_.ConstructGetHeaderBlock(kUrl)); |
| 6344 | SpdySerializedFrame request0(spdy_util_.ConstructSpdyHeaders( |
| 6345 | 1, std::move(request_headers0), LOWEST, true)); |
| 6346 | |
| 6347 | SpdyHeaderBlock response_headers0; |
Bence Béky | bda8295 | 2017-10-02 17:35:27 | [diff] [blame] | 6348 | response_headers0[kHttp2StatusHeader] = "401"; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6349 | response_headers0["www-authenticate"] = "NTLM"; |
| 6350 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyResponseHeaders( |
| 6351 | 1, std::move(response_headers0), true)); |
| 6352 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6353 | // Stream 1 is closed. |
| 6354 | spdy_util_.UpdateWithStreamDestruction(1); |
| 6355 | |
| 6356 | // Generate the NTLM messages based on known test data. |
| 6357 | std::string negotiate_msg; |
| 6358 | std::string challenge_msg; |
| 6359 | std::string authenticate_msg; |
| 6360 | base::Base64Encode( |
| 6361 | base::StringPiece( |
| 6362 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
| 6363 | arraysize(ntlm::test::kExpectedNegotiateMsg)), |
| 6364 | &negotiate_msg); |
| 6365 | base::Base64Encode(base::StringPiece(reinterpret_cast<const char*>( |
| 6366 | ntlm::test::kChallengeMsgV1), |
| 6367 | arraysize(ntlm::test::kChallengeMsgV1)), |
| 6368 | &challenge_msg); |
| 6369 | base::Base64Encode( |
| 6370 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6371 | reinterpret_cast<const char*>( |
| 6372 | ntlm::test::kExpectedAuthenticateMsgSpecResponseV1), |
| 6373 | arraysize(ntlm::test::kExpectedAuthenticateMsgSpecResponseV1)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6374 | &authenticate_msg); |
| 6375 | |
| 6376 | // Retry with authorization header. |
| 6377 | SpdyHeaderBlock request_headers1(spdy_util_.ConstructGetHeaderBlock(kUrl)); |
| 6378 | request_headers1["authorization"] = std::string("NTLM ") + negotiate_msg; |
| 6379 | SpdySerializedFrame request1(spdy_util_.ConstructSpdyHeaders( |
| 6380 | 3, std::move(request_headers1), LOWEST, true)); |
| 6381 | |
| 6382 | SpdySerializedFrame rst( |
| 6383 | spdy_util_.ConstructSpdyRstStream(3, ERROR_CODE_HTTP_1_1_REQUIRED)); |
| 6384 | |
Bence Béky | 3238f2e1 | 2017-09-22 22:44:49 | [diff] [blame] | 6385 | MockWrite writes0[] = {CreateMockWrite(request0, 0)}; |
| 6386 | MockRead reads0[] = {CreateMockRead(resp, 1), MockRead(ASYNC, 0, 2)}; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6387 | |
| 6388 | // Retry yet again using HTTP/1.1. |
| 6389 | MockWrite writes1[] = { |
| 6390 | // After restarting with a null identity, this is the |
| 6391 | // request we should be issuing -- the final header line contains a Type |
| 6392 | // 1 message. |
| 6393 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6394 | "Host: 172.22.68.17\r\n" |
| 6395 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6396 | "Authorization: NTLM "), |
| 6397 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6398 | |
| 6399 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 6400 | // (the credentials for the origin server). The second request continues |
| 6401 | // on the same connection. |
| 6402 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6403 | "Host: 172.22.68.17\r\n" |
| 6404 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6405 | "Authorization: NTLM "), |
| 6406 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6407 | }; |
| 6408 | |
| 6409 | MockRead reads1[] = { |
| 6410 | // The origin server responds with a Type 2 message. |
| 6411 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6412 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 6413 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6414 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6415 | MockRead("You are not authorized to view this page\r\n"), |
| 6416 | |
| 6417 | // Lastly we get the desired content. |
| 6418 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6419 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6420 | 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] | 6421 | }; |
| 6422 | SequencedSocketData data0(reads0, arraysize(reads0), writes0, |
| 6423 | arraysize(writes0)); |
| 6424 | StaticSocketDataProvider data1(reads1, arraysize(reads1), writes1, |
| 6425 | arraysize(writes1)); |
| 6426 | session_deps_.socket_factory->AddSocketDataProvider(&data0); |
| 6427 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6428 | |
| 6429 | SSLSocketDataProvider ssl0(ASYNC, OK); |
| 6430 | ssl0.next_proto = kProtoHTTP2; |
| 6431 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 6432 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl0); |
| 6433 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 6434 | |
| 6435 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6436 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 6437 | |
| 6438 | TestCompletionCallback callback1; |
| 6439 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
| 6440 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6441 | |
| 6442 | rv = callback1.WaitForResult(); |
| 6443 | EXPECT_THAT(rv, IsOk()); |
| 6444 | |
| 6445 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
| 6446 | |
| 6447 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 6448 | ASSERT_TRUE(response); |
| 6449 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
| 6450 | |
| 6451 | TestCompletionCallback callback2; |
| 6452 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6453 | rv = trans.RestartWithAuth( |
| 6454 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 6455 | callback2.callback()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6456 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6457 | |
| 6458 | rv = callback2.WaitForResult(); |
| 6459 | EXPECT_THAT(rv, IsOk()); |
| 6460 | |
| 6461 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 6462 | |
| 6463 | response = trans.GetResponseInfo(); |
| 6464 | ASSERT_TRUE(response); |
| 6465 | EXPECT_FALSE(response->auth_challenge); |
| 6466 | |
| 6467 | TestCompletionCallback callback3; |
| 6468 | |
| 6469 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
| 6470 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6471 | |
| 6472 | rv = callback3.WaitForResult(); |
| 6473 | EXPECT_THAT(rv, IsOk()); |
| 6474 | |
| 6475 | response = trans.GetResponseInfo(); |
| 6476 | ASSERT_TRUE(response); |
| 6477 | EXPECT_FALSE(response->auth_challenge); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6478 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 6479 | |
| 6480 | std::string response_data; |
| 6481 | rv = ReadTransaction(&trans, &response_data); |
| 6482 | EXPECT_THAT(rv, IsOk()); |
| 6483 | EXPECT_EQ("Please Login\r\n", response_data); |
| 6484 | |
| 6485 | EXPECT_TRUE(data0.AllReadDataConsumed()); |
| 6486 | EXPECT_TRUE(data0.AllWriteDataConsumed()); |
| 6487 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 6488 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6489 | } |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6490 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6491 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6492 | // Test reading a server response which has only headers, and no body. |
| 6493 | // After some maximum number of bytes is consumed, the transaction should |
| 6494 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6495 | TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6496 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6497 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6498 | request.url = GURL("http://www.example.org/"); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6499 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6500 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6501 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6502 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 6503 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 6504 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 6505 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6506 | |
| 6507 | MockRead data_reads[] = { |
| 6508 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6509 | MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6510 | MockRead("\r\nBODY"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6511 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6512 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6513 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6514 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6515 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6516 | TestCompletionCallback callback; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6517 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6518 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6519 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6520 | |
| 6521 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6522 | EXPECT_THAT(rv, IsError(ERR_RESPONSE_HEADERS_TOO_BIG)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6523 | } |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6524 | |
| 6525 | // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 6526 | // establish tunnel. |
| 6527 | // http://code.google.com/p/chromium/issues/detail?id=3772 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6528 | TEST_F(HttpNetworkTransactionTest, DontRecycleTransportSocketForSSLTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6529 | HttpRequestInfo request; |
| 6530 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6531 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6532 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6533 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 6534 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 6535 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6536 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6537 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6538 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6539 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6540 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6541 | // Since we have proxy, should try to establish tunnel. |
| 6542 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 6543 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6544 | "Host: www.example.org:443\r\n" |
| 6545 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6546 | }; |
| 6547 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 6548 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6549 | // connection. Usually a proxy would return 501 (not implemented), |
| 6550 | // or 200 (tunnel established). |
| 6551 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 6552 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 6553 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6554 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6555 | }; |
| 6556 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6557 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6558 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6559 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6560 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6561 | TestCompletionCallback callback1; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6562 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6563 | int rv = trans->Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6564 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6565 | |
| 6566 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6567 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6568 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6569 | // Empty the current queue. This is necessary because idle sockets are |
| 6570 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6571 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6572 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6573 | // We now check to make sure the TCPClientSocket was not added back to |
| 6574 | // the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6575 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6576 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6577 | base::RunLoop().RunUntilIdle(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6578 | // Make sure that the socket didn't get recycled after calling the destructor. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6579 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6580 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6581 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6582 | // Make sure that we recycle a socket after reading all of the response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6583 | TEST_F(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6584 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6585 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6586 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6587 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6588 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6589 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6590 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6591 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6592 | MockRead data_reads[] = { |
| 6593 | // A part of the response body is received with the response headers. |
| 6594 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 6595 | // The rest of the response body is received in two parts. |
| 6596 | MockRead("lo"), |
| 6597 | MockRead(" world"), |
| 6598 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6599 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6600 | }; |
| 6601 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6602 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6603 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6604 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6605 | TestCompletionCallback callback; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6606 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6607 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6608 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6609 | |
| 6610 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6611 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6612 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6613 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6614 | ASSERT_TRUE(response); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6615 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6616 | EXPECT_TRUE(response->headers); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6617 | std::string status_line = response->headers->GetStatusLine(); |
| 6618 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 6619 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6620 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6621 | |
| 6622 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6623 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6624 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6625 | EXPECT_EQ("hello world", response_data); |
| 6626 | |
| 6627 | // Empty the current queue. This is necessary because idle sockets are |
| 6628 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6629 | base::RunLoop().RunUntilIdle(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6630 | |
| 6631 | // 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] | 6632 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6633 | } |
| 6634 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6635 | // Make sure that we recycle a SSL socket after reading all of the response |
| 6636 | // body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6637 | TEST_F(HttpNetworkTransactionTest, RecycleSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6638 | HttpRequestInfo request; |
| 6639 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6640 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6641 | |
| 6642 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6643 | MockWrite( |
| 6644 | "GET / HTTP/1.1\r\n" |
| 6645 | "Host: www.example.org\r\n" |
| 6646 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6647 | }; |
| 6648 | |
| 6649 | MockRead data_reads[] = { |
| 6650 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6651 | MockRead("Content-Length: 11\r\n\r\n"), |
| 6652 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6653 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6654 | }; |
| 6655 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6656 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6657 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6658 | |
| 6659 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6660 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6661 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6662 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6663 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6664 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6665 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6666 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6667 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6668 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6669 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6670 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6671 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6672 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6673 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6674 | ASSERT_TRUE(response); |
| 6675 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6676 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6677 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6678 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6679 | |
| 6680 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6681 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6682 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6683 | EXPECT_EQ("hello world", response_data); |
| 6684 | |
| 6685 | // Empty the current queue. This is necessary because idle sockets are |
| 6686 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6687 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6688 | |
| 6689 | // 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] | 6690 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6691 | } |
| 6692 | |
| 6693 | // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it |
| 6694 | // from the pool and make sure that we recover okay. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6695 | TEST_F(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6696 | HttpRequestInfo request; |
| 6697 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6698 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6699 | |
| 6700 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6701 | MockWrite( |
| 6702 | "GET / HTTP/1.1\r\n" |
| 6703 | "Host: www.example.org\r\n" |
| 6704 | "Connection: keep-alive\r\n\r\n"), |
| 6705 | MockWrite( |
| 6706 | "GET / HTTP/1.1\r\n" |
| 6707 | "Host: www.example.org\r\n" |
| 6708 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6709 | }; |
| 6710 | |
| 6711 | MockRead data_reads[] = { |
mmenke | 911ee022 | 2015-12-04 03:58:42 | [diff] [blame] | 6712 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 6713 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6714 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6715 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6716 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6717 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6718 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6719 | |
| 6720 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6721 | data_writes, arraysize(data_writes)); |
| 6722 | StaticSocketDataProvider data2(data_reads, arraysize(data_reads), |
| 6723 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6724 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6725 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6726 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6727 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6728 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6729 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6730 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6731 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6732 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6733 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6734 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6735 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6736 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6737 | |
| 6738 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6739 | ASSERT_TRUE(response); |
| 6740 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6741 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6742 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6743 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6744 | |
| 6745 | std::string response_data; |
| 6746 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6747 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6748 | EXPECT_EQ("hello world", response_data); |
| 6749 | |
| 6750 | // Empty the current queue. This is necessary because idle sockets are |
| 6751 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6752 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6753 | |
| 6754 | // 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] | 6755 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6756 | |
| 6757 | // Now start the second transaction, which should reuse the previous socket. |
| 6758 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6759 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6760 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6761 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6762 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6763 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6764 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6765 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6766 | |
| 6767 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6768 | ASSERT_TRUE(response); |
| 6769 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6770 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6771 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6772 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6773 | |
| 6774 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6775 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6776 | EXPECT_EQ("hello world", response_data); |
| 6777 | |
| 6778 | // Empty the current queue. This is necessary because idle sockets are |
| 6779 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6780 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6781 | |
| 6782 | // 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] | 6783 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6784 | } |
| 6785 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6786 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 6787 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6788 | TEST_F(HttpNetworkTransactionTest, FlushSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6789 | HttpRequestInfo request; |
| 6790 | request.method = "GET"; |
| 6791 | request.url = GURL("http://www.example.org/"); |
| 6792 | request.load_flags = 0; |
| 6793 | |
| 6794 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6795 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6796 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6797 | |
| 6798 | MockRead data_reads[] = { |
| 6799 | // A part of the response body is received with the response headers. |
| 6800 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 6801 | // The rest of the response body is received in two parts. |
| 6802 | MockRead("lo"), MockRead(" world"), |
| 6803 | MockRead("junk"), // Should not be read!! |
| 6804 | MockRead(SYNCHRONOUS, OK), |
| 6805 | }; |
| 6806 | |
| 6807 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 6808 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6809 | |
| 6810 | TestCompletionCallback callback; |
| 6811 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6812 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6813 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6814 | |
| 6815 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6816 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6817 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6818 | ASSERT_TRUE(response); |
| 6819 | EXPECT_TRUE(response->headers); |
| 6820 | std::string status_line = response->headers->GetStatusLine(); |
| 6821 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 6822 | |
| 6823 | // Make memory critical notification and ensure the transaction still has been |
| 6824 | // operating right. |
| 6825 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 6826 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 6827 | base::RunLoop().RunUntilIdle(); |
| 6828 | |
| 6829 | // Socket should not be flushed as long as it is not idle. |
| 6830 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 6831 | |
| 6832 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6833 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6834 | EXPECT_THAT(rv, IsOk()); |
| 6835 | EXPECT_EQ("hello world", response_data); |
| 6836 | |
| 6837 | // Empty the current queue. This is necessary because idle sockets are |
| 6838 | // added to the connection pool asynchronously with a PostTask. |
| 6839 | base::RunLoop().RunUntilIdle(); |
| 6840 | |
| 6841 | // We now check to make sure the socket was added back to the pool. |
| 6842 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 6843 | |
| 6844 | // Idle sockets should be flushed now. |
| 6845 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 6846 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 6847 | base::RunLoop().RunUntilIdle(); |
| 6848 | |
| 6849 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 6850 | } |
| 6851 | |
| 6852 | // Grab an SSL socket, use it, and put it back into the pool. Then, make |
| 6853 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6854 | TEST_F(HttpNetworkTransactionTest, FlushSSLSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6855 | HttpRequestInfo request; |
| 6856 | request.method = "GET"; |
| 6857 | request.url = GURL("https://www.example.org/"); |
| 6858 | request.load_flags = 0; |
| 6859 | |
| 6860 | MockWrite data_writes[] = { |
| 6861 | MockWrite("GET / HTTP/1.1\r\n" |
| 6862 | "Host: www.example.org\r\n" |
| 6863 | "Connection: keep-alive\r\n\r\n"), |
| 6864 | }; |
| 6865 | |
| 6866 | MockRead data_reads[] = { |
| 6867 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 6868 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
| 6869 | |
| 6870 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6871 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6872 | |
| 6873 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 6874 | arraysize(data_writes)); |
| 6875 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6876 | |
| 6877 | TestCompletionCallback callback; |
| 6878 | |
| 6879 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6880 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6881 | |
| 6882 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6883 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6884 | |
| 6885 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6886 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6887 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6888 | ASSERT_TRUE(response); |
| 6889 | ASSERT_TRUE(response->headers); |
| 6890 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6891 | |
| 6892 | // Make memory critical notification and ensure the transaction still has been |
| 6893 | // operating right. |
| 6894 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 6895 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 6896 | base::RunLoop().RunUntilIdle(); |
| 6897 | |
| 6898 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 6899 | |
| 6900 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6901 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6902 | EXPECT_THAT(rv, IsOk()); |
| 6903 | EXPECT_EQ("hello world", response_data); |
| 6904 | |
| 6905 | // Empty the current queue. This is necessary because idle sockets are |
| 6906 | // added to the connection pool asynchronously with a PostTask. |
| 6907 | base::RunLoop().RunUntilIdle(); |
| 6908 | |
| 6909 | // We now check to make sure the socket was added back to the pool. |
| 6910 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 6911 | |
| 6912 | // Make memory notification once again and ensure idle socket is closed. |
| 6913 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 6914 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 6915 | base::RunLoop().RunUntilIdle(); |
| 6916 | |
| 6917 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 6918 | } |
| 6919 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6920 | // Make sure that we recycle a socket after a zero-length response. |
| 6921 | // http://crbug.com/9880 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6922 | TEST_F(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6923 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6924 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6925 | request.url = GURL( |
| 6926 | "http://www.example.org/csi?v=3&s=web&action=&" |
| 6927 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 6928 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 6929 | "rt=prt.2642,ol.2649,xjs.2951"); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6930 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6931 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6932 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6933 | MockRead data_reads[] = { |
| 6934 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 6935 | "Content-Length: 0\r\n" |
| 6936 | "Content-Type: text/html\r\n\r\n"), |
| 6937 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6938 | MockRead(SYNCHRONOUS, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6939 | }; |
| 6940 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6941 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6942 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6943 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 6944 | // Transaction must be created after the MockReads, so it's destroyed before |
| 6945 | // them. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6946 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 6947 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6948 | TestCompletionCallback callback; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6949 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6950 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6951 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6952 | |
| 6953 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6954 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6955 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6956 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6957 | ASSERT_TRUE(response); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6958 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6959 | EXPECT_TRUE(response->headers); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6960 | std::string status_line = response->headers->GetStatusLine(); |
| 6961 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 6962 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6963 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6964 | |
| 6965 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6966 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6967 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6968 | EXPECT_EQ("", response_data); |
| 6969 | |
| 6970 | // Empty the current queue. This is necessary because idle sockets are |
| 6971 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6972 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6973 | |
| 6974 | // 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] | 6975 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6976 | } |
| 6977 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6978 | TEST_F(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6979 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 6980 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6981 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 6982 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 6983 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6984 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6985 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 6986 | // after use. |
| 6987 | request[0].method = "GET"; |
| 6988 | request[0].url = GURL("http://www.google.com/"); |
| 6989 | request[0].load_flags = 0; |
| 6990 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 6991 | // transaction 1. The first attempts fails when writing the POST data. |
| 6992 | // This causes the transaction to retry with a new socket. The second |
| 6993 | // attempt succeeds. |
| 6994 | request[1].method = "POST"; |
| 6995 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 6996 | request[1].upload_data_stream = &upload_data_stream; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6997 | request[1].load_flags = 0; |
| 6998 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6999 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7000 | |
| 7001 | // The first socket is used for transaction 1 and the first attempt of |
| 7002 | // transaction 2. |
| 7003 | |
| 7004 | // The response of transaction 1. |
| 7005 | MockRead data_reads1[] = { |
| 7006 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 7007 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7008 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7009 | }; |
| 7010 | // The mock write results of transaction 1 and the first attempt of |
| 7011 | // transaction 2. |
| 7012 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7013 | MockWrite(SYNCHRONOUS, 64), // GET |
| 7014 | MockWrite(SYNCHRONOUS, 93), // POST |
| 7015 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7016 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7017 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7018 | data_writes1, arraysize(data_writes1)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7019 | |
| 7020 | // The second socket is used for the second attempt of transaction 2. |
| 7021 | |
| 7022 | // The response of transaction 2. |
| 7023 | MockRead data_reads2[] = { |
| 7024 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 7025 | MockRead("welcome"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7026 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7027 | }; |
| 7028 | // The mock write results of the second attempt of transaction 2. |
| 7029 | MockWrite data_writes2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7030 | MockWrite(SYNCHRONOUS, 93), // POST |
| 7031 | MockWrite(SYNCHRONOUS, 3), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7032 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7033 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7034 | data_writes2, arraysize(data_writes2)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7035 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7036 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7037 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7038 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 7039 | const char* const kExpectedResponseData[] = { |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7040 | "hello world", "welcome" |
| 7041 | }; |
| 7042 | |
| 7043 | for (int i = 0; i < 2; ++i) { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7044 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7045 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7046 | TestCompletionCallback callback; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7047 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7048 | int rv = trans.Start(&request[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7049 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7050 | |
| 7051 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7052 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7053 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7054 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7055 | ASSERT_TRUE(response); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7056 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7057 | EXPECT_TRUE(response->headers); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7058 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 7059 | |
| 7060 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7061 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7062 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7063 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 7064 | } |
| 7065 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7066 | |
| 7067 | // Test the request-challenge-retry sequence for basic auth when there is |
| 7068 | // 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] | 7069 | // it fails the identity from the URL is used to answer the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7070 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7071 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7072 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7073 | request.url = GURL("http://foo:b@[email protected]/"); |
[email protected] | 7b08ba6 | 2012-02-10 20:19:41 | [diff] [blame] | 7074 | request.load_flags = LOAD_NORMAL; |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 7075 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7076 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7077 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7078 | |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 7079 | // The password contains an escaped character -- for this test to pass it |
| 7080 | // will need to be unescaped by HttpNetworkTransaction. |
| 7081 | EXPECT_EQ("b%40r", request.url.password()); |
| 7082 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7083 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7084 | MockWrite( |
| 7085 | "GET / HTTP/1.1\r\n" |
| 7086 | "Host: www.example.org\r\n" |
| 7087 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7088 | }; |
| 7089 | |
| 7090 | MockRead data_reads1[] = { |
| 7091 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7092 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7093 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7094 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7095 | }; |
| 7096 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7097 | // After the challenge above, the transaction will be restarted using the |
| 7098 | // identity from the url (foo, b@r) to answer the challenge. |
| 7099 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7100 | MockWrite( |
| 7101 | "GET / HTTP/1.1\r\n" |
| 7102 | "Host: www.example.org\r\n" |
| 7103 | "Connection: keep-alive\r\n" |
| 7104 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7105 | }; |
| 7106 | |
| 7107 | MockRead data_reads2[] = { |
| 7108 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7109 | MockRead("Content-Length: 100\r\n\r\n"), |
| 7110 | MockRead(SYNCHRONOUS, OK), |
| 7111 | }; |
| 7112 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7113 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7114 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7115 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7116 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7117 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7118 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7119 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7120 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7121 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7122 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7123 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7124 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7125 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7126 | |
| 7127 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7128 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7129 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7130 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7131 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7132 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7133 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7134 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7135 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7136 | |
| 7137 | // There is no challenge info, since the identity in URL worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7138 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7139 | |
| 7140 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7141 | |
| 7142 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7143 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7144 | } |
| 7145 | |
| 7146 | // Test the request-challenge-retry sequence for basic auth when there is an |
| 7147 | // incorrect identity in the URL. The identity from the URL should be used only |
| 7148 | // once. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7149 | TEST_F(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7150 | HttpRequestInfo request; |
| 7151 | request.method = "GET"; |
| 7152 | // Note: the URL has a username:password in it. The password "baz" is |
| 7153 | // wrong (should be "bar"). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7154 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7155 | |
| 7156 | request.load_flags = LOAD_NORMAL; |
| 7157 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7158 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7159 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7160 | |
| 7161 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7162 | MockWrite( |
| 7163 | "GET / HTTP/1.1\r\n" |
| 7164 | "Host: www.example.org\r\n" |
| 7165 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7166 | }; |
| 7167 | |
| 7168 | MockRead data_reads1[] = { |
| 7169 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7170 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7171 | MockRead("Content-Length: 10\r\n\r\n"), |
| 7172 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 7173 | }; |
| 7174 | |
| 7175 | // After the challenge above, the transaction will be restarted using the |
| 7176 | // identity from the url (foo, baz) to answer the challenge. |
| 7177 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7178 | MockWrite( |
| 7179 | "GET / HTTP/1.1\r\n" |
| 7180 | "Host: www.example.org\r\n" |
| 7181 | "Connection: keep-alive\r\n" |
| 7182 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7183 | }; |
| 7184 | |
| 7185 | MockRead data_reads2[] = { |
| 7186 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7187 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7188 | MockRead("Content-Length: 10\r\n\r\n"), |
| 7189 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 7190 | }; |
| 7191 | |
| 7192 | // After the challenge above, the transaction will be restarted using the |
| 7193 | // identity supplied by the user (foo, bar) to answer the challenge. |
| 7194 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7195 | MockWrite( |
| 7196 | "GET / HTTP/1.1\r\n" |
| 7197 | "Host: www.example.org\r\n" |
| 7198 | "Connection: keep-alive\r\n" |
| 7199 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7200 | }; |
| 7201 | |
| 7202 | MockRead data_reads3[] = { |
| 7203 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7204 | MockRead("Content-Length: 100\r\n\r\n"), |
| 7205 | MockRead(SYNCHRONOUS, OK), |
| 7206 | }; |
| 7207 | |
| 7208 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7209 | data_writes1, arraysize(data_writes1)); |
| 7210 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7211 | data_writes2, arraysize(data_writes2)); |
| 7212 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 7213 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7214 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7215 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7216 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7217 | |
| 7218 | TestCompletionCallback callback1; |
| 7219 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7220 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7221 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7222 | |
| 7223 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7224 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7225 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7226 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7227 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7228 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7229 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7230 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7231 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7232 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7233 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7234 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7235 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7236 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 7237 | |
| 7238 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7239 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7240 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7241 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7242 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7243 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7244 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7245 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7246 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7247 | |
| 7248 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7249 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7250 | |
| 7251 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7252 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 7253 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7254 | base::RunLoop().RunUntilIdle(); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 7255 | } |
| 7256 | |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7257 | |
| 7258 | // Test the request-challenge-retry sequence for basic auth when there is a |
| 7259 | // correct identity in the URL, but its use is being suppressed. The identity |
| 7260 | // from the URL should never be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7261 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURLSuppressed) { |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7262 | HttpRequestInfo request; |
| 7263 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7264 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7265 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
| 7266 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7267 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7268 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7269 | |
| 7270 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7271 | MockWrite( |
| 7272 | "GET / HTTP/1.1\r\n" |
| 7273 | "Host: www.example.org\r\n" |
| 7274 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7275 | }; |
| 7276 | |
| 7277 | MockRead data_reads1[] = { |
| 7278 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7279 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7280 | MockRead("Content-Length: 10\r\n\r\n"), |
| 7281 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 7282 | }; |
| 7283 | |
| 7284 | // After the challenge above, the transaction will be restarted using the |
| 7285 | // identity supplied by the user, not the one in the URL, to answer the |
| 7286 | // challenge. |
| 7287 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7288 | MockWrite( |
| 7289 | "GET / HTTP/1.1\r\n" |
| 7290 | "Host: www.example.org\r\n" |
| 7291 | "Connection: keep-alive\r\n" |
| 7292 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7293 | }; |
| 7294 | |
| 7295 | MockRead data_reads3[] = { |
| 7296 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7297 | MockRead("Content-Length: 100\r\n\r\n"), |
| 7298 | MockRead(SYNCHRONOUS, OK), |
| 7299 | }; |
| 7300 | |
| 7301 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7302 | data_writes1, arraysize(data_writes1)); |
| 7303 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 7304 | data_writes3, arraysize(data_writes3)); |
| 7305 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7306 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 7307 | |
| 7308 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7309 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7310 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7311 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7312 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7313 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7314 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7315 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7316 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7317 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 7318 | |
| 7319 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7320 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7321 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7322 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7323 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7324 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7325 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7326 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7327 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7328 | |
| 7329 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7330 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7331 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7332 | |
| 7333 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7334 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7335 | } |
| 7336 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7337 | // Test that previously tried username/passwords for a realm get re-used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7338 | TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7339 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7340 | |
| 7341 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 7342 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7343 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7344 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7345 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7346 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7347 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7348 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7349 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7350 | MockWrite( |
| 7351 | "GET /x/y/z HTTP/1.1\r\n" |
| 7352 | "Host: www.example.org\r\n" |
| 7353 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7354 | }; |
| 7355 | |
| 7356 | MockRead data_reads1[] = { |
| 7357 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7358 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7359 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7360 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7361 | }; |
| 7362 | |
| 7363 | // Resend with authorization (username=foo, password=bar) |
| 7364 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7365 | MockWrite( |
| 7366 | "GET /x/y/z HTTP/1.1\r\n" |
| 7367 | "Host: www.example.org\r\n" |
| 7368 | "Connection: keep-alive\r\n" |
| 7369 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7370 | }; |
| 7371 | |
| 7372 | // Sever accepts the authorization. |
| 7373 | MockRead data_reads2[] = { |
| 7374 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7375 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7376 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7377 | }; |
| 7378 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7379 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7380 | data_writes1, arraysize(data_writes1)); |
| 7381 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7382 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7383 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7384 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7385 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7386 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7387 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7388 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7389 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7390 | |
| 7391 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7392 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7393 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7394 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7395 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7396 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7397 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7398 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7399 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7400 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 7401 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7402 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7403 | |
| 7404 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7405 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7406 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7407 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7408 | ASSERT_TRUE(response); |
| 7409 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7410 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7411 | } |
| 7412 | |
| 7413 | // ------------------------------------------------------------------------ |
| 7414 | |
| 7415 | // Transaction 2: authenticate (foo2, bar2) on MyRealm2 |
| 7416 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7417 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7418 | request.method = "GET"; |
| 7419 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 7420 | // protection space as MyRealm1. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7421 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7422 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7423 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7424 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7425 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7426 | MockWrite( |
| 7427 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 7428 | "Host: www.example.org\r\n" |
| 7429 | "Connection: keep-alive\r\n" |
| 7430 | // Send preemptive authorization for MyRealm1 |
| 7431 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7432 | }; |
| 7433 | |
| 7434 | // The server didn't like the preemptive authorization, and |
| 7435 | // challenges us for a different realm (MyRealm2). |
| 7436 | MockRead data_reads1[] = { |
| 7437 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7438 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 7439 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7440 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7441 | }; |
| 7442 | |
| 7443 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 7444 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7445 | MockWrite( |
| 7446 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 7447 | "Host: www.example.org\r\n" |
| 7448 | "Connection: keep-alive\r\n" |
| 7449 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7450 | }; |
| 7451 | |
| 7452 | // Sever accepts the authorization. |
| 7453 | MockRead data_reads2[] = { |
| 7454 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7455 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7456 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7457 | }; |
| 7458 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7459 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7460 | data_writes1, arraysize(data_writes1)); |
| 7461 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7462 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7463 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7464 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7465 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7466 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7467 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7468 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7469 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7470 | |
| 7471 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7472 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7473 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7474 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7475 | ASSERT_TRUE(response); |
| 7476 | ASSERT_TRUE(response->auth_challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7477 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 7478 | EXPECT_EQ("http://www.example.org", |
| 7479 | response->auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7480 | EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 7481 | EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7482 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7483 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7484 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7485 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 7486 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7487 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7488 | |
| 7489 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7490 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7491 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7492 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7493 | ASSERT_TRUE(response); |
| 7494 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7495 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7496 | } |
| 7497 | |
| 7498 | // ------------------------------------------------------------------------ |
| 7499 | |
| 7500 | // Transaction 3: Resend a request in MyRealm's protection space -- |
| 7501 | // succeed with preemptive authorization. |
| 7502 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7503 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7504 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7505 | request.url = GURL("http://www.example.org/x/y/z2"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7506 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7507 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7508 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7509 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7510 | MockWrite( |
| 7511 | "GET /x/y/z2 HTTP/1.1\r\n" |
| 7512 | "Host: www.example.org\r\n" |
| 7513 | "Connection: keep-alive\r\n" |
| 7514 | // The authorization for MyRealm1 gets sent preemptively |
| 7515 | // (since the url is in the same protection space) |
| 7516 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7517 | }; |
| 7518 | |
| 7519 | // Sever accepts the preemptive authorization |
| 7520 | MockRead data_reads1[] = { |
| 7521 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7522 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7523 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7524 | }; |
| 7525 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7526 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7527 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7528 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7529 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7530 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7531 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7532 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7533 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7534 | |
| 7535 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7536 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7537 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7538 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7539 | ASSERT_TRUE(response); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7540 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7541 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7542 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7543 | } |
| 7544 | |
| 7545 | // ------------------------------------------------------------------------ |
| 7546 | |
| 7547 | // Transaction 4: request another URL in MyRealm (however the |
| 7548 | // url is not known to belong to the protection space, so no pre-auth). |
| 7549 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7550 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7551 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7552 | request.url = GURL("http://www.example.org/x/1"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7553 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7554 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7555 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7556 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7557 | MockWrite( |
| 7558 | "GET /x/1 HTTP/1.1\r\n" |
| 7559 | "Host: www.example.org\r\n" |
| 7560 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7561 | }; |
| 7562 | |
| 7563 | MockRead data_reads1[] = { |
| 7564 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7565 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7566 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7567 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7568 | }; |
| 7569 | |
| 7570 | // Resend with authorization from MyRealm's cache. |
| 7571 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7572 | MockWrite( |
| 7573 | "GET /x/1 HTTP/1.1\r\n" |
| 7574 | "Host: www.example.org\r\n" |
| 7575 | "Connection: keep-alive\r\n" |
| 7576 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7577 | }; |
| 7578 | |
| 7579 | // Sever accepts the authorization. |
| 7580 | MockRead data_reads2[] = { |
| 7581 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7582 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7583 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7584 | }; |
| 7585 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7586 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7587 | data_writes1, arraysize(data_writes1)); |
| 7588 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7589 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7590 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7591 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7592 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7593 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7594 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7595 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7596 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7597 | |
| 7598 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7599 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7600 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7601 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7602 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7603 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7604 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7605 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7606 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7607 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7608 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7609 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7610 | ASSERT_TRUE(response); |
| 7611 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7612 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7613 | } |
| 7614 | |
| 7615 | // ------------------------------------------------------------------------ |
| 7616 | |
| 7617 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 7618 | // cached identity. Should invalidate and re-prompt. |
| 7619 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7620 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7621 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7622 | request.url = GURL("http://www.example.org/p/q/t"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7623 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7624 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7625 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7626 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7627 | MockWrite( |
| 7628 | "GET /p/q/t HTTP/1.1\r\n" |
| 7629 | "Host: www.example.org\r\n" |
| 7630 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7631 | }; |
| 7632 | |
| 7633 | MockRead data_reads1[] = { |
| 7634 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7635 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7636 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7637 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7638 | }; |
| 7639 | |
| 7640 | // Resend with authorization from cache for MyRealm. |
| 7641 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7642 | MockWrite( |
| 7643 | "GET /p/q/t HTTP/1.1\r\n" |
| 7644 | "Host: www.example.org\r\n" |
| 7645 | "Connection: keep-alive\r\n" |
| 7646 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7647 | }; |
| 7648 | |
| 7649 | // Sever rejects the authorization. |
| 7650 | MockRead data_reads2[] = { |
| 7651 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7652 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7653 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7654 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7655 | }; |
| 7656 | |
| 7657 | // At this point we should prompt for new credentials for MyRealm. |
| 7658 | // Restart with username=foo3, password=foo4. |
| 7659 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7660 | MockWrite( |
| 7661 | "GET /p/q/t HTTP/1.1\r\n" |
| 7662 | "Host: www.example.org\r\n" |
| 7663 | "Connection: keep-alive\r\n" |
| 7664 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7665 | }; |
| 7666 | |
| 7667 | // Sever accepts the authorization. |
| 7668 | MockRead data_reads3[] = { |
| 7669 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7670 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7671 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7672 | }; |
| 7673 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7674 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7675 | data_writes1, arraysize(data_writes1)); |
| 7676 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7677 | data_writes2, arraysize(data_writes2)); |
| 7678 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 7679 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7680 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7681 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7682 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7683 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7684 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7685 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7686 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7687 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7688 | |
| 7689 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7690 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7691 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7692 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7693 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7694 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7695 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7696 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7697 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7698 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7699 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7700 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7701 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7702 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7703 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7704 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7705 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7706 | rv = trans.RestartWithAuth(AuthCredentials(kFoo3, kBar3), |
| 7707 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7708 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7709 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7710 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7711 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7712 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7713 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7714 | ASSERT_TRUE(response); |
| 7715 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7716 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7717 | } |
| 7718 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7719 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7720 | // Tests that nonce count increments when multiple auth attempts |
| 7721 | // are started with the same nonce. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7722 | TEST_F(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { |
[email protected] | 54fea256 | 2010-11-17 14:40:44 | [diff] [blame] | 7723 | HttpAuthHandlerDigest::Factory* digest_factory = |
| 7724 | new HttpAuthHandlerDigest::Factory(); |
| 7725 | HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = |
| 7726 | new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); |
| 7727 | digest_factory->set_nonce_generator(nonce_generator); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7728 | session_deps_.http_auth_handler_factory.reset(digest_factory); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7729 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7730 | |
| 7731 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 7732 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7733 | HttpRequestInfo request; |
| 7734 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7735 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7736 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7737 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7738 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7739 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7740 | MockWrite( |
| 7741 | "GET /x/y/z HTTP/1.1\r\n" |
| 7742 | "Host: www.example.org\r\n" |
| 7743 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7744 | }; |
| 7745 | |
| 7746 | MockRead data_reads1[] = { |
| 7747 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7748 | MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " |
| 7749 | "algorithm=MD5, qop=\"auth\"\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7750 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7751 | }; |
| 7752 | |
| 7753 | // Resend with authorization (username=foo, password=bar) |
| 7754 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7755 | MockWrite( |
| 7756 | "GET /x/y/z HTTP/1.1\r\n" |
| 7757 | "Host: www.example.org\r\n" |
| 7758 | "Connection: keep-alive\r\n" |
| 7759 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 7760 | "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " |
| 7761 | "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " |
| 7762 | "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7763 | }; |
| 7764 | |
| 7765 | // Sever accepts the authorization. |
| 7766 | MockRead data_reads2[] = { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 7767 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7768 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7769 | }; |
| 7770 | |
| 7771 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7772 | data_writes1, arraysize(data_writes1)); |
| 7773 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7774 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7775 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7776 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7777 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7778 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7779 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7780 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7781 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7782 | |
| 7783 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7784 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7785 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7786 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7787 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7788 | EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge.get())); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7789 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7790 | TestCompletionCallback callback2; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7791 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7792 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 7793 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7794 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7795 | |
| 7796 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7797 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7798 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7799 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7800 | ASSERT_TRUE(response); |
| 7801 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7802 | } |
| 7803 | |
| 7804 | // ------------------------------------------------------------------------ |
| 7805 | |
| 7806 | // Transaction 2: Request another resource in digestive's protection space. |
| 7807 | // This will preemptively add an Authorization header which should have an |
| 7808 | // "nc" value of 2 (as compared to 1 in the first use. |
| 7809 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7810 | HttpRequestInfo request; |
| 7811 | request.method = "GET"; |
| 7812 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 7813 | // protection space as digest. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7814 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7815 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7816 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7817 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7818 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7819 | MockWrite( |
| 7820 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 7821 | "Host: www.example.org\r\n" |
| 7822 | "Connection: keep-alive\r\n" |
| 7823 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 7824 | "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " |
| 7825 | "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " |
| 7826 | "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7827 | }; |
| 7828 | |
| 7829 | // Sever accepts the authorization. |
| 7830 | MockRead data_reads1[] = { |
| 7831 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7832 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7833 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7834 | }; |
| 7835 | |
| 7836 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7837 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7838 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7839 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7840 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7841 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7842 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7843 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7844 | |
| 7845 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7846 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7847 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7848 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7849 | ASSERT_TRUE(response); |
| 7850 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7851 | } |
| 7852 | } |
| 7853 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7854 | // Test the ResetStateForRestart() private method. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7855 | TEST_F(HttpNetworkTransactionTest, ResetStateForRestart) { |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7856 | // Create a transaction (the dependencies aren't important). |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7857 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7858 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7859 | |
| 7860 | // Setup some state (which we expect ResetStateForRestart() will clear). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7861 | trans.read_buf_ = new IOBuffer(15); |
| 7862 | trans.read_buf_len_ = 15; |
| 7863 | trans.request_headers_.SetHeader("Authorization", "NTLM"); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7864 | |
| 7865 | // Setup state in response_ |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7866 | HttpResponseInfo* response = &trans.response_; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7867 | response->auth_challenge = new AuthChallengeInfo(); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 7868 | response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7869 | response->response_time = base::Time::Now(); |
| 7870 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7871 | |
| 7872 | { // Setup state for response_.vary_data |
| 7873 | HttpRequestInfo request; |
| 7874 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 7875 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 7876 | scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 7877 | request.extra_headers.SetHeader("Foo", "1"); |
| 7878 | request.extra_headers.SetHeader("bar", "23"); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7879 | EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7880 | } |
| 7881 | |
| 7882 | // Cause the above state to be reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7883 | trans.ResetStateForRestart(); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7884 | |
| 7885 | // Verify that the state that needed to be reset, has been reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7886 | EXPECT_FALSE(trans.read_buf_); |
| 7887 | EXPECT_EQ(0, trans.read_buf_len_); |
| 7888 | EXPECT_TRUE(trans.request_headers_.IsEmpty()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7889 | EXPECT_FALSE(response->auth_challenge); |
| 7890 | EXPECT_FALSE(response->headers); |
[email protected] | 34f4094 | 2010-10-04 00:34:04 | [diff] [blame] | 7891 | EXPECT_FALSE(response->was_cached); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 7892 | EXPECT_EQ(0U, response->ssl_info.cert_status); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7893 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7894 | } |
| 7895 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7896 | // Test HTTPS connections to a site with a bad certificate |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7897 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7898 | HttpRequestInfo request; |
| 7899 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7900 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7901 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7902 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7903 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7904 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7905 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7906 | MockWrite( |
| 7907 | "GET / HTTP/1.1\r\n" |
| 7908 | "Host: www.example.org\r\n" |
| 7909 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7910 | }; |
| 7911 | |
| 7912 | MockRead data_reads[] = { |
| 7913 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7914 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7915 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7916 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7917 | }; |
| 7918 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 7919 | StaticSocketDataProvider ssl_bad_certificate; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7920 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7921 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7922 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 7923 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7924 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7925 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 7926 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7927 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 7928 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7929 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7930 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7931 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7932 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7933 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7934 | |
| 7935 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7936 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7937 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7938 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7939 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7940 | |
| 7941 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7942 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7943 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7944 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7945 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7946 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7947 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7948 | } |
| 7949 | |
| 7950 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 7951 | // proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7952 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7953 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7954 | |
| 7955 | HttpRequestInfo request; |
| 7956 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7957 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7958 | |
| 7959 | MockWrite proxy_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7960 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7961 | "Host: www.example.org:443\r\n" |
| 7962 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7963 | }; |
| 7964 | |
| 7965 | MockRead proxy_reads[] = { |
| 7966 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7967 | MockRead(SYNCHRONOUS, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7968 | }; |
| 7969 | |
| 7970 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7971 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7972 | "Host: www.example.org:443\r\n" |
| 7973 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7974 | MockWrite("GET / HTTP/1.1\r\n" |
| 7975 | "Host: www.example.org\r\n" |
| 7976 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7977 | }; |
| 7978 | |
| 7979 | MockRead data_reads[] = { |
| 7980 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 7981 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7982 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7983 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7984 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7985 | }; |
| 7986 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7987 | StaticSocketDataProvider ssl_bad_certificate( |
| 7988 | proxy_reads, arraysize(proxy_reads), |
| 7989 | proxy_writes, arraysize(proxy_writes)); |
| 7990 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7991 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7992 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 7993 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7994 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7995 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 7996 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7997 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 7998 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7999 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8000 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8001 | |
| 8002 | for (int i = 0; i < 2; i++) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8003 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8004 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8005 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8006 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8007 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8008 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8009 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8010 | |
| 8011 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8012 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8013 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8014 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8015 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8016 | |
| 8017 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8018 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8019 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8020 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8021 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8022 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8023 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8024 | } |
| 8025 | } |
| 8026 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8027 | |
| 8028 | // Test HTTPS connections to a site, going through an HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8029 | TEST_F(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8030 | session_deps_.proxy_service = |
| 8031 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8032 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8033 | session_deps_.net_log = &net_log; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8034 | |
| 8035 | HttpRequestInfo request; |
| 8036 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8037 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8038 | |
| 8039 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8040 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8041 | "Host: www.example.org:443\r\n" |
| 8042 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 8043 | MockWrite("GET / HTTP/1.1\r\n" |
| 8044 | "Host: www.example.org\r\n" |
| 8045 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8046 | }; |
| 8047 | |
| 8048 | MockRead data_reads[] = { |
| 8049 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 8050 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 8051 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8052 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8053 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8054 | }; |
| 8055 | |
| 8056 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8057 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8058 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 8059 | SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8060 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8061 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8062 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 8063 | session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8064 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8065 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8066 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8067 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8068 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8069 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8070 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8071 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8072 | |
| 8073 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8074 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8075 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8076 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8077 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8078 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 8079 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8080 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8081 | EXPECT_EQ(200, response->headers->response_code()); |
| 8082 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8083 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8084 | |
| 8085 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8086 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8087 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8088 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8089 | } |
| 8090 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8091 | // Test an HTTPS Proxy's ability to redirect a CONNECT request |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8092 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8093 | session_deps_.proxy_service = |
| 8094 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8095 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8096 | session_deps_.net_log = &net_log; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8097 | |
| 8098 | HttpRequestInfo request; |
| 8099 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8100 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8101 | |
| 8102 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8103 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8104 | "Host: www.example.org:443\r\n" |
| 8105 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8106 | }; |
| 8107 | |
| 8108 | MockRead data_reads[] = { |
| 8109 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 8110 | MockRead("Location: http://login.example.com/\r\n"), |
| 8111 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8112 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8113 | }; |
| 8114 | |
| 8115 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8116 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8117 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8118 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8119 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8120 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8121 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8122 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8123 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8124 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8125 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8126 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8127 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8128 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8129 | |
| 8130 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8131 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8132 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8133 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8134 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8135 | |
| 8136 | EXPECT_EQ(302, response->headers->response_code()); |
| 8137 | std::string url; |
| 8138 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 8139 | EXPECT_EQ("http://login.example.com/", url); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8140 | |
| 8141 | // In the case of redirects from proxies, HttpNetworkTransaction returns |
| 8142 | // timing for the proxy connection instead of the connection to the host, |
| 8143 | // and no send / receive times. |
| 8144 | // See HttpNetworkTransaction::OnHttpsProxyTunnelResponse. |
| 8145 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8146 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8147 | |
| 8148 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 8149 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8150 | |
| 8151 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 8152 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 8153 | load_timing_info.proxy_resolve_end); |
| 8154 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 8155 | load_timing_info.connect_timing.connect_start); |
| 8156 | ExpectConnectTimingHasTimes( |
| 8157 | load_timing_info.connect_timing, |
| 8158 | CONNECT_TIMING_HAS_DNS_TIMES | CONNECT_TIMING_HAS_SSL_TIMES); |
| 8159 | |
| 8160 | EXPECT_TRUE(load_timing_info.send_start.is_null()); |
| 8161 | EXPECT_TRUE(load_timing_info.send_end.is_null()); |
| 8162 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8163 | } |
| 8164 | |
| 8165 | // Test an HTTPS (SPDY) Proxy's ability to redirect a CONNECT request |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8166 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8167 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8168 | |
| 8169 | HttpRequestInfo request; |
| 8170 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8171 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8172 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8173 | SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8174 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8175 | SpdySerializedFrame goaway( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 8176 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8177 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8178 | CreateMockWrite(conn, 0, SYNCHRONOUS), |
| 8179 | CreateMockWrite(goaway, 2, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8180 | }; |
| 8181 | |
| 8182 | static const char* const kExtraHeaders[] = { |
| 8183 | "location", |
| 8184 | "http://login.example.com/", |
| 8185 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8186 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
bnc | c9f762a | 2016-12-06 20:38:23 | [diff] [blame] | 8187 | "302", kExtraHeaders, arraysize(kExtraHeaders) / 2, 1)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8188 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8189 | CreateMockRead(resp, 1), MockRead(ASYNC, 0, 3), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8190 | }; |
| 8191 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8192 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 8193 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8194 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8195 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8196 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8197 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8198 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8199 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8200 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8201 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8202 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8203 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8204 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8205 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8206 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8207 | |
| 8208 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8209 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8210 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8211 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8212 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8213 | |
| 8214 | EXPECT_EQ(302, response->headers->response_code()); |
| 8215 | std::string url; |
| 8216 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 8217 | EXPECT_EQ("http://login.example.com/", url); |
| 8218 | } |
| 8219 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 8220 | // Test that an HTTPS proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8221 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8222 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8223 | |
| 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] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8227 | |
| 8228 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8229 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8230 | "Host: www.example.org:443\r\n" |
| 8231 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8232 | }; |
| 8233 | |
| 8234 | MockRead data_reads[] = { |
| 8235 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 8236 | MockRead("Content-Length: 23\r\n\r\n"), |
| 8237 | MockRead("The host does not exist"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8238 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8239 | }; |
| 8240 | |
| 8241 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8242 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8243 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8244 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8245 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8246 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8247 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8248 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8249 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8250 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8251 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8252 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8253 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8254 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8255 | |
| 8256 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8257 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8258 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 8259 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8260 | } |
| 8261 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 8262 | // Test that a SPDY proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8263 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaSpdyProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8264 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8265 | |
| 8266 | HttpRequestInfo request; |
| 8267 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8268 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8269 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8270 | SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8271 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8272 | SpdySerializedFrame rst( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 8273 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8274 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8275 | CreateMockWrite(conn, 0), CreateMockWrite(rst, 3), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8276 | }; |
| 8277 | |
| 8278 | static const char* const kExtraHeaders[] = { |
| 8279 | "location", |
| 8280 | "http://login.example.com/", |
| 8281 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8282 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
bnc | c9f762a | 2016-12-06 20:38:23 | [diff] [blame] | 8283 | "404", kExtraHeaders, arraysize(kExtraHeaders) / 2, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8284 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 8285 | 1, "The host does not exist", 23, true)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8286 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8287 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8288 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8289 | }; |
| 8290 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8291 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 8292 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8293 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8294 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8295 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8296 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8297 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8298 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8299 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8300 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8301 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8302 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8303 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8304 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8305 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8306 | |
| 8307 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8308 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8309 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 8310 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8311 | } |
| 8312 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8313 | // Test the request-challenge-retry sequence for basic auth, through |
| 8314 | // a SPDY proxy over a single SPDY session. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8315 | TEST_F(HttpNetworkTransactionTest, BasicAuthSpdyProxy) { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8316 | HttpRequestInfo request; |
| 8317 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8318 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8319 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 8320 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8321 | |
| 8322 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8323 | session_deps_.proxy_service = |
| 8324 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8325 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8326 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8327 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8328 | |
| 8329 | // Since we have proxy, should try to establish tunnel. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8330 | SpdySerializedFrame req(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8331 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8332 | SpdySerializedFrame rst( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 8333 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 8334 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8335 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8336 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8337 | // be issuing -- the final header line contains the credentials. |
| 8338 | const char* const kAuthCredentials[] = { |
| 8339 | "proxy-authorization", "Basic Zm9vOmJhcg==", |
| 8340 | }; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8341 | SpdySerializedFrame connect2(spdy_util_.ConstructSpdyConnect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 8342 | kAuthCredentials, arraysize(kAuthCredentials) / 2, 3, LOWEST, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8343 | HostPortPair("www.example.org", 443))); |
| 8344 | // fetch https://www.example.org/ via HTTP |
| 8345 | const char get[] = |
| 8346 | "GET / HTTP/1.1\r\n" |
| 8347 | "Host: www.example.org\r\n" |
| 8348 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8349 | SpdySerializedFrame wrapped_get( |
| 8350 | spdy_util_.ConstructSpdyDataFrame(3, get, strlen(get), false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8351 | |
| 8352 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8353 | CreateMockWrite(req, 0, ASYNC), CreateMockWrite(rst, 2, ASYNC), |
| 8354 | CreateMockWrite(connect2, 3), CreateMockWrite(wrapped_get, 5), |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8355 | }; |
| 8356 | |
| 8357 | // The proxy responds to the connect with a 407, using a persistent |
| 8358 | // connection. |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 8359 | const char kAuthStatus[] = "407"; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8360 | const char* const kAuthChallenge[] = { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8361 | "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 8362 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8363 | SpdySerializedFrame conn_auth_resp(spdy_util_.ConstructSpdyReplyError( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8364 | kAuthStatus, kAuthChallenge, arraysize(kAuthChallenge) / 2, 1)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8365 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8366 | SpdySerializedFrame conn_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8367 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 8368 | "Content-Length: 5\r\n\r\n"; |
| 8369 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8370 | SpdySerializedFrame wrapped_get_resp( |
| 8371 | spdy_util_.ConstructSpdyDataFrame(3, resp, strlen(resp), false)); |
| 8372 | SpdySerializedFrame wrapped_body( |
| 8373 | spdy_util_.ConstructSpdyDataFrame(3, "hello", 5, false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8374 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8375 | CreateMockRead(conn_auth_resp, 1, ASYNC), |
| 8376 | CreateMockRead(conn_resp, 4, ASYNC), |
| 8377 | CreateMockRead(wrapped_get_resp, 6, ASYNC), |
| 8378 | CreateMockRead(wrapped_body, 7, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8379 | MockRead(ASYNC, OK, 8), // EOF. May or may not be read. |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8380 | }; |
| 8381 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8382 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8383 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8384 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8385 | // Negotiate SPDY to the proxy |
| 8386 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8387 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8388 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8389 | // Vanilla SSL to the server |
| 8390 | SSLSocketDataProvider server(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8391 | session_deps_.socket_factory->AddSSLSocketDataProvider(&server); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8392 | |
| 8393 | TestCompletionCallback callback1; |
| 8394 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8395 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8396 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8397 | |
| 8398 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8399 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8400 | |
| 8401 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8402 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 8403 | TestNetLogEntry::List entries; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8404 | log.GetEntries(&entries); |
| 8405 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 8406 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 8407 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8408 | ExpectLogContainsSomewhere( |
| 8409 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 8410 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 8411 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8412 | |
| 8413 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8414 | ASSERT_TRUE(response); |
| 8415 | ASSERT_TRUE(response->headers); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8416 | EXPECT_EQ(407, response->headers->response_code()); |
| 8417 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8418 | EXPECT_TRUE(response->auth_challenge); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 8419 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8420 | |
| 8421 | TestCompletionCallback callback2; |
| 8422 | |
| 8423 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 8424 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8425 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8426 | |
| 8427 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8428 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8429 | |
| 8430 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8431 | ASSERT_TRUE(response); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8432 | |
| 8433 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8434 | EXPECT_EQ(200, response->headers->response_code()); |
| 8435 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 8436 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8437 | |
| 8438 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8439 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8440 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8441 | LoadTimingInfo load_timing_info; |
| 8442 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8443 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8444 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 8445 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8446 | trans.reset(); |
| 8447 | session->CloseAllConnections(); |
| 8448 | } |
| 8449 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8450 | // Test that an explicitly trusted SPDY proxy can push a resource from an |
| 8451 | // origin that is different from that of its associated resource. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8452 | TEST_F(HttpNetworkTransactionTest, CrossOriginSPDYProxyPush) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8453 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8454 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8455 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 8456 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8457 | HttpRequestInfo request; |
| 8458 | HttpRequestInfo push_request; |
| 8459 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8460 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8461 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8462 | push_request.method = "GET"; |
| 8463 | push_request.url = GURL("http://www.another-origin.com/foo.dat"); |
| 8464 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8465 | // Configure against https proxy server "myproxy:443". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8466 | session_deps_.proxy_service = |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8467 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:443"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8468 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8469 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8470 | |
inlinechan | 894515af | 2016-12-09 02:40:10 | [diff] [blame] | 8471 | session_deps_.proxy_delegate = std::move(proxy_delegate); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8472 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8473 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8474 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8475 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 8476 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8477 | SpdySerializedFrame stream2_priority( |
| 8478 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8479 | |
| 8480 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8481 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8482 | CreateMockWrite(stream2_priority, 3, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8483 | }; |
| 8484 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8485 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8486 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8487 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8488 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8489 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8490 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 8491 | NULL, 0, 2, 1, "http://www.another-origin.com/foo.dat")); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8492 | const char kPushedData[] = "pushed"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8493 | SpdySerializedFrame stream2_body(spdy_util_.ConstructSpdyDataFrame( |
| 8494 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8495 | |
| 8496 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8497 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 8498 | CreateMockRead(stream2_syn, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8499 | CreateMockRead(stream1_body, 4, ASYNC), |
| 8500 | CreateMockRead(stream2_body, 5, ASYNC), |
| 8501 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8502 | }; |
| 8503 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8504 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8505 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8506 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8507 | // Negotiate SPDY to the proxy |
| 8508 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8509 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8510 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8511 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8512 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8513 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8514 | TestCompletionCallback callback; |
| 8515 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8516 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8517 | |
| 8518 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8519 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8520 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8521 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8522 | auto push_trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8523 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8524 | rv = push_trans->Start(&push_request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8525 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8526 | |
| 8527 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8528 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8529 | const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); |
| 8530 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8531 | ASSERT_TRUE(response); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8532 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8533 | |
| 8534 | EXPECT_EQ(200, response->headers->response_code()); |
| 8535 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8536 | |
| 8537 | std::string response_data; |
| 8538 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8539 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8540 | EXPECT_EQ("hello!", response_data); |
| 8541 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8542 | LoadTimingInfo load_timing_info; |
| 8543 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8544 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8545 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 8546 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8547 | // Verify the pushed stream. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8548 | EXPECT_TRUE(push_response->headers); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8549 | EXPECT_EQ(200, push_response->headers->response_code()); |
| 8550 | |
| 8551 | rv = ReadTransaction(push_trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8552 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8553 | EXPECT_EQ("pushed", response_data); |
| 8554 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8555 | LoadTimingInfo push_load_timing_info; |
| 8556 | EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); |
| 8557 | TestLoadTimingReusedWithPac(push_load_timing_info); |
| 8558 | // The transactions should share a socket ID, despite being for different |
| 8559 | // origins. |
| 8560 | EXPECT_EQ(load_timing_info.socket_log_id, |
| 8561 | push_load_timing_info.socket_log_id); |
| 8562 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8563 | trans.reset(); |
| 8564 | push_trans.reset(); |
| 8565 | session->CloseAllConnections(); |
| 8566 | } |
| 8567 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8568 | // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8569 | TEST_F(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8570 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8571 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8572 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 8573 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8574 | HttpRequestInfo request; |
| 8575 | |
| 8576 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8577 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8578 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8579 | session_deps_.proxy_service = |
| 8580 | ProxyService::CreateFixed("https://myproxy:443"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8581 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8582 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8583 | |
| 8584 | // Enable cross-origin push. |
inlinechan | 894515af | 2016-12-09 02:40:10 | [diff] [blame] | 8585 | session_deps_.proxy_delegate = std::move(proxy_delegate); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8586 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8587 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8588 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8589 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 8590 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8591 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8592 | SpdySerializedFrame push_rst( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 8593 | spdy_util_.ConstructSpdyRstStream(2, ERROR_CODE_REFUSED_STREAM)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8594 | |
| 8595 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8596 | CreateMockWrite(stream1_syn, 0, ASYNC), CreateMockWrite(push_rst, 3), |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8597 | }; |
| 8598 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8599 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8600 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8601 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8602 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8603 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8604 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 8605 | NULL, 0, 2, 1, "https://www.another-origin.com/foo.dat")); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8606 | |
| 8607 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8608 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 8609 | CreateMockRead(stream2_syn, 2, ASYNC), |
| 8610 | CreateMockRead(stream1_body, 4, ASYNC), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 8611 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a hang |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8612 | }; |
| 8613 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8614 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8615 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8616 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8617 | // Negotiate SPDY to the proxy |
| 8618 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8619 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8620 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8621 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8622 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8623 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8624 | TestCompletionCallback callback; |
| 8625 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8626 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8627 | |
| 8628 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8629 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8630 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8631 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8632 | ASSERT_TRUE(response); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8633 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8634 | |
| 8635 | EXPECT_EQ(200, response->headers->response_code()); |
| 8636 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8637 | |
| 8638 | std::string response_data; |
| 8639 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8640 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8641 | EXPECT_EQ("hello!", response_data); |
| 8642 | |
| 8643 | trans.reset(); |
| 8644 | session->CloseAllConnections(); |
| 8645 | } |
| 8646 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8647 | // Test that an explicitly trusted SPDY proxy can push same-origin HTTPS |
| 8648 | // resources. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8649 | TEST_F(HttpNetworkTransactionTest, SameOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8650 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8651 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8652 | proxy_delegate->set_trusted_spdy_proxy( |
| 8653 | net::ProxyServer::FromURI("myproxy:70", net::ProxyServer::SCHEME_HTTP)); |
| 8654 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8655 | HttpRequestInfo request; |
| 8656 | |
| 8657 | request.method = "GET"; |
| 8658 | request.url = GURL("http://www.example.org/"); |
| 8659 | |
| 8660 | // Configure against https proxy server "myproxy:70". |
| 8661 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
| 8662 | BoundTestNetLog log; |
| 8663 | session_deps_.net_log = log.bound().net_log(); |
| 8664 | |
| 8665 | // Enable cross-origin push. |
inlinechan | 894515af | 2016-12-09 02:40:10 | [diff] [blame] | 8666 | session_deps_.proxy_delegate = std::move(proxy_delegate); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8667 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8668 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8669 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8670 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 8671 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8672 | SpdySerializedFrame stream2_priority( |
| 8673 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8674 | |
| 8675 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8676 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8677 | CreateMockWrite(stream2_priority, 3, ASYNC), |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8678 | }; |
| 8679 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8680 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8681 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8682 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8683 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
Bence Béky | 096cf05 | 2017-08-08 23:55:33 | [diff] [blame] | 8684 | nullptr, 0, 2, 1, "http://www.example.org/foo.dat")); |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 8685 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8686 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8687 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8688 | SpdySerializedFrame stream2_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8689 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8690 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8691 | SpdySerializedFrame stream2_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8692 | |
| 8693 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8694 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 8695 | CreateMockRead(stream2_syn, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8696 | CreateMockRead(stream1_body, 4, ASYNC), |
| 8697 | CreateMockRead(stream2_body, 5, ASYNC), |
| 8698 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8699 | }; |
| 8700 | |
| 8701 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8702 | arraysize(spdy_writes)); |
| 8703 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 8704 | // Negotiate SPDY to the proxy |
| 8705 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8706 | proxy.next_proto = kProtoHTTP2; |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8707 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
| 8708 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8709 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8710 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8711 | TestCompletionCallback callback; |
| 8712 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8713 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8714 | |
| 8715 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8716 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8717 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8718 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8719 | ASSERT_TRUE(response); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8720 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8721 | |
| 8722 | EXPECT_EQ(200, response->headers->response_code()); |
| 8723 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8724 | |
| 8725 | std::string response_data; |
| 8726 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8727 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8728 | EXPECT_EQ("hello!", response_data); |
| 8729 | |
| 8730 | trans.reset(); |
| 8731 | session->CloseAllConnections(); |
| 8732 | } |
| 8733 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8734 | // Test HTTPS connections to a site with a bad certificate, going through an |
| 8735 | // HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8736 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8737 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8738 | |
| 8739 | HttpRequestInfo request; |
| 8740 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8741 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8742 | |
| 8743 | // Attempt to fetch the URL from a server with a bad cert |
| 8744 | MockWrite bad_cert_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8745 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8746 | "Host: www.example.org:443\r\n" |
| 8747 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8748 | }; |
| 8749 | |
| 8750 | MockRead bad_cert_reads[] = { |
| 8751 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8752 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8753 | }; |
| 8754 | |
| 8755 | // Attempt to fetch the URL with a good cert |
| 8756 | MockWrite good_data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8757 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8758 | "Host: www.example.org:443\r\n" |
| 8759 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 8760 | MockWrite("GET / HTTP/1.1\r\n" |
| 8761 | "Host: www.example.org\r\n" |
| 8762 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8763 | }; |
| 8764 | |
| 8765 | MockRead good_cert_reads[] = { |
| 8766 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 8767 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8768 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8769 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8770 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8771 | }; |
| 8772 | |
| 8773 | StaticSocketDataProvider ssl_bad_certificate( |
| 8774 | bad_cert_reads, arraysize(bad_cert_reads), |
| 8775 | bad_cert_writes, arraysize(bad_cert_writes)); |
| 8776 | StaticSocketDataProvider data(good_cert_reads, arraysize(good_cert_reads), |
| 8777 | good_data_writes, arraysize(good_data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8778 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 8779 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8780 | |
| 8781 | // SSL to the proxy, then CONNECT request, then SSL with bad certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8782 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 8783 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 8784 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8785 | |
| 8786 | // SSL to the proxy, then CONNECT request, then valid SSL certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8787 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 8788 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8789 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8790 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8791 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8792 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8793 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8794 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8795 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8796 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8797 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8798 | |
| 8799 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8800 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8801 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8802 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8803 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8804 | |
| 8805 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8806 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8807 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8808 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8809 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8810 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8811 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8812 | } |
| 8813 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8814 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8815 | HttpRequestInfo request; |
| 8816 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8817 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8818 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 8819 | "Chromium Ultra Awesome X Edition"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8820 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8821 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8822 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8823 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8824 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8825 | MockWrite( |
| 8826 | "GET / HTTP/1.1\r\n" |
| 8827 | "Host: www.example.org\r\n" |
| 8828 | "Connection: keep-alive\r\n" |
| 8829 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8830 | }; |
| 8831 | |
| 8832 | // Lastly, the server responds with the actual content. |
| 8833 | MockRead data_reads[] = { |
| 8834 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8835 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8836 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8837 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8838 | }; |
| 8839 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8840 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8841 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8842 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8843 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8844 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8845 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8846 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8847 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8848 | |
| 8849 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8850 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8851 | } |
| 8852 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8853 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8854 | HttpRequestInfo request; |
| 8855 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8856 | request.url = GURL("https://www.example.org/"); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8857 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 8858 | "Chromium Ultra Awesome X Edition"); |
| 8859 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8860 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8861 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8862 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8863 | |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8864 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8865 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8866 | "Host: www.example.org:443\r\n" |
| 8867 | "Proxy-Connection: keep-alive\r\n" |
| 8868 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8869 | }; |
| 8870 | MockRead data_reads[] = { |
| 8871 | // Return an error, so the transaction stops here (this test isn't |
| 8872 | // interested in the rest). |
| 8873 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 8874 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8875 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 8876 | }; |
| 8877 | |
| 8878 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8879 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8880 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8881 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8882 | TestCompletionCallback callback; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8883 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8884 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8885 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8886 | |
| 8887 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8888 | EXPECT_THAT(rv, IsOk()); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8889 | } |
| 8890 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8891 | TEST_F(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8892 | HttpRequestInfo request; |
| 8893 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8894 | request.url = GURL("http://www.example.org/"); |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 8895 | request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 8896 | "http://the.previous.site.com/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8897 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8898 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8899 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8900 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8901 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8902 | MockWrite( |
| 8903 | "GET / HTTP/1.1\r\n" |
| 8904 | "Host: www.example.org\r\n" |
| 8905 | "Connection: keep-alive\r\n" |
| 8906 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8907 | }; |
| 8908 | |
| 8909 | // Lastly, the server responds with the actual content. |
| 8910 | MockRead data_reads[] = { |
| 8911 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8912 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8913 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8914 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8915 | }; |
| 8916 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8917 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8918 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8919 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8920 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8921 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8922 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8923 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8924 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8925 | |
| 8926 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8927 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8928 | } |
| 8929 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8930 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8931 | HttpRequestInfo request; |
| 8932 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8933 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8934 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8935 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8936 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8937 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8938 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8939 | MockWrite( |
| 8940 | "POST / HTTP/1.1\r\n" |
| 8941 | "Host: www.example.org\r\n" |
| 8942 | "Connection: keep-alive\r\n" |
| 8943 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8944 | }; |
| 8945 | |
| 8946 | // Lastly, the server responds with the actual content. |
| 8947 | MockRead data_reads[] = { |
| 8948 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8949 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8950 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8951 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8952 | }; |
| 8953 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8954 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8955 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8956 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8957 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8958 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8959 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8960 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8961 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8962 | |
| 8963 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8964 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8965 | } |
| 8966 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8967 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8968 | HttpRequestInfo request; |
| 8969 | request.method = "PUT"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8970 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8971 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8972 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8973 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8974 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8975 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8976 | MockWrite( |
| 8977 | "PUT / HTTP/1.1\r\n" |
| 8978 | "Host: www.example.org\r\n" |
| 8979 | "Connection: keep-alive\r\n" |
| 8980 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8981 | }; |
| 8982 | |
| 8983 | // Lastly, the server responds with the actual content. |
| 8984 | MockRead data_reads[] = { |
| 8985 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8986 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8987 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8988 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8989 | }; |
| 8990 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8991 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8992 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8993 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8994 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8995 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8996 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8997 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8998 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8999 | |
| 9000 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9001 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9002 | } |
| 9003 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9004 | TEST_F(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9005 | HttpRequestInfo request; |
| 9006 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9007 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9008 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9009 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9010 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9011 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9012 | MockWrite data_writes[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 9013 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 9014 | "Host: www.example.org\r\n" |
| 9015 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9016 | }; |
| 9017 | |
| 9018 | // Lastly, the server responds with the actual content. |
| 9019 | MockRead data_reads[] = { |
| 9020 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9021 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9022 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9023 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9024 | }; |
| 9025 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9026 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9027 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9028 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9029 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9030 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9031 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9032 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9033 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9034 | |
| 9035 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9036 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9037 | } |
| 9038 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9039 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9040 | HttpRequestInfo request; |
| 9041 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9042 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9043 | request.load_flags = LOAD_BYPASS_CACHE; |
| 9044 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9045 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9046 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9047 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9048 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9049 | MockWrite( |
| 9050 | "GET / HTTP/1.1\r\n" |
| 9051 | "Host: www.example.org\r\n" |
| 9052 | "Connection: keep-alive\r\n" |
| 9053 | "Pragma: no-cache\r\n" |
| 9054 | "Cache-Control: no-cache\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9055 | }; |
| 9056 | |
| 9057 | // Lastly, the server responds with the actual content. |
| 9058 | MockRead data_reads[] = { |
| 9059 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9060 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9061 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9062 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9063 | }; |
| 9064 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9065 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9066 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9067 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9068 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9069 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9070 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9071 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9072 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9073 | |
| 9074 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9075 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9076 | } |
| 9077 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9078 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlValidateCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9079 | HttpRequestInfo request; |
| 9080 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9081 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9082 | request.load_flags = LOAD_VALIDATE_CACHE; |
| 9083 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9084 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9085 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9086 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9087 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9088 | MockWrite( |
| 9089 | "GET / HTTP/1.1\r\n" |
| 9090 | "Host: www.example.org\r\n" |
| 9091 | "Connection: keep-alive\r\n" |
| 9092 | "Cache-Control: max-age=0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9093 | }; |
| 9094 | |
| 9095 | // Lastly, the server responds with the actual content. |
| 9096 | MockRead data_reads[] = { |
| 9097 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9098 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9099 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9100 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9101 | }; |
| 9102 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9103 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9104 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9105 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9106 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9107 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9108 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9109 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9110 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9111 | |
| 9112 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9113 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9114 | } |
| 9115 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9116 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9117 | HttpRequestInfo request; |
| 9118 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9119 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 9120 | request.extra_headers.SetHeader("FooHeader", "Bar"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9121 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9122 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9123 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9124 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9125 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9126 | MockWrite( |
| 9127 | "GET / HTTP/1.1\r\n" |
| 9128 | "Host: www.example.org\r\n" |
| 9129 | "Connection: keep-alive\r\n" |
| 9130 | "FooHeader: Bar\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9131 | }; |
| 9132 | |
| 9133 | // Lastly, the server responds with the actual content. |
| 9134 | MockRead data_reads[] = { |
| 9135 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9136 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9137 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9138 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9139 | }; |
| 9140 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9141 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9142 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9143 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9144 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9145 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9146 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9147 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9148 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9149 | |
| 9150 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9151 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9152 | } |
| 9153 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9154 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9155 | HttpRequestInfo request; |
| 9156 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9157 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 9158 | request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 9159 | request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 9160 | request.extra_headers.SetHeader("FoO", "bar"); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9161 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9162 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9163 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9164 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9165 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9166 | MockWrite( |
| 9167 | "GET / HTTP/1.1\r\n" |
| 9168 | "Host: www.example.org\r\n" |
| 9169 | "Connection: keep-alive\r\n" |
| 9170 | "referer: www.foo.com\r\n" |
| 9171 | "hEllo: Kitty\r\n" |
| 9172 | "FoO: bar\r\n\r\n"), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9173 | }; |
| 9174 | |
| 9175 | // Lastly, the server responds with the actual content. |
| 9176 | MockRead data_reads[] = { |
| 9177 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9178 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9179 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9180 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9181 | }; |
| 9182 | |
| 9183 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9184 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9185 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9186 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9187 | TestCompletionCallback callback; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9188 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9189 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9190 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9191 | |
| 9192 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9193 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9194 | } |
| 9195 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9196 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9197 | HttpRequestInfo request; |
| 9198 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9199 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9200 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9201 | session_deps_.proxy_service = |
| 9202 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9203 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9204 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9205 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9206 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9207 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9208 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9209 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 9210 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 9211 | |
| 9212 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9213 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 9214 | MockWrite( |
| 9215 | "GET / HTTP/1.1\r\n" |
| 9216 | "Host: www.example.org\r\n" |
| 9217 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9218 | |
| 9219 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9220 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9221 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9222 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9223 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9224 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9225 | }; |
| 9226 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9227 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9228 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9229 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9230 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9231 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9232 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9233 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9234 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9235 | |
| 9236 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9237 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9238 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9239 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9240 | ASSERT_TRUE(response); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9241 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9242 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9243 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9244 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9245 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9246 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 9247 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9248 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9249 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9250 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9251 | EXPECT_EQ("Payload", response_text); |
| 9252 | } |
| 9253 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9254 | TEST_F(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9255 | HttpRequestInfo request; |
| 9256 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9257 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9258 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9259 | session_deps_.proxy_service = |
| 9260 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9261 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9262 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9263 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9264 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9265 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9266 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9267 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 9268 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 9269 | |
| 9270 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9271 | MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), |
| 9272 | arraysize(write_buffer)), |
| 9273 | MockWrite( |
| 9274 | "GET / HTTP/1.1\r\n" |
| 9275 | "Host: www.example.org\r\n" |
| 9276 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9277 | |
| 9278 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 9279 | MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), |
| 9280 | arraysize(read_buffer)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9281 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9282 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9283 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9284 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9285 | }; |
| 9286 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9287 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9288 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9289 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9290 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9291 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9292 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9293 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9294 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9295 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9296 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9297 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9298 | |
| 9299 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9300 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9301 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9302 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9303 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9304 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9305 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 9306 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9307 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9308 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9309 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9310 | |
| 9311 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9312 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9313 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9314 | EXPECT_EQ("Payload", response_text); |
| 9315 | } |
| 9316 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9317 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9318 | HttpRequestInfo request; |
| 9319 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9320 | request.url = GURL("http://www.example.org/"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9321 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9322 | session_deps_.proxy_service = |
| 9323 | ProxyService::CreateFixed("socks4://myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9324 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9325 | session_deps_.net_log = &net_log; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9326 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9327 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9328 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9329 | |
| 9330 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 9331 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 9332 | |
| 9333 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9334 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 9335 | MockWrite( |
| 9336 | "GET / HTTP/1.1\r\n" |
| 9337 | "Host: www.example.org\r\n" |
| 9338 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9339 | |
| 9340 | MockRead data_reads[] = { |
| 9341 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
| 9342 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9343 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9344 | MockRead("Payload"), |
| 9345 | MockRead(SYNCHRONOUS, OK) |
| 9346 | }; |
| 9347 | |
| 9348 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9349 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9350 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9351 | |
| 9352 | TestCompletionCallback callback; |
| 9353 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9354 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9355 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9356 | |
| 9357 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9358 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9359 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9360 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9361 | ASSERT_TRUE(response); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9362 | |
| 9363 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9364 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9365 | TestLoadTimingNotReused(load_timing_info, |
| 9366 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 9367 | |
| 9368 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9369 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9370 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9371 | EXPECT_EQ("Payload", response_text); |
| 9372 | } |
| 9373 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9374 | TEST_F(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9375 | HttpRequestInfo request; |
| 9376 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9377 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9378 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9379 | session_deps_.proxy_service = |
| 9380 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9381 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9382 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9383 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9384 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9385 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9386 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9387 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 9388 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9389 | const char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9390 | 0x05, // Version |
| 9391 | 0x01, // Command (CONNECT) |
| 9392 | 0x00, // Reserved. |
| 9393 | 0x03, // Address type (DOMAINNAME). |
| 9394 | 0x0F, // Length of domain (15) |
| 9395 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 9396 | '.', 'o', 'r', 'g', 0x00, 0x50, // 16-bit port (80) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9397 | }; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9398 | const char kSOCKS5OkResponse[] = |
| 9399 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 9400 | |
| 9401 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9402 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 9403 | MockWrite(ASYNC, kSOCKS5OkRequest, arraysize(kSOCKS5OkRequest)), |
| 9404 | MockWrite( |
| 9405 | "GET / HTTP/1.1\r\n" |
| 9406 | "Host: www.example.org\r\n" |
| 9407 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9408 | |
| 9409 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 9410 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 9411 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9412 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9413 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9414 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9415 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9416 | }; |
| 9417 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9418 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9419 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9420 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9421 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9422 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9423 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9424 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9425 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9426 | |
| 9427 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9428 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9429 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9430 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9431 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9432 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9433 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9434 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9435 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9436 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9437 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 9438 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9439 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9440 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9441 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9442 | EXPECT_EQ("Payload", response_text); |
| 9443 | } |
| 9444 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9445 | TEST_F(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9446 | HttpRequestInfo request; |
| 9447 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9448 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9449 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9450 | session_deps_.proxy_service = |
| 9451 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9452 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9453 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9454 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9455 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9456 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9457 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9458 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 9459 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9460 | const unsigned char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9461 | 0x05, // Version |
| 9462 | 0x01, // Command (CONNECT) |
| 9463 | 0x00, // Reserved. |
| 9464 | 0x03, // Address type (DOMAINNAME). |
| 9465 | 0x0F, // Length of domain (15) |
| 9466 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 9467 | '.', 'o', 'r', 'g', 0x01, 0xBB, // 16-bit port (443) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9468 | }; |
| 9469 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9470 | const char kSOCKS5OkResponse[] = |
| 9471 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 9472 | |
| 9473 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9474 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 9475 | MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
| 9476 | arraysize(kSOCKS5OkRequest)), |
| 9477 | MockWrite( |
| 9478 | "GET / HTTP/1.1\r\n" |
| 9479 | "Host: www.example.org\r\n" |
| 9480 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9481 | |
| 9482 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 9483 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 9484 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9485 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9486 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9487 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9488 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9489 | }; |
| 9490 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9491 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9492 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9493 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9494 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9495 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9496 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9497 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9498 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9499 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9500 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9501 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9502 | |
| 9503 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9504 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9505 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9506 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9507 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9508 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9509 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9510 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9511 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9512 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9513 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 9514 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9515 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9516 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9517 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9518 | EXPECT_EQ("Payload", response_text); |
| 9519 | } |
| 9520 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9521 | namespace { |
| 9522 | |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9523 | // Tests that for connection endpoints the group names are correctly set. |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9524 | |
| 9525 | struct GroupNameTest { |
| 9526 | std::string proxy_server; |
| 9527 | std::string url; |
| 9528 | std::string expected_group_name; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9529 | bool ssl; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9530 | }; |
| 9531 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9532 | std::unique_ptr<HttpNetworkSession> SetupSessionForGroupNameTests( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9533 | SpdySessionDependencies* session_deps_) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9534 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9535 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 9536 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9537 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 9538 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9539 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 9540 | http_server_properties->SetHttp2AlternativeService( |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9541 | url::SchemeHostPort("https", "host.with.alternate", 443), |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 9542 | alternative_service, expiration); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9543 | |
| 9544 | return session; |
| 9545 | } |
| 9546 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9547 | int GroupNameTransactionHelper(const std::string& url, |
| 9548 | HttpNetworkSession* session) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9549 | HttpRequestInfo request; |
| 9550 | request.method = "GET"; |
| 9551 | request.url = GURL(url); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9552 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9553 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9554 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9555 | TestCompletionCallback callback; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9556 | |
| 9557 | // We do not complete this request, the dtor will clean the transaction up. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9558 | return trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9559 | } |
| 9560 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9561 | } // namespace |
| 9562 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9563 | TEST_F(HttpNetworkTransactionTest, GroupNameForDirectConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9564 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9565 | { |
| 9566 | "", // unused |
| 9567 | "http://www.example.org/direct", |
| 9568 | "www.example.org:80", |
| 9569 | false, |
| 9570 | }, |
| 9571 | { |
| 9572 | "", // unused |
| 9573 | "http://[2001:1418:13:1::25]/direct", |
| 9574 | "[2001:1418:13:1::25]:80", |
| 9575 | false, |
| 9576 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9577 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9578 | // SSL Tests |
| 9579 | { |
| 9580 | "", // unused |
| 9581 | "https://www.example.org/direct_ssl", |
| 9582 | "ssl/www.example.org:443", |
| 9583 | true, |
| 9584 | }, |
| 9585 | { |
| 9586 | "", // unused |
| 9587 | "https://[2001:1418:13:1::25]/direct", |
| 9588 | "ssl/[2001:1418:13:1::25]:443", |
| 9589 | true, |
| 9590 | }, |
| 9591 | { |
| 9592 | "", // unused |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9593 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9594 | "ssl/host.with.alternate:443", |
| 9595 | true, |
| 9596 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9597 | }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9598 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 9599 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9600 | session_deps_.proxy_service = |
| 9601 | ProxyService::CreateFixed(tests[i].proxy_server); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9602 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 9603 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9604 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9605 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9606 | CaptureGroupNameTransportSocketPool* transport_conn_pool = |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9607 | new CaptureGroupNameTransportSocketPool(nullptr, nullptr); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9608 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9609 | new CaptureGroupNameSSLSocketPool(nullptr, nullptr); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9610 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 9611 | mock_pool_manager->SetTransportSocketPool(transport_conn_pool); |
| 9612 | mock_pool_manager->SetSSLSocketPool(ssl_conn_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 9613 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9614 | |
| 9615 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9616 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9617 | if (tests[i].ssl) |
| 9618 | EXPECT_EQ(tests[i].expected_group_name, |
| 9619 | ssl_conn_pool->last_group_name_received()); |
| 9620 | else |
| 9621 | EXPECT_EQ(tests[i].expected_group_name, |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9622 | transport_conn_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9623 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9624 | } |
| 9625 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9626 | TEST_F(HttpNetworkTransactionTest, GroupNameForHTTPProxyConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9627 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9628 | { |
| 9629 | "http_proxy", |
| 9630 | "http://www.example.org/http_proxy_normal", |
| 9631 | "www.example.org:80", |
| 9632 | false, |
| 9633 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9634 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9635 | // SSL Tests |
| 9636 | { |
| 9637 | "http_proxy", |
| 9638 | "https://www.example.org/http_connect_ssl", |
| 9639 | "ssl/www.example.org:443", |
| 9640 | true, |
| 9641 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 9642 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9643 | { |
| 9644 | "http_proxy", |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9645 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9646 | "ssl/host.with.alternate:443", |
| 9647 | true, |
| 9648 | }, |
[email protected] | 4549925 | 2013-01-23 17:12:56 | [diff] [blame] | 9649 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9650 | { |
| 9651 | "http_proxy", |
| 9652 | "ftp://ftp.google.com/http_proxy_normal", |
| 9653 | "ftp/ftp.google.com:21", |
| 9654 | false, |
| 9655 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9656 | }; |
| 9657 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 9658 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9659 | session_deps_.proxy_service = |
| 9660 | ProxyService::CreateFixed(tests[i].proxy_server); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9661 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 9662 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9663 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9664 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9665 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9666 | HostPortPair proxy_host("http_proxy", 80); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9667 | CaptureGroupNameHttpProxySocketPool* http_proxy_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9668 | new CaptureGroupNameHttpProxySocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9669 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9670 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9671 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
avi | adef344 | 2016-10-03 18:50:39 | [diff] [blame] | 9672 | mock_pool_manager->SetSocketPoolForHTTPProxy( |
| 9673 | proxy_host, base::WrapUnique(http_proxy_pool)); |
| 9674 | mock_pool_manager->SetSocketPoolForSSLWithProxy( |
| 9675 | proxy_host, base::WrapUnique(ssl_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 9676 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9677 | |
| 9678 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9679 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9680 | if (tests[i].ssl) |
| 9681 | EXPECT_EQ(tests[i].expected_group_name, |
| 9682 | ssl_conn_pool->last_group_name_received()); |
| 9683 | else |
| 9684 | EXPECT_EQ(tests[i].expected_group_name, |
| 9685 | http_proxy_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9686 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9687 | } |
| 9688 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9689 | TEST_F(HttpNetworkTransactionTest, GroupNameForSOCKSConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9690 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9691 | { |
| 9692 | "socks4://socks_proxy:1080", |
| 9693 | "http://www.example.org/socks4_direct", |
| 9694 | "socks4/www.example.org:80", |
| 9695 | false, |
| 9696 | }, |
| 9697 | { |
| 9698 | "socks5://socks_proxy:1080", |
| 9699 | "http://www.example.org/socks5_direct", |
| 9700 | "socks5/www.example.org:80", |
| 9701 | false, |
| 9702 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9703 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9704 | // SSL Tests |
| 9705 | { |
| 9706 | "socks4://socks_proxy:1080", |
| 9707 | "https://www.example.org/socks4_ssl", |
| 9708 | "socks4/ssl/www.example.org:443", |
| 9709 | true, |
| 9710 | }, |
| 9711 | { |
| 9712 | "socks5://socks_proxy:1080", |
| 9713 | "https://www.example.org/socks5_ssl", |
| 9714 | "socks5/ssl/www.example.org:443", |
| 9715 | true, |
| 9716 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 9717 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9718 | { |
| 9719 | "socks4://socks_proxy:1080", |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9720 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9721 | "socks4/ssl/host.with.alternate:443", |
| 9722 | true, |
| 9723 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9724 | }; |
| 9725 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 9726 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9727 | session_deps_.proxy_service = |
| 9728 | ProxyService::CreateFixed(tests[i].proxy_server); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9729 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 9730 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 9731 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9732 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9733 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9734 | HostPortPair proxy_host("socks_proxy", 1080); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9735 | CaptureGroupNameSOCKSSocketPool* socks_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9736 | new CaptureGroupNameSOCKSSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9737 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9738 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9739 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
avi | adef344 | 2016-10-03 18:50:39 | [diff] [blame] | 9740 | mock_pool_manager->SetSocketPoolForSOCKSProxy( |
| 9741 | proxy_host, base::WrapUnique(socks_conn_pool)); |
| 9742 | mock_pool_manager->SetSocketPoolForSSLWithProxy( |
| 9743 | proxy_host, base::WrapUnique(ssl_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 9744 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9745 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9746 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9747 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9748 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9749 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9750 | if (tests[i].ssl) |
| 9751 | EXPECT_EQ(tests[i].expected_group_name, |
| 9752 | ssl_conn_pool->last_group_name_received()); |
| 9753 | else |
| 9754 | EXPECT_EQ(tests[i].expected_group_name, |
| 9755 | socks_conn_pool->last_group_name_received()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9756 | } |
| 9757 | } |
| 9758 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9759 | TEST_F(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9760 | HttpRequestInfo request; |
| 9761 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9762 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9763 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9764 | session_deps_.proxy_service = |
| 9765 | ProxyService::CreateFixed("myproxy:70;foobar:80"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 9766 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 9767 | // This simulates failure resolving all hostnames; that means we will fail |
| 9768 | // connecting to both proxies (myproxy:70 and foobar:80). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9769 | session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 9770 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9771 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9772 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9773 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9774 | TestCompletionCallback callback; |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9775 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9776 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9777 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9778 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9779 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9780 | EXPECT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9781 | } |
| 9782 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9783 | // Base test to make sure that when the load flags for a request specify to |
| 9784 | // bypass the cache, the DNS cache is not used. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9785 | void HttpNetworkTransactionTest::BypassHostCacheOnRefreshHelper( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9786 | int load_flags) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9787 | // Issue a request, asking to bypass the cache(s). |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9788 | HttpRequestInfo request_info; |
| 9789 | request_info.method = "GET"; |
| 9790 | request_info.load_flags = load_flags; |
| 9791 | request_info.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9792 | |
[email protected] | a2c2fb9 | 2009-07-18 07:31:04 | [diff] [blame] | 9793 | // Select a host resolver that does caching. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9794 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 9795 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9796 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9797 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9798 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9799 | // 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] | 9800 | AddressList addrlist; |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 9801 | TestCompletionCallback callback; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9802 | std::unique_ptr<HostResolver::Request> request1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9803 | int rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9804 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9805 | DEFAULT_PRIORITY, &addrlist, callback.callback(), &request1, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9806 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9807 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 9808 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9809 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9810 | |
| 9811 | // Verify that it was added to host cache, by doing a subsequent async lookup |
| 9812 | // and confirming it completes synchronously. |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9813 | std::unique_ptr<HostResolver::Request> request2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9814 | rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9815 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9816 | DEFAULT_PRIORITY, &addrlist, callback.callback(), &request2, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9817 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9818 | ASSERT_THAT(rv, IsOk()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9819 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9820 | // 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] | 9821 | // we can tell if the next lookup hit the cache, or the "network". |
| 9822 | // (cache --> success, "network" --> failure). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9823 | session_deps_.host_resolver->rules()->AddSimulatedFailure("www.example.org"); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9824 | |
| 9825 | // Connect up a mock socket which will fail with ERR_UNEXPECTED during the |
| 9826 | // 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] | 9827 | MockRead data_reads[] = { MockRead(SYNCHRONOUS, ERR_UNEXPECTED) }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9828 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9829 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9830 | |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9831 | // Run the request. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9832 | rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9833 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9834 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9835 | |
| 9836 | // If we bypassed the cache, we would have gotten a failure while resolving |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9837 | // "www.example.org". |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9838 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9839 | } |
| 9840 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9841 | // There are multiple load flags that should trigger the host cache bypass. |
| 9842 | // Test each in isolation: |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9843 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh1) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9844 | BypassHostCacheOnRefreshHelper(LOAD_BYPASS_CACHE); |
| 9845 | } |
| 9846 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9847 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh2) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9848 | BypassHostCacheOnRefreshHelper(LOAD_VALIDATE_CACHE); |
| 9849 | } |
| 9850 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9851 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh3) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9852 | BypassHostCacheOnRefreshHelper(LOAD_DISABLE_CACHE); |
| 9853 | } |
| 9854 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9855 | // Make sure we can handle an error when writing the request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9856 | TEST_F(HttpNetworkTransactionTest, RequestWriteError) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9857 | HttpRequestInfo request; |
| 9858 | request.method = "GET"; |
| 9859 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9860 | |
| 9861 | MockWrite write_failure[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9862 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9863 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9864 | StaticSocketDataProvider data(NULL, 0, |
| 9865 | write_failure, arraysize(write_failure)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9866 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9867 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9868 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9869 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9870 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9871 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9872 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9873 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9874 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9875 | |
| 9876 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9877 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9878 | |
| 9879 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9880 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9881 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9882 | } |
| 9883 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9884 | // Check that a connection closed after the start of the headers finishes ok. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9885 | TEST_F(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9886 | HttpRequestInfo request; |
| 9887 | request.method = "GET"; |
| 9888 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9889 | |
| 9890 | MockRead data_reads[] = { |
| 9891 | MockRead("HTTP/1."), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9892 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9893 | }; |
| 9894 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9895 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9896 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9897 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9898 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9899 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9900 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9901 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9902 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9903 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9904 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9905 | |
| 9906 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9907 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9908 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9909 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9910 | ASSERT_TRUE(response); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9911 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9912 | EXPECT_TRUE(response->headers); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9913 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 9914 | |
| 9915 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9916 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9917 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9918 | EXPECT_EQ("", response_data); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9919 | |
| 9920 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9921 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9922 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9923 | } |
| 9924 | |
| 9925 | // Make sure that a dropped connection while draining the body for auth |
| 9926 | // restart does the right thing. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9927 | TEST_F(HttpNetworkTransactionTest, DrainResetOK) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9928 | HttpRequestInfo request; |
| 9929 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9930 | request.url = GURL("http://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9931 | |
| 9932 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9933 | MockWrite( |
| 9934 | "GET / HTTP/1.1\r\n" |
| 9935 | "Host: www.example.org\r\n" |
| 9936 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9937 | }; |
| 9938 | |
| 9939 | MockRead data_reads1[] = { |
| 9940 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 9941 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9942 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9943 | MockRead("Content-Length: 14\r\n\r\n"), |
| 9944 | MockRead("Unauth"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9945 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9946 | }; |
| 9947 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9948 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 9949 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9950 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9951 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9952 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9953 | // be issuing -- the final header line contains the credentials. |
| 9954 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9955 | MockWrite( |
| 9956 | "GET / HTTP/1.1\r\n" |
| 9957 | "Host: www.example.org\r\n" |
| 9958 | "Connection: keep-alive\r\n" |
| 9959 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9960 | }; |
| 9961 | |
| 9962 | // Lastly, the server responds with the actual content. |
| 9963 | MockRead data_reads2[] = { |
| 9964 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9965 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9966 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9967 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9968 | }; |
| 9969 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9970 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 9971 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9972 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9973 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9974 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9975 | TestCompletionCallback callback1; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9976 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9977 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9978 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9979 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9980 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9981 | |
| 9982 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9983 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9984 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9985 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9986 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9987 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9988 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9989 | TestCompletionCallback callback2; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9990 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9991 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9992 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9993 | |
| 9994 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9995 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9996 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9997 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9998 | ASSERT_TRUE(response); |
| 9999 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10000 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 10001 | } |
| 10002 | |
| 10003 | // Test HTTPS connections going through a proxy that sends extra data. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10004 | TEST_F(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 10005 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10006 | |
| 10007 | HttpRequestInfo request; |
| 10008 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10009 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10010 | |
| 10011 | MockRead proxy_reads[] = { |
| 10012 | MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10013 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10014 | }; |
| 10015 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10016 | StaticSocketDataProvider data(proxy_reads, arraysize(proxy_reads), NULL, 0); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10017 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10018 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10019 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10020 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10021 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10022 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10023 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10024 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10025 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10026 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10027 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10028 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10029 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10030 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10031 | |
| 10032 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10033 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10034 | } |
| 10035 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10036 | TEST_F(HttpNetworkTransactionTest, LargeContentLengthThenClose) { |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10037 | HttpRequestInfo request; |
| 10038 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10039 | request.url = GURL("http://www.example.org/"); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10040 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10041 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10042 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10043 | |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 10044 | MockRead data_reads[] = { |
| 10045 | 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] | 10046 | MockRead(SYNCHRONOUS, OK), |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 10047 | }; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10048 | |
| 10049 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10050 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10051 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10052 | TestCompletionCallback callback; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10053 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10054 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10055 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10056 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10057 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10058 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10059 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10060 | ASSERT_TRUE(response); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10061 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10062 | EXPECT_TRUE(response->headers); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10063 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 10064 | |
| 10065 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10066 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10067 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 10068 | } |
| 10069 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10070 | TEST_F(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 10071 | base::FilePath temp_file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 10072 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path)); |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 10073 | const uint64_t kFakeSize = 100000; // file is actually blank |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 10074 | UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 10075 | overriding_content_length(kFakeSize); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10076 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10077 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10078 | element_readers.push_back(std::make_unique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 10079 | base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 10080 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 10081 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10082 | |
| 10083 | HttpRequestInfo request; |
| 10084 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10085 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10086 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10087 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10088 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10089 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10090 | |
| 10091 | MockRead data_reads[] = { |
| 10092 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 10093 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10094 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10095 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10096 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10097 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10098 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10099 | TestCompletionCallback callback; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10100 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10101 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10102 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10103 | |
| 10104 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10105 | EXPECT_THAT(rv, IsError(ERR_UPLOAD_FILE_CHANGED)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10106 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10107 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10108 | ASSERT_TRUE(response); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10109 | |
maksim.sisov | e869bf5 | 2016-06-23 17:11:52 | [diff] [blame] | 10110 | EXPECT_FALSE(response->headers); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10111 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 10112 | base::DeleteFile(temp_file_path, false); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10113 | } |
| 10114 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10115 | TEST_F(HttpNetworkTransactionTest, UploadUnreadableFile) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 10116 | base::FilePath temp_file; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 10117 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10118 | std::string temp_file_content("Unreadable file."); |
lazyboy | 8df84fc | 2017-04-12 02:12:48 | [diff] [blame] | 10119 | ASSERT_EQ(static_cast<int>(temp_file_content.length()), |
| 10120 | base::WriteFile(temp_file, temp_file_content.c_str(), |
| 10121 | temp_file_content.length())); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 10122 | ASSERT_TRUE(base::MakeFileUnreadable(temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10123 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10124 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10125 | element_readers.push_back(std::make_unique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 10126 | base::ThreadTaskRunnerHandle::Get().get(), temp_file, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 10127 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 10128 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10129 | |
| 10130 | HttpRequestInfo request; |
| 10131 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10132 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10133 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10134 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 10135 | // If we try to upload an unreadable file, the transaction should fail. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10136 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10137 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10138 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 10139 | StaticSocketDataProvider data(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10140 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10141 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10142 | TestCompletionCallback callback; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10143 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10144 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10145 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10146 | |
| 10147 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10148 | EXPECT_THAT(rv, IsError(ERR_ACCESS_DENIED)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10149 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 10150 | base::DeleteFile(temp_file, false); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10151 | } |
| 10152 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10153 | TEST_F(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10154 | class FakeUploadElementReader : public UploadElementReader { |
| 10155 | public: |
| 10156 | FakeUploadElementReader() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10157 | ~FakeUploadElementReader() override {} |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10158 | |
| 10159 | const CompletionCallback& callback() const { return callback_; } |
| 10160 | |
| 10161 | // UploadElementReader overrides: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10162 | int Init(const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10163 | callback_ = callback; |
| 10164 | return ERR_IO_PENDING; |
| 10165 | } |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 10166 | uint64_t GetContentLength() const override { return 0; } |
| 10167 | uint64_t BytesRemaining() const override { return 0; } |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10168 | int Read(IOBuffer* buf, |
| 10169 | int buf_length, |
| 10170 | const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10171 | return ERR_FAILED; |
| 10172 | } |
| 10173 | |
| 10174 | private: |
| 10175 | CompletionCallback callback_; |
| 10176 | }; |
| 10177 | |
| 10178 | FakeUploadElementReader* fake_reader = new FakeUploadElementReader; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10179 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
| 10180 | element_readers.push_back(base::WrapUnique(fake_reader)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 10181 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10182 | |
| 10183 | HttpRequestInfo request; |
| 10184 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10185 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10186 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10187 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10188 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10189 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10190 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10191 | |
| 10192 | StaticSocketDataProvider data; |
| 10193 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10194 | |
| 10195 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10196 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10197 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 10198 | base::RunLoop().RunUntilIdle(); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10199 | |
| 10200 | // Transaction is pending on request body initialization. |
| 10201 | ASSERT_FALSE(fake_reader->callback().is_null()); |
| 10202 | |
| 10203 | // Return Init()'s result after the transaction gets destroyed. |
| 10204 | trans.reset(); |
| 10205 | fake_reader->callback().Run(OK); // Should not crash. |
| 10206 | } |
| 10207 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10208 | // Tests that changes to Auth realms are treated like auth rejections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10209 | TEST_F(HttpNetworkTransactionTest, ChangeAuthRealms) { |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10210 | HttpRequestInfo request; |
| 10211 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10212 | request.url = GURL("http://www.example.org/"); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10213 | |
| 10214 | // First transaction will request a resource and receive a Basic challenge |
| 10215 | // with realm="first_realm". |
| 10216 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10217 | MockWrite( |
| 10218 | "GET / HTTP/1.1\r\n" |
| 10219 | "Host: www.example.org\r\n" |
| 10220 | "Connection: keep-alive\r\n" |
| 10221 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10222 | }; |
| 10223 | MockRead data_reads1[] = { |
| 10224 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 10225 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 10226 | "\r\n"), |
| 10227 | }; |
| 10228 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10229 | // After calling trans.RestartWithAuth(), provide an Authentication header |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10230 | // for first_realm. The server will reject and provide a challenge with |
| 10231 | // second_realm. |
| 10232 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10233 | MockWrite( |
| 10234 | "GET / HTTP/1.1\r\n" |
| 10235 | "Host: www.example.org\r\n" |
| 10236 | "Connection: keep-alive\r\n" |
| 10237 | "Authorization: Basic Zmlyc3Q6YmF6\r\n" |
| 10238 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10239 | }; |
| 10240 | MockRead data_reads2[] = { |
| 10241 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 10242 | "WWW-Authenticate: Basic realm=\"second_realm\"\r\n" |
| 10243 | "\r\n"), |
| 10244 | }; |
| 10245 | |
| 10246 | // This again fails, and goes back to first_realm. Make sure that the |
| 10247 | // entry is removed from cache. |
| 10248 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10249 | MockWrite( |
| 10250 | "GET / HTTP/1.1\r\n" |
| 10251 | "Host: www.example.org\r\n" |
| 10252 | "Connection: keep-alive\r\n" |
| 10253 | "Authorization: Basic c2Vjb25kOmZvdQ==\r\n" |
| 10254 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10255 | }; |
| 10256 | MockRead data_reads3[] = { |
| 10257 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 10258 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 10259 | "\r\n"), |
| 10260 | }; |
| 10261 | |
| 10262 | // Try one last time (with the correct password) and get the resource. |
| 10263 | MockWrite data_writes4[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10264 | MockWrite( |
| 10265 | "GET / HTTP/1.1\r\n" |
| 10266 | "Host: www.example.org\r\n" |
| 10267 | "Connection: keep-alive\r\n" |
| 10268 | "Authorization: Basic Zmlyc3Q6YmFy\r\n" |
| 10269 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10270 | }; |
| 10271 | MockRead data_reads4[] = { |
| 10272 | MockRead("HTTP/1.1 200 OK\r\n" |
| 10273 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10274 | "Content-Length: 5\r\n" |
| 10275 | "\r\n" |
| 10276 | "hello"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10277 | }; |
| 10278 | |
| 10279 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 10280 | data_writes1, arraysize(data_writes1)); |
| 10281 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 10282 | data_writes2, arraysize(data_writes2)); |
| 10283 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 10284 | data_writes3, arraysize(data_writes3)); |
| 10285 | StaticSocketDataProvider data4(data_reads4, arraysize(data_reads4), |
| 10286 | data_writes4, arraysize(data_writes4)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10287 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 10288 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 10289 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 10290 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10291 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10292 | TestCompletionCallback callback1; |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10293 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10294 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10295 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10296 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10297 | // Issue the first request with Authorize headers. There should be a |
| 10298 | // password prompt for first_realm waiting to be filled in after the |
| 10299 | // transaction completes. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10300 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10301 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10302 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10303 | EXPECT_THAT(rv, IsOk()); |
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 | const AuthChallengeInfo* challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10307 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10308 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10309 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10310 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 10311 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10312 | |
| 10313 | // Issue the second request with an incorrect password. There should be a |
| 10314 | // password prompt for second_realm waiting to be filled in after the |
| 10315 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10316 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10317 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBaz), |
| 10318 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10319 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10320 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10321 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10322 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10323 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10324 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10325 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10326 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10327 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10328 | EXPECT_EQ("second_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 10329 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10330 | |
| 10331 | // Issue the third request with another incorrect password. There should be |
| 10332 | // a password prompt for first_realm waiting to be filled in. If the password |
| 10333 | // prompt is not present, it indicates that the HttpAuthCacheEntry for |
| 10334 | // first_realm was not correctly removed. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10335 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10336 | rv = trans.RestartWithAuth(AuthCredentials(kSecond, kFou), |
| 10337 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10338 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10339 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10340 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10341 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10342 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10343 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10344 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10345 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10346 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10347 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 10348 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10349 | |
| 10350 | // Issue the fourth request with the correct password and username. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10351 | TestCompletionCallback callback4; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10352 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBar), |
| 10353 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10354 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10355 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10356 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10357 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10358 | ASSERT_TRUE(response); |
| 10359 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10360 | } |
| 10361 | |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 10362 | // Regression test for https://crbug.com/754395. |
| 10363 | TEST_F(HttpNetworkTransactionTest, IgnoreAltSvcWithInvalidCert) { |
| 10364 | MockRead data_reads[] = { |
| 10365 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10366 | MockRead(kAlternativeServiceHttpHeader), |
| 10367 | MockRead("\r\n"), |
| 10368 | MockRead("hello world"), |
| 10369 | MockRead(SYNCHRONOUS, OK), |
| 10370 | }; |
| 10371 | |
| 10372 | HttpRequestInfo request; |
| 10373 | request.method = "GET"; |
| 10374 | request.url = GURL("https://www.example.org/"); |
| 10375 | |
| 10376 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 10377 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10378 | |
| 10379 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10380 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 10381 | ASSERT_TRUE(ssl.cert); |
| 10382 | ssl.cert_status = CERT_STATUS_COMMON_NAME_INVALID; |
| 10383 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10384 | |
| 10385 | TestCompletionCallback callback; |
| 10386 | |
| 10387 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10388 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 10389 | |
| 10390 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 10391 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10392 | |
| 10393 | url::SchemeHostPort test_server(request.url); |
| 10394 | HttpServerProperties* http_server_properties = |
| 10395 | session->http_server_properties(); |
| 10396 | EXPECT_TRUE( |
| 10397 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
| 10398 | |
| 10399 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 10400 | |
| 10401 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 10402 | ASSERT_TRUE(response); |
| 10403 | ASSERT_TRUE(response->headers); |
| 10404 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10405 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 10406 | EXPECT_FALSE(response->was_alpn_negotiated); |
| 10407 | |
| 10408 | std::string response_data; |
| 10409 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 10410 | EXPECT_EQ("hello world", response_data); |
| 10411 | |
| 10412 | EXPECT_TRUE( |
| 10413 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
| 10414 | } |
| 10415 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10416 | TEST_F(HttpNetworkTransactionTest, HonorAlternativeServiceHeader) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10417 | MockRead data_reads[] = { |
| 10418 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10419 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10420 | MockRead("\r\n"), |
| 10421 | MockRead("hello world"), |
| 10422 | MockRead(SYNCHRONOUS, OK), |
| 10423 | }; |
| 10424 | |
| 10425 | HttpRequestInfo request; |
| 10426 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10427 | request.url = GURL("https://www.example.org/"); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10428 | |
| 10429 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10430 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10431 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10432 | SSLSocketDataProvider ssl(ASYNC, OK); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 10433 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 10434 | ASSERT_TRUE(ssl.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10435 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10436 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10437 | TestCompletionCallback callback; |
| 10438 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10439 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10440 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10441 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10442 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10443 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10444 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10445 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10446 | HttpServerProperties* http_server_properties = |
| 10447 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10448 | EXPECT_TRUE( |
| 10449 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10450 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10451 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10452 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10453 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10454 | ASSERT_TRUE(response); |
| 10455 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10456 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10457 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10458 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10459 | |
| 10460 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10461 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10462 | EXPECT_EQ("hello world", response_data); |
| 10463 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10464 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 10465 | http_server_properties->GetAlternativeServiceInfos(test_server); |
| 10466 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 10467 | AlternativeService alternative_service(kProtoHTTP2, "mail.example.org", 443); |
| 10468 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 10469 | alternative_service_info_vector[0].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10470 | } |
| 10471 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10472 | // Regression test for https://crbug.com/615497. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10473 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10474 | DoNotParseAlternativeServiceHeaderOnInsecureRequest) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10475 | MockRead data_reads[] = { |
| 10476 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10477 | MockRead(kAlternativeServiceHttpHeader), |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10478 | MockRead("\r\n"), |
| 10479 | MockRead("hello world"), |
| 10480 | MockRead(SYNCHRONOUS, OK), |
| 10481 | }; |
| 10482 | |
| 10483 | HttpRequestInfo request; |
| 10484 | request.method = "GET"; |
| 10485 | request.url = GURL("http://www.example.org/"); |
| 10486 | request.load_flags = 0; |
| 10487 | |
| 10488 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 10489 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10490 | |
| 10491 | TestCompletionCallback callback; |
| 10492 | |
| 10493 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10494 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10495 | |
| 10496 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10497 | HttpServerProperties* http_server_properties = |
| 10498 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10499 | EXPECT_TRUE( |
| 10500 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10501 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10502 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10503 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10504 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10505 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10506 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10507 | ASSERT_TRUE(response); |
| 10508 | ASSERT_TRUE(response->headers); |
| 10509 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10510 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10511 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10512 | |
| 10513 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10514 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10515 | EXPECT_EQ("hello world", response_data); |
| 10516 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10517 | EXPECT_TRUE( |
| 10518 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10519 | } |
| 10520 | |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 10521 | // HTTP/2 Alternative Services should be disabled by default. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10522 | // TODO(bnc): Remove when https://crbug.com/615413 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10523 | TEST_F(HttpNetworkTransactionTest, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10524 | DisableHTTP2AlternativeServicesWithDifferentHost) { |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 10525 | session_deps_.enable_http2_alternative_service = false; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10526 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10527 | HttpRequestInfo request; |
| 10528 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10529 | request.url = GURL("https://www.example.org/"); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10530 | request.load_flags = 0; |
| 10531 | |
| 10532 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10533 | StaticSocketDataProvider first_data; |
| 10534 | first_data.set_connect_data(mock_connect); |
| 10535 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10536 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10537 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10538 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10539 | |
| 10540 | MockRead data_reads[] = { |
| 10541 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 10542 | MockRead(ASYNC, OK), |
| 10543 | }; |
| 10544 | StaticSocketDataProvider second_data(data_reads, arraysize(data_reads), NULL, |
| 10545 | 0); |
| 10546 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 10547 | |
| 10548 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10549 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10550 | HttpServerProperties* http_server_properties = |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10551 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10552 | AlternativeService alternative_service(kProtoHTTP2, "different.example.org", |
| 10553 | 444); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10554 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10555 | http_server_properties->SetHttp2AlternativeService( |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10556 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 10557 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10558 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10559 | TestCompletionCallback callback; |
| 10560 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10561 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10562 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10563 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10564 | } |
| 10565 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10566 | // Regression test for https://crbug.com/615497: |
| 10567 | // Alternative Services should be disabled for http origin. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10568 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10569 | DisableAlternativeServicesForInsecureOrigin) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10570 | HttpRequestInfo request; |
| 10571 | request.method = "GET"; |
| 10572 | request.url = GURL("http://www.example.org/"); |
| 10573 | request.load_flags = 0; |
| 10574 | |
| 10575 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10576 | StaticSocketDataProvider first_data; |
| 10577 | first_data.set_connect_data(mock_connect); |
| 10578 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
| 10579 | |
| 10580 | MockRead data_reads[] = { |
| 10581 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 10582 | MockRead(ASYNC, OK), |
| 10583 | }; |
| 10584 | StaticSocketDataProvider second_data(data_reads, arraysize(data_reads), NULL, |
| 10585 | 0); |
| 10586 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 10587 | |
| 10588 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10589 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10590 | HttpServerProperties* http_server_properties = |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10591 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10592 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10593 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10594 | http_server_properties->SetHttp2AlternativeService( |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10595 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 10596 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10597 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10598 | TestCompletionCallback callback; |
| 10599 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10600 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10601 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10602 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10603 | } |
| 10604 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10605 | TEST_F(HttpNetworkTransactionTest, ClearAlternativeServices) { |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10606 | // Set an alternative service for origin. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10607 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10608 | HttpServerProperties* http_server_properties = |
| 10609 | session->http_server_properties(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10610 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10611 | AlternativeService alternative_service(kProtoQUIC, "", 80); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10612 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10613 | http_server_properties->SetQuicAlternativeService( |
| 10614 | test_server, alternative_service, expiration, |
| 10615 | session->params().quic_supported_versions); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10616 | EXPECT_EQ( |
| 10617 | 1u, |
| 10618 | http_server_properties->GetAlternativeServiceInfos(test_server).size()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10619 | |
| 10620 | // Send a clear header. |
| 10621 | MockRead data_reads[] = { |
| 10622 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10623 | MockRead("Alt-Svc: clear\r\n"), |
| 10624 | MockRead("\r\n"), |
| 10625 | MockRead("hello world"), |
| 10626 | MockRead(SYNCHRONOUS, OK), |
| 10627 | }; |
| 10628 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 10629 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10630 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10631 | SSLSocketDataProvider ssl(ASYNC, OK); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 10632 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 10633 | ASSERT_TRUE(ssl.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10634 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10635 | |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10636 | HttpRequestInfo request; |
| 10637 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10638 | request.url = GURL("https://www.example.org/"); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10639 | |
| 10640 | TestCompletionCallback callback; |
| 10641 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10642 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10643 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10644 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10645 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10646 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10647 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10648 | ASSERT_TRUE(response); |
| 10649 | ASSERT_TRUE(response->headers); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10650 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10651 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10652 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10653 | |
| 10654 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10655 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10656 | EXPECT_EQ("hello world", response_data); |
| 10657 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10658 | EXPECT_TRUE( |
| 10659 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10660 | } |
| 10661 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10662 | TEST_F(HttpNetworkTransactionTest, HonorMultipleAlternativeServiceHeaders) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10663 | MockRead data_reads[] = { |
| 10664 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10665 | MockRead("Alt-Svc: h2=\"www.example.com:443\","), |
| 10666 | MockRead("h2=\":1234\"\r\n\r\n"), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10667 | MockRead("hello world"), |
| 10668 | MockRead(SYNCHRONOUS, OK), |
| 10669 | }; |
| 10670 | |
| 10671 | HttpRequestInfo request; |
| 10672 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10673 | request.url = GURL("https://www.example.org/"); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10674 | |
| 10675 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10676 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10677 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10678 | SSLSocketDataProvider ssl(ASYNC, OK); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 10679 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 10680 | ASSERT_TRUE(ssl.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10681 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10682 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10683 | TestCompletionCallback callback; |
| 10684 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10685 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10686 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10687 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10688 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10689 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10690 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10691 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10692 | HttpServerProperties* http_server_properties = |
| 10693 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10694 | EXPECT_TRUE( |
| 10695 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10696 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10697 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10698 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10699 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10700 | ASSERT_TRUE(response); |
| 10701 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10702 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10703 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10704 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10705 | |
| 10706 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10707 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10708 | EXPECT_EQ("hello world", response_data); |
| 10709 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10710 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 10711 | http_server_properties->GetAlternativeServiceInfos(test_server); |
| 10712 | ASSERT_EQ(2u, alternative_service_info_vector.size()); |
| 10713 | |
| 10714 | AlternativeService alternative_service(kProtoHTTP2, "www.example.com", 443); |
| 10715 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 10716 | alternative_service_info_vector[0].alternative_service()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10717 | AlternativeService alternative_service_2(kProtoHTTP2, "www.example.org", |
| 10718 | 1234); |
| 10719 | EXPECT_EQ(alternative_service_2, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 10720 | alternative_service_info_vector[1].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10721 | } |
| 10722 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10723 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10724 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10725 | HostPortPair alternative("alternative.example.org", 443); |
| 10726 | std::string origin_url = "https://origin.example.org:443"; |
| 10727 | std::string alternative_url = "https://alternative.example.org:443"; |
| 10728 | |
| 10729 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 10730 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10731 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10732 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10733 | |
| 10734 | // HTTP/1.1 data for request. |
| 10735 | MockWrite http_writes[] = { |
| 10736 | MockWrite("GET / HTTP/1.1\r\n" |
| 10737 | "Host: alternative.example.org\r\n" |
| 10738 | "Connection: keep-alive\r\n\r\n"), |
| 10739 | }; |
| 10740 | |
| 10741 | MockRead http_reads[] = { |
| 10742 | MockRead("HTTP/1.1 200 OK\r\n" |
| 10743 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10744 | "Content-Length: 40\r\n\r\n" |
| 10745 | "first HTTP/1.1 response from alternative"), |
| 10746 | }; |
| 10747 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 10748 | http_writes, arraysize(http_writes)); |
| 10749 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 10750 | |
| 10751 | StaticSocketDataProvider data_refused; |
| 10752 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 10753 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 10754 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10755 | // Set up a QUIC alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10756 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10757 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10758 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10759 | AlternativeService alternative_service(kProtoQUIC, alternative); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10760 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10761 | http_server_properties->SetQuicAlternativeService( |
| 10762 | server, alternative_service, expiration, |
| 10763 | HttpNetworkSession::Params().quic_supported_versions); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10764 | // Mark the QUIC alternative service as broken. |
| 10765 | http_server_properties->MarkAlternativeServiceBroken(alternative_service); |
| 10766 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10767 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 10768 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10769 | request.method = "GET"; |
| 10770 | request.url = GURL(origin_url); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10771 | TestCompletionCallback callback; |
| 10772 | NetErrorDetails details; |
| 10773 | EXPECT_FALSE(details.quic_broken); |
| 10774 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10775 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10776 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10777 | EXPECT_TRUE(details.quic_broken); |
| 10778 | } |
| 10779 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10780 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicNotBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10781 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10782 | HostPortPair alternative1("alternative1.example.org", 443); |
| 10783 | HostPortPair alternative2("alternative2.example.org", 443); |
| 10784 | std::string origin_url = "https://origin.example.org:443"; |
| 10785 | std::string alternative_url1 = "https://alternative1.example.org:443"; |
| 10786 | std::string alternative_url2 = "https://alternative2.example.org:443"; |
| 10787 | |
| 10788 | // Negotiate HTTP/1.1 with alternative1.example.org. |
| 10789 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10790 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10791 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10792 | |
| 10793 | // HTTP/1.1 data for request. |
| 10794 | MockWrite http_writes[] = { |
| 10795 | MockWrite("GET / HTTP/1.1\r\n" |
| 10796 | "Host: alternative1.example.org\r\n" |
| 10797 | "Connection: keep-alive\r\n\r\n"), |
| 10798 | }; |
| 10799 | |
| 10800 | MockRead http_reads[] = { |
| 10801 | MockRead("HTTP/1.1 200 OK\r\n" |
| 10802 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10803 | "Content-Length: 40\r\n\r\n" |
| 10804 | "first HTTP/1.1 response from alternative1"), |
| 10805 | }; |
| 10806 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 10807 | http_writes, arraysize(http_writes)); |
| 10808 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 10809 | |
| 10810 | StaticSocketDataProvider data_refused; |
| 10811 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 10812 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 10813 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10814 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10815 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10816 | session->http_server_properties(); |
| 10817 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10818 | // Set up two QUIC alternative services for server. |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10819 | AlternativeServiceInfoVector alternative_service_info_vector; |
| 10820 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 10821 | |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10822 | AlternativeService alternative_service1(kProtoQUIC, alternative1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10823 | alternative_service_info_vector.push_back( |
| 10824 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 10825 | alternative_service1, expiration, |
| 10826 | session->params().quic_supported_versions)); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10827 | AlternativeService alternative_service2(kProtoQUIC, alternative2); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10828 | alternative_service_info_vector.push_back( |
| 10829 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 10830 | alternative_service2, expiration, |
| 10831 | session->params().quic_supported_versions)); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10832 | |
| 10833 | http_server_properties->SetAlternativeServices( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10834 | server, alternative_service_info_vector); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10835 | |
| 10836 | // Mark one of the QUIC alternative service as broken. |
| 10837 | http_server_properties->MarkAlternativeServiceBroken(alternative_service1); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10838 | EXPECT_EQ(2u, |
| 10839 | http_server_properties->GetAlternativeServiceInfos(server).size()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10840 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10841 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 10842 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10843 | request.method = "GET"; |
| 10844 | request.url = GURL(origin_url); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10845 | TestCompletionCallback callback; |
| 10846 | NetErrorDetails details; |
| 10847 | EXPECT_FALSE(details.quic_broken); |
| 10848 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10849 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10850 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10851 | EXPECT_FALSE(details.quic_broken); |
| 10852 | } |
| 10853 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10854 | TEST_F(HttpNetworkTransactionTest, MarkBrokenAlternateProtocolAndFallback) { |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10855 | HttpRequestInfo request; |
| 10856 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10857 | request.url = GURL("https://www.example.org/"); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10858 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10859 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10860 | StaticSocketDataProvider first_data; |
| 10861 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10862 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10863 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10864 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10865 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10866 | |
| 10867 | MockRead data_reads[] = { |
| 10868 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10869 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10870 | MockRead(ASYNC, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10871 | }; |
| 10872 | StaticSocketDataProvider second_data( |
| 10873 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10874 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10875 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10876 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10877 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10878 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10879 | session->http_server_properties(); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10880 | const url::SchemeHostPort server(request.url); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10881 | // Port must be < 1024, or the header will be ignored (since initial port was |
| 10882 | // port 80 (another restricted port). |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10883 | // Port is ignored by MockConnect anyway. |
| 10884 | const AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 10885 | 666); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10886 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10887 | http_server_properties->SetHttp2AlternativeService( |
| 10888 | server, alternative_service, expiration); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10889 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10890 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10891 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10892 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10893 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10894 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10895 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10896 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10897 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10898 | ASSERT_TRUE(response); |
| 10899 | ASSERT_TRUE(response->headers); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10900 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10901 | |
| 10902 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10903 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10904 | EXPECT_EQ("hello world", response_data); |
| 10905 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10906 | const AlternativeServiceInfoVector alternative_service_info_vector = |
| 10907 | http_server_properties->GetAlternativeServiceInfos(server); |
| 10908 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 10909 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 10910 | alternative_service_info_vector[0].alternative_service()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10911 | EXPECT_TRUE( |
| 10912 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10913 | } |
| 10914 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10915 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10916 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10917 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10918 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10919 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedBlocked) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10920 | HttpRequestInfo restricted_port_request; |
| 10921 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10922 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10923 | restricted_port_request.load_flags = 0; |
| 10924 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10925 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10926 | StaticSocketDataProvider first_data; |
| 10927 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10928 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10929 | |
| 10930 | MockRead data_reads[] = { |
| 10931 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10932 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10933 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10934 | }; |
| 10935 | StaticSocketDataProvider second_data( |
| 10936 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10937 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10938 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10939 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10940 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10941 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10942 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10943 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10944 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10945 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10946 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10947 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 10948 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10949 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10950 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10951 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10952 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10953 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10954 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10955 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10956 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10957 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 10958 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10959 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10960 | // Invalid change to unrestricted port should fail. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10961 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_REFUSED)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10962 | } |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10963 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10964 | // Ensure that we are allowed to redirect traffic via an alternate protocol to |
| 10965 | // an unrestricted (port >= 1024) when the original traffic was on a restricted |
| 10966 | // port (port < 1024) if we set |enable_user_alternate_protocol_ports|. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10967 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedPermitted) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10968 | session_deps_.enable_user_alternate_protocol_ports = true; |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10969 | |
| 10970 | HttpRequestInfo restricted_port_request; |
| 10971 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10972 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10973 | restricted_port_request.load_flags = 0; |
| 10974 | |
| 10975 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10976 | StaticSocketDataProvider first_data; |
| 10977 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10978 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10979 | |
| 10980 | MockRead data_reads[] = { |
| 10981 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10982 | MockRead("hello world"), |
| 10983 | MockRead(ASYNC, OK), |
| 10984 | }; |
| 10985 | StaticSocketDataProvider second_data( |
| 10986 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10987 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10988 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10989 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10990 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10991 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10992 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10993 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10994 | HttpServerProperties* http_server_properties = |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10995 | session->http_server_properties(); |
| 10996 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10997 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 10998 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10999 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11000 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11001 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11002 | expiration); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11003 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11004 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11005 | TestCompletionCallback callback; |
| 11006 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11007 | EXPECT_EQ(ERR_IO_PENDING, |
| 11008 | trans.Start(&restricted_port_request, callback.callback(), |
| 11009 | NetLogWithSource())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11010 | // Change to unrestricted port should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11011 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11012 | } |
| 11013 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11014 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 11015 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 11016 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 11017 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11018 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedAllowed) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11019 | HttpRequestInfo restricted_port_request; |
| 11020 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11021 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11022 | restricted_port_request.load_flags = 0; |
| 11023 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11024 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11025 | StaticSocketDataProvider first_data; |
| 11026 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11027 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11028 | |
| 11029 | MockRead data_reads[] = { |
| 11030 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11031 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11032 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11033 | }; |
| 11034 | StaticSocketDataProvider second_data( |
| 11035 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11036 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11037 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11038 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 11039 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11040 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11041 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11042 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11043 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11044 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11045 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11046 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11047 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11048 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11049 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11050 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11051 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11052 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11053 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11054 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11055 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11056 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 11057 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11058 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11059 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11060 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11061 | } |
| 11062 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11063 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 11064 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 11065 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 11066 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11067 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed1) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11068 | HttpRequestInfo unrestricted_port_request; |
| 11069 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11070 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11071 | unrestricted_port_request.load_flags = 0; |
| 11072 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11073 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11074 | StaticSocketDataProvider first_data; |
| 11075 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11076 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11077 | |
| 11078 | MockRead data_reads[] = { |
| 11079 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11080 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11081 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11082 | }; |
| 11083 | StaticSocketDataProvider second_data( |
| 11084 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11085 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11086 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11087 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11088 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11089 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11090 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11091 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11092 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11093 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11094 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11095 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11096 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11097 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11098 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11099 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11100 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11101 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11102 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11103 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11104 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11105 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11106 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11107 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11108 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11109 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11110 | } |
| 11111 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11112 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 11113 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 11114 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 11115 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11116 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed2) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11117 | HttpRequestInfo unrestricted_port_request; |
| 11118 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11119 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11120 | unrestricted_port_request.load_flags = 0; |
| 11121 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11122 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11123 | StaticSocketDataProvider first_data; |
| 11124 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11125 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11126 | |
| 11127 | MockRead data_reads[] = { |
| 11128 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11129 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11130 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11131 | }; |
| 11132 | StaticSocketDataProvider second_data( |
| 11133 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11134 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11135 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11136 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 11137 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11138 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11139 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11140 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11141 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11142 | session->http_server_properties(); |
bnc | 0bbb0262 | 2015-07-23 10:06:22 | [diff] [blame] | 11143 | const int kUnrestrictedAlternatePort = 1025; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11144 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11145 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11146 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11147 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11148 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11149 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11150 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11151 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11152 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11153 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11154 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11155 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11156 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11157 | // Valid change to an unrestricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11158 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11159 | } |
| 11160 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11161 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 11162 | // to an unsafe port, and that we resume the second HttpStreamFactoryImpl::Job |
| 11163 | // once the alternate protocol request fails. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11164 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) { |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11165 | HttpRequestInfo request; |
| 11166 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11167 | request.url = GURL("http://www.example.org/"); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11168 | |
| 11169 | // The alternate protocol request will error out before we attempt to connect, |
| 11170 | // so only the standard HTTP request will try to connect. |
| 11171 | MockRead data_reads[] = { |
| 11172 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11173 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11174 | MockRead(ASYNC, OK), |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11175 | }; |
| 11176 | StaticSocketDataProvider data( |
| 11177 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11178 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11179 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11180 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11181 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11182 | HttpServerProperties* http_server_properties = |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11183 | session->http_server_properties(); |
| 11184 | const int kUnsafePort = 7; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11185 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11186 | kUnsafePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11187 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11188 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11189 | url::SchemeHostPort(request.url), alternative_service, expiration); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11190 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11191 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11192 | TestCompletionCallback callback; |
| 11193 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11194 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11195 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11196 | // The HTTP request should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11197 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11198 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11199 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11200 | ASSERT_TRUE(response); |
| 11201 | ASSERT_TRUE(response->headers); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11202 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11203 | |
| 11204 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11205 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11206 | EXPECT_EQ("hello world", response_data); |
| 11207 | } |
| 11208 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11209 | TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11210 | HttpRequestInfo request; |
| 11211 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11212 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11213 | |
| 11214 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11215 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11216 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11217 | MockRead("\r\n"), |
| 11218 | MockRead("hello world"), |
| 11219 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11220 | MockRead(ASYNC, OK)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11221 | |
| 11222 | StaticSocketDataProvider first_transaction( |
| 11223 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11224 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11225 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11226 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11227 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11228 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11229 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11230 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11231 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11232 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11233 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11234 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 11235 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11236 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11237 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11238 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11239 | }; |
| 11240 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11241 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11242 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11243 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11244 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11245 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11246 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 11247 | NULL, 0, NULL, 0); |
| 11248 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 11249 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11250 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11251 | &hanging_non_alternate_protocol_socket); |
| 11252 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11253 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11254 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11255 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11256 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11257 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11258 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11259 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11260 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11261 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11262 | |
| 11263 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11264 | ASSERT_TRUE(response); |
| 11265 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11266 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11267 | |
| 11268 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11269 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11270 | EXPECT_EQ("hello world", response_data); |
| 11271 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11272 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11273 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11274 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11275 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11276 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11277 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11278 | |
| 11279 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11280 | ASSERT_TRUE(response); |
| 11281 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11282 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11283 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11284 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11285 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11286 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11287 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11288 | } |
| 11289 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11290 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11291 | HttpRequestInfo request; |
| 11292 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11293 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11294 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11295 | // First transaction receives Alt-Svc header over HTTP/1.1. |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11296 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11297 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11298 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11299 | MockRead("\r\n"), |
| 11300 | MockRead("hello world"), |
| 11301 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11302 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11303 | }; |
| 11304 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11305 | StaticSocketDataProvider http11_data(data_reads, arraysize(data_reads), NULL, |
| 11306 | 0); |
| 11307 | session_deps_.socket_factory->AddSocketDataProvider(&http11_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11308 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11309 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 11310 | ssl_http11.cert = ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11311 | ASSERT_TRUE(ssl_http11.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11312 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
| 11313 | |
| 11314 | // Second transaction starts an alternative and a non-alternative Job. |
| 11315 | // Both sockets hang. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11316 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 11317 | StaticSocketDataProvider hanging_socket1(NULL, 0, NULL, 0); |
| 11318 | hanging_socket1.set_connect_data(never_finishing_connect); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 11319 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket1); |
| 11320 | |
| 11321 | StaticSocketDataProvider hanging_socket2(NULL, 0, NULL, 0); |
| 11322 | hanging_socket2.set_connect_data(never_finishing_connect); |
| 11323 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket2); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11324 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11325 | // Third transaction starts an alternative and a non-alternative job. |
| 11326 | // The non-alternative job hangs, but the alternative one succeeds. |
| 11327 | // The second transaction, still pending, binds to this socket. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11328 | SpdySerializedFrame req1( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11329 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11330 | SpdySerializedFrame req2( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11331 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 3, LOWEST)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11332 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11333 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 1), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11334 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 11335 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11336 | SpdySerializedFrame data1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 11337 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11338 | SpdySerializedFrame data2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11339 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11340 | CreateMockRead(resp1, 2), CreateMockRead(data1, 3), |
| 11341 | CreateMockRead(resp2, 4), CreateMockRead(data2, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11342 | MockRead(ASYNC, 0, 6), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11343 | }; |
| 11344 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11345 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11346 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11347 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11348 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11349 | AddSSLSocketData(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11350 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 11351 | StaticSocketDataProvider hanging_socket3(NULL, 0, NULL, 0); |
| 11352 | hanging_socket3.set_connect_data(never_finishing_connect); |
| 11353 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket3); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11354 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11355 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11356 | TestCompletionCallback callback1; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11357 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11358 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11359 | int rv = trans1.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11360 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11361 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11362 | |
| 11363 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11364 | ASSERT_TRUE(response); |
| 11365 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11366 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11367 | |
| 11368 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11369 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11370 | EXPECT_EQ("hello world", response_data); |
| 11371 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11372 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11373 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11374 | rv = trans2.Start(&request, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11375 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11376 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11377 | TestCompletionCallback callback3; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11378 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11379 | rv = trans3.Start(&request, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11380 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11381 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11382 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
| 11383 | EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11384 | |
| 11385 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11386 | ASSERT_TRUE(response); |
| 11387 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11388 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11389 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11390 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11391 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11392 | EXPECT_EQ("hello!", response_data); |
| 11393 | |
| 11394 | response = trans3.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11395 | ASSERT_TRUE(response); |
| 11396 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11397 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11398 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11399 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11400 | ASSERT_THAT(ReadTransaction(&trans3, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11401 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11402 | } |
| 11403 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11404 | TEST_F(HttpNetworkTransactionTest, StallAlternativeServiceForNpnSpdy) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11405 | HttpRequestInfo request; |
| 11406 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11407 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11408 | |
| 11409 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11410 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11411 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11412 | MockRead("\r\n"), |
| 11413 | MockRead("hello world"), |
| 11414 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11415 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11416 | }; |
| 11417 | |
| 11418 | StaticSocketDataProvider first_transaction( |
| 11419 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11420 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11421 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11422 | SSLSocketDataProvider ssl(ASYNC, OK); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 11423 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11424 | ASSERT_TRUE(ssl.cert); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11425 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11426 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11427 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11428 | StaticSocketDataProvider hanging_alternate_protocol_socket( |
| 11429 | NULL, 0, NULL, 0); |
| 11430 | hanging_alternate_protocol_socket.set_connect_data( |
| 11431 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11432 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11433 | &hanging_alternate_protocol_socket); |
| 11434 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11435 | // 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] | 11436 | StaticSocketDataProvider second_transaction(data_reads, arraysize(data_reads), |
| 11437 | NULL, 0); |
| 11438 | session_deps_.socket_factory->AddSocketDataProvider(&second_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11439 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11440 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11441 | TestCompletionCallback callback; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11442 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11443 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11444 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11445 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11446 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11447 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11448 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11449 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11450 | |
| 11451 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11452 | ASSERT_TRUE(response); |
| 11453 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11454 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11455 | |
| 11456 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11457 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11458 | EXPECT_EQ("hello world", response_data); |
| 11459 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11460 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11461 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11462 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11463 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11464 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11465 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11466 | |
| 11467 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11468 | ASSERT_TRUE(response); |
| 11469 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11470 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11471 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11472 | EXPECT_FALSE(response->was_alpn_negotiated); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11473 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11474 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11475 | EXPECT_EQ("hello world", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11476 | } |
| 11477 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11478 | class CapturingProxyResolver : public ProxyResolver { |
| 11479 | public: |
sammc | e90c921 | 2015-05-27 23:43:35 | [diff] [blame] | 11480 | CapturingProxyResolver() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11481 | ~CapturingProxyResolver() override {} |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11482 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11483 | int GetProxyForURL(const GURL& url, |
| 11484 | ProxyInfo* results, |
| 11485 | const CompletionCallback& callback, |
maksim.sisov | 7e15726 | 2016-10-20 11:19:55 | [diff] [blame] | 11486 | std::unique_ptr<Request>* request, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11487 | const NetLogWithSource& net_log) override { |
[email protected] | fae7669f | 2010-08-02 21:49:40 | [diff] [blame] | 11488 | ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, |
| 11489 | HostPortPair("myproxy", 80)); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11490 | results->UseProxyServer(proxy_server); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11491 | resolved_.push_back(url); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11492 | return OK; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11493 | } |
| 11494 | |
[email protected] | 2447640 | 2010-07-20 20:55:17 | [diff] [blame] | 11495 | const std::vector<GURL>& resolved() const { return resolved_; } |
| 11496 | |
| 11497 | private: |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11498 | std::vector<GURL> resolved_; |
| 11499 | |
| 11500 | DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); |
| 11501 | }; |
| 11502 | |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 11503 | class CapturingProxyResolverFactory : public ProxyResolverFactory { |
| 11504 | public: |
| 11505 | explicit CapturingProxyResolverFactory(CapturingProxyResolver* resolver) |
| 11506 | : ProxyResolverFactory(false), resolver_(resolver) {} |
| 11507 | |
| 11508 | int CreateProxyResolver( |
| 11509 | const scoped_refptr<ProxyResolverScriptData>& pac_script, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11510 | std::unique_ptr<ProxyResolver>* resolver, |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 11511 | const net::CompletionCallback& callback, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11512 | std::unique_ptr<Request>* request) override { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11513 | *resolver = std::make_unique<ForwardingProxyResolver>(resolver_); |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 11514 | return OK; |
| 11515 | } |
| 11516 | |
| 11517 | private: |
| 11518 | ProxyResolver* resolver_; |
| 11519 | }; |
| 11520 | |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11521 | // Test that proxy is resolved using the origin url, |
| 11522 | // regardless of the alternative server. |
| 11523 | TEST_F(HttpNetworkTransactionTest, UseOriginNotAlternativeForProxy) { |
| 11524 | // Configure proxy to bypass www.example.org, which is the origin URL. |
| 11525 | ProxyConfig proxy_config; |
| 11526 | proxy_config.proxy_rules().ParseFromString("myproxy:70"); |
| 11527 | proxy_config.proxy_rules().bypass_rules.AddRuleFromString("www.example.org"); |
| 11528 | auto proxy_config_service = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11529 | std::make_unique<ProxyConfigServiceFixed>(proxy_config); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11530 | |
| 11531 | CapturingProxyResolver capturing_proxy_resolver; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11532 | auto proxy_resolver_factory = std::make_unique<CapturingProxyResolverFactory>( |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11533 | &capturing_proxy_resolver); |
| 11534 | |
| 11535 | TestNetLog net_log; |
| 11536 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11537 | session_deps_.proxy_service = std::make_unique<ProxyService>( |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11538 | std::move(proxy_config_service), std::move(proxy_resolver_factory), |
| 11539 | &net_log); |
| 11540 | |
| 11541 | session_deps_.net_log = &net_log; |
| 11542 | |
| 11543 | // Configure alternative service with a hostname that is not bypassed by the |
| 11544 | // proxy. |
| 11545 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11546 | HttpServerProperties* http_server_properties = |
| 11547 | session->http_server_properties(); |
| 11548 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 11549 | HostPortPair alternative("www.example.com", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11550 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11551 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11552 | http_server_properties->SetHttp2AlternativeService( |
| 11553 | server, alternative_service, expiration); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11554 | |
| 11555 | // Non-alternative job should hang. |
| 11556 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
| 11557 | StaticSocketDataProvider hanging_alternate_protocol_socket(nullptr, 0, |
| 11558 | nullptr, 0); |
| 11559 | hanging_alternate_protocol_socket.set_connect_data(never_finishing_connect); |
| 11560 | session_deps_.socket_factory->AddSocketDataProvider( |
| 11561 | &hanging_alternate_protocol_socket); |
| 11562 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11563 | AddSSLSocketData(); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11564 | |
| 11565 | HttpRequestInfo request; |
| 11566 | request.method = "GET"; |
| 11567 | request.url = GURL("https://www.example.org/"); |
| 11568 | request.load_flags = 0; |
| 11569 | |
| 11570 | SpdySerializedFrame req( |
| 11571 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
| 11572 | |
| 11573 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
| 11574 | |
| 11575 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 11576 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 11577 | MockRead spdy_reads[] = { |
| 11578 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
| 11579 | }; |
| 11580 | |
| 11581 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11582 | arraysize(spdy_writes)); |
| 11583 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 11584 | |
| 11585 | TestCompletionCallback callback; |
| 11586 | |
| 11587 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 11588 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11589 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11590 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 11591 | |
| 11592 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 11593 | ASSERT_TRUE(response); |
| 11594 | ASSERT_TRUE(response->headers); |
| 11595 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 11596 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11597 | EXPECT_TRUE(response->was_alpn_negotiated); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11598 | |
| 11599 | std::string response_data; |
| 11600 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 11601 | EXPECT_EQ("hello!", response_data); |
| 11602 | |
| 11603 | // Origin host bypasses proxy, no resolution should have happened. |
| 11604 | ASSERT_TRUE(capturing_proxy_resolver.resolved().empty()); |
| 11605 | } |
| 11606 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11607 | TEST_F(HttpNetworkTransactionTest, UseAlternativeServiceForTunneledNpnSpdy) { |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11608 | ProxyConfig proxy_config; |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11609 | proxy_config.set_auto_detect(true); |
| 11610 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 11611 | |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11612 | CapturingProxyResolver capturing_proxy_resolver; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11613 | session_deps_.proxy_service = std::make_unique<ProxyService>( |
| 11614 | std::make_unique<ProxyConfigServiceFixed>(proxy_config), |
| 11615 | std::make_unique<CapturingProxyResolverFactory>( |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11616 | &capturing_proxy_resolver), |
| 11617 | nullptr); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11618 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11619 | session_deps_.net_log = &net_log; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11620 | |
| 11621 | HttpRequestInfo request; |
| 11622 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11623 | request.url = GURL("https://www.example.org/"); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11624 | |
| 11625 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11626 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11627 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11628 | MockRead("\r\n"), |
| 11629 | MockRead("hello world"), |
| 11630 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11631 | MockRead(ASYNC, OK), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11632 | }; |
| 11633 | |
| 11634 | StaticSocketDataProvider first_transaction( |
| 11635 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11636 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11637 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11638 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11639 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11640 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11641 | AddSSLSocketData(); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11642 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11643 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11644 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11645 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11646 | MockWrite(ASYNC, 0, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11647 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 11648 | "Host: www.example.org:443\r\n" |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11649 | "Proxy-Connection: keep-alive\r\n\r\n"), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11650 | CreateMockWrite(req, 2), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11651 | }; |
| 11652 | |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11653 | const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 11654 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 11655 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11656 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11657 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11658 | MockRead(ASYNC, 1, kCONNECTResponse), CreateMockRead(resp, 3), |
| 11659 | CreateMockRead(data, 4), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11660 | }; |
| 11661 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11662 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11663 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11664 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11665 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11666 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11667 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 11668 | NULL, 0, NULL, 0); |
| 11669 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 11670 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11671 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11672 | &hanging_non_alternate_protocol_socket); |
| 11673 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11674 | TestCompletionCallback callback; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11675 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11676 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11677 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11678 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11679 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11680 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 11681 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11682 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 11683 | |
| 11684 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 11685 | ASSERT_TRUE(response); |
| 11686 | ASSERT_TRUE(response->headers); |
| 11687 | EXPECT_EQ("HTTP/0.9 200 OK", response->headers->GetStatusLine()); |
| 11688 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11689 | EXPECT_TRUE(response->was_alpn_negotiated); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 11690 | |
| 11691 | std::string response_data; |
| 11692 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 11693 | EXPECT_EQ("hello world", response_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11694 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11695 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11696 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11697 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11698 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11699 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11700 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11701 | |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 11702 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11703 | ASSERT_TRUE(response); |
| 11704 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11705 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11706 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11707 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11708 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11709 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11710 | EXPECT_EQ("hello!", response_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11711 | ASSERT_EQ(2u, capturing_proxy_resolver.resolved().size()); |
| 11712 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11713 | capturing_proxy_resolver.resolved()[0].spec()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11714 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11715 | capturing_proxy_resolver.resolved()[1].spec()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11716 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11717 | LoadTimingInfo load_timing_info; |
| 11718 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 11719 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11720 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11721 | } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11722 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11723 | TEST_F(HttpNetworkTransactionTest, |
bnc | 1c196c6e | 2016-05-28 13:51:48 | [diff] [blame] | 11724 | UseAlternativeServiceForNpnSpdyWithExistingSpdySession) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11725 | HttpRequestInfo request; |
| 11726 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11727 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11728 | |
| 11729 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11730 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11731 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11732 | MockRead("\r\n"), |
| 11733 | MockRead("hello world"), |
| 11734 | MockRead(ASYNC, OK), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11735 | }; |
| 11736 | |
| 11737 | StaticSocketDataProvider first_transaction( |
| 11738 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11739 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11740 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11741 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11742 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11743 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11744 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11745 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11746 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11747 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11748 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11749 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 11750 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11751 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11752 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11753 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11754 | }; |
| 11755 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11756 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11757 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11758 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11759 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 11760 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11761 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11762 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11763 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11764 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11765 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11766 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11767 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11768 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11769 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11770 | |
| 11771 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11772 | ASSERT_TRUE(response); |
| 11773 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11774 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11775 | |
| 11776 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11777 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11778 | EXPECT_EQ("hello world", response_data); |
| 11779 | |
| 11780 | // Set up an initial SpdySession in the pool to reuse. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11781 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 11782 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 11783 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 11784 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 11785 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 11786 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11787 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11788 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11789 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11790 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11791 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11792 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11793 | |
| 11794 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11795 | ASSERT_TRUE(response); |
| 11796 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11797 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11798 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11799 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11800 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11801 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11802 | EXPECT_EQ("hello!", response_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11803 | } |
| 11804 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11805 | // GenerateAuthToken is a mighty big test. |
| 11806 | // It tests all permutation of GenerateAuthToken behavior: |
| 11807 | // - Synchronous and Asynchronous completion. |
| 11808 | // - OK or error on completion. |
| 11809 | // - Direct connection, non-authenticating proxy, and authenticating proxy. |
| 11810 | // - HTTP or HTTPS backend (to include proxy tunneling). |
| 11811 | // - Non-authenticating and authenticating backend. |
| 11812 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 11813 | // In all, there are 44 reasonable permuations (for example, if there are |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11814 | // problems generating an auth token for an authenticating proxy, we don't |
| 11815 | // need to test all permutations of the backend server). |
| 11816 | // |
| 11817 | // The test proceeds by going over each of the configuration cases, and |
| 11818 | // potentially running up to three rounds in each of the tests. The TestConfig |
| 11819 | // specifies both the configuration for the test as well as the expectations |
| 11820 | // for the results. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11821 | TEST_F(HttpNetworkTransactionTest, GenerateAuthToken) { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11822 | static const char kServer[] = "http://www.example.com"; |
| 11823 | static const char kSecureServer[] = "https://www.example.com"; |
| 11824 | static const char kProxy[] = "myproxy:70"; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11825 | |
| 11826 | enum AuthTiming { |
| 11827 | AUTH_NONE, |
| 11828 | AUTH_SYNC, |
| 11829 | AUTH_ASYNC, |
| 11830 | }; |
| 11831 | |
| 11832 | const MockWrite kGet( |
| 11833 | "GET / HTTP/1.1\r\n" |
| 11834 | "Host: www.example.com\r\n" |
| 11835 | "Connection: keep-alive\r\n\r\n"); |
| 11836 | const MockWrite kGetProxy( |
| 11837 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11838 | "Host: www.example.com\r\n" |
| 11839 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 11840 | const MockWrite kGetAuth( |
| 11841 | "GET / HTTP/1.1\r\n" |
| 11842 | "Host: www.example.com\r\n" |
| 11843 | "Connection: keep-alive\r\n" |
| 11844 | "Authorization: auth_token\r\n\r\n"); |
| 11845 | const MockWrite kGetProxyAuth( |
| 11846 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11847 | "Host: www.example.com\r\n" |
| 11848 | "Proxy-Connection: keep-alive\r\n" |
| 11849 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 11850 | const MockWrite kGetAuthThroughProxy( |
| 11851 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11852 | "Host: www.example.com\r\n" |
| 11853 | "Proxy-Connection: keep-alive\r\n" |
| 11854 | "Authorization: auth_token\r\n\r\n"); |
| 11855 | const MockWrite kGetAuthWithProxyAuth( |
| 11856 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11857 | "Host: www.example.com\r\n" |
| 11858 | "Proxy-Connection: keep-alive\r\n" |
| 11859 | "Proxy-Authorization: auth_token\r\n" |
| 11860 | "Authorization: auth_token\r\n\r\n"); |
| 11861 | const MockWrite kConnect( |
| 11862 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 11863 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11864 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 11865 | const MockWrite kConnectProxyAuth( |
| 11866 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 11867 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11868 | "Proxy-Connection: keep-alive\r\n" |
| 11869 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 11870 | |
| 11871 | const MockRead kSuccess( |
| 11872 | "HTTP/1.1 200 OK\r\n" |
| 11873 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11874 | "Content-Length: 3\r\n\r\n" |
| 11875 | "Yes"); |
| 11876 | const MockRead kFailure( |
| 11877 | "Should not be called."); |
| 11878 | const MockRead kServerChallenge( |
| 11879 | "HTTP/1.1 401 Unauthorized\r\n" |
| 11880 | "WWW-Authenticate: Mock realm=server\r\n" |
| 11881 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11882 | "Content-Length: 14\r\n\r\n" |
| 11883 | "Unauthorized\r\n"); |
| 11884 | const MockRead kProxyChallenge( |
| 11885 | "HTTP/1.1 407 Unauthorized\r\n" |
| 11886 | "Proxy-Authenticate: Mock realm=proxy\r\n" |
| 11887 | "Proxy-Connection: close\r\n" |
| 11888 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11889 | "Content-Length: 14\r\n\r\n" |
| 11890 | "Unauthorized\r\n"); |
| 11891 | const MockRead kProxyConnected( |
| 11892 | "HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 11893 | |
| 11894 | // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with |
| 11895 | // no constructors, but the C++ compiler on Windows warns about |
| 11896 | // unspecified data in compound literals. So, moved to using constructors, |
| 11897 | // and TestRound's created with the default constructor should not be used. |
| 11898 | struct TestRound { |
| 11899 | TestRound() |
| 11900 | : expected_rv(ERR_UNEXPECTED), |
| 11901 | extra_write(NULL), |
| 11902 | extra_read(NULL) { |
| 11903 | } |
| 11904 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 11905 | int expected_rv_arg) |
| 11906 | : write(write_arg), |
| 11907 | read(read_arg), |
| 11908 | expected_rv(expected_rv_arg), |
| 11909 | extra_write(NULL), |
| 11910 | extra_read(NULL) { |
| 11911 | } |
| 11912 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 11913 | int expected_rv_arg, const MockWrite* extra_write_arg, |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 11914 | const MockRead* extra_read_arg) |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11915 | : write(write_arg), |
| 11916 | read(read_arg), |
| 11917 | expected_rv(expected_rv_arg), |
| 11918 | extra_write(extra_write_arg), |
| 11919 | extra_read(extra_read_arg) { |
| 11920 | } |
| 11921 | MockWrite write; |
| 11922 | MockRead read; |
| 11923 | int expected_rv; |
| 11924 | const MockWrite* extra_write; |
| 11925 | const MockRead* extra_read; |
| 11926 | }; |
| 11927 | |
| 11928 | static const int kNoSSL = 500; |
| 11929 | |
| 11930 | struct TestConfig { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11931 | int line_number; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 11932 | const char* const proxy_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11933 | AuthTiming proxy_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11934 | int first_generate_proxy_token_rv; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 11935 | const char* const server_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11936 | AuthTiming server_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11937 | int first_generate_server_token_rv; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11938 | int num_auth_rounds; |
| 11939 | int first_ssl_round; |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11940 | TestRound rounds[4]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11941 | } test_configs[] = { |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11942 | // Non-authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11943 | {__LINE__, |
| 11944 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11945 | AUTH_NONE, |
| 11946 | OK, |
| 11947 | kServer, |
| 11948 | AUTH_NONE, |
| 11949 | OK, |
| 11950 | 1, |
| 11951 | kNoSSL, |
| 11952 | {TestRound(kGet, kSuccess, OK)}}, |
| 11953 | // Authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11954 | {__LINE__, |
| 11955 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11956 | AUTH_NONE, |
| 11957 | OK, |
| 11958 | kServer, |
| 11959 | AUTH_SYNC, |
| 11960 | OK, |
| 11961 | 2, |
| 11962 | kNoSSL, |
| 11963 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11964 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11965 | {__LINE__, |
| 11966 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11967 | AUTH_NONE, |
| 11968 | OK, |
| 11969 | kServer, |
| 11970 | AUTH_SYNC, |
| 11971 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11972 | 3, |
| 11973 | kNoSSL, |
| 11974 | {TestRound(kGet, kServerChallenge, OK), |
| 11975 | TestRound(kGet, kServerChallenge, OK), |
| 11976 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11977 | {__LINE__, |
| 11978 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11979 | AUTH_NONE, |
| 11980 | OK, |
| 11981 | kServer, |
| 11982 | AUTH_SYNC, |
| 11983 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 11984 | 2, |
| 11985 | kNoSSL, |
| 11986 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11987 | {__LINE__, |
| 11988 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11989 | AUTH_NONE, |
| 11990 | OK, |
| 11991 | kServer, |
| 11992 | AUTH_SYNC, |
| 11993 | ERR_UNDOCUMENTED_SECURITY_LIBRARY_STATUS, |
| 11994 | 2, |
| 11995 | kNoSSL, |
| 11996 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11997 | {__LINE__, |
| 11998 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11999 | AUTH_SYNC, |
| 12000 | ERR_FAILED, |
| 12001 | kServer, |
| 12002 | AUTH_NONE, |
| 12003 | OK, |
| 12004 | 2, |
| 12005 | kNoSSL, |
| 12006 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12007 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12008 | {__LINE__, |
| 12009 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12010 | AUTH_ASYNC, |
| 12011 | ERR_FAILED, |
| 12012 | kServer, |
| 12013 | AUTH_NONE, |
| 12014 | OK, |
| 12015 | 2, |
| 12016 | kNoSSL, |
| 12017 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12018 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12019 | {__LINE__, |
| 12020 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12021 | AUTH_NONE, |
| 12022 | OK, |
| 12023 | kServer, |
| 12024 | AUTH_SYNC, |
| 12025 | ERR_FAILED, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12026 | 2, |
| 12027 | kNoSSL, |
| 12028 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12029 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12030 | {__LINE__, |
| 12031 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12032 | AUTH_NONE, |
| 12033 | OK, |
| 12034 | kServer, |
| 12035 | AUTH_ASYNC, |
| 12036 | ERR_FAILED, |
| 12037 | 2, |
| 12038 | kNoSSL, |
| 12039 | {TestRound(kGet, kServerChallenge, OK), |
| 12040 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12041 | {__LINE__, |
| 12042 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12043 | AUTH_NONE, |
| 12044 | OK, |
| 12045 | kServer, |
| 12046 | AUTH_ASYNC, |
| 12047 | OK, |
| 12048 | 2, |
| 12049 | kNoSSL, |
| 12050 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12051 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12052 | {__LINE__, |
| 12053 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12054 | AUTH_NONE, |
| 12055 | OK, |
| 12056 | kServer, |
| 12057 | AUTH_ASYNC, |
| 12058 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12059 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12060 | kNoSSL, |
| 12061 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12062 | // The second round uses a HttpAuthHandlerMock that always succeeds. |
| 12063 | TestRound(kGet, kServerChallenge, OK), |
| 12064 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12065 | // Non-authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12066 | {__LINE__, |
| 12067 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12068 | AUTH_NONE, |
| 12069 | OK, |
| 12070 | kServer, |
| 12071 | AUTH_NONE, |
| 12072 | OK, |
| 12073 | 1, |
| 12074 | kNoSSL, |
| 12075 | {TestRound(kGetProxy, kSuccess, OK)}}, |
| 12076 | // Authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12077 | {__LINE__, |
| 12078 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12079 | AUTH_NONE, |
| 12080 | OK, |
| 12081 | kServer, |
| 12082 | AUTH_SYNC, |
| 12083 | OK, |
| 12084 | 2, |
| 12085 | kNoSSL, |
| 12086 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12087 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12088 | {__LINE__, |
| 12089 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12090 | AUTH_NONE, |
| 12091 | OK, |
| 12092 | kServer, |
| 12093 | AUTH_SYNC, |
| 12094 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12095 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12096 | kNoSSL, |
| 12097 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12098 | TestRound(kGetProxy, kServerChallenge, OK), |
| 12099 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12100 | {__LINE__, |
| 12101 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12102 | AUTH_NONE, |
| 12103 | OK, |
| 12104 | kServer, |
| 12105 | AUTH_ASYNC, |
| 12106 | OK, |
| 12107 | 2, |
| 12108 | kNoSSL, |
| 12109 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12110 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12111 | {__LINE__, |
| 12112 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12113 | AUTH_NONE, |
| 12114 | OK, |
| 12115 | kServer, |
| 12116 | AUTH_ASYNC, |
| 12117 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12118 | 2, |
| 12119 | kNoSSL, |
| 12120 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12121 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12122 | // Non-authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12123 | {__LINE__, |
| 12124 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12125 | AUTH_SYNC, |
| 12126 | OK, |
| 12127 | kServer, |
| 12128 | AUTH_NONE, |
| 12129 | OK, |
| 12130 | 2, |
| 12131 | kNoSSL, |
| 12132 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12133 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12134 | {__LINE__, |
| 12135 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12136 | AUTH_SYNC, |
| 12137 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12138 | kServer, |
| 12139 | AUTH_NONE, |
| 12140 | OK, |
| 12141 | 2, |
| 12142 | kNoSSL, |
| 12143 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12144 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12145 | {__LINE__, |
| 12146 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12147 | AUTH_ASYNC, |
| 12148 | OK, |
| 12149 | kServer, |
| 12150 | AUTH_NONE, |
| 12151 | OK, |
| 12152 | 2, |
| 12153 | kNoSSL, |
| 12154 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12155 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12156 | {__LINE__, |
| 12157 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12158 | AUTH_ASYNC, |
| 12159 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12160 | kServer, |
| 12161 | AUTH_NONE, |
| 12162 | OK, |
| 12163 | 2, |
| 12164 | kNoSSL, |
| 12165 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12166 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12167 | {__LINE__, |
| 12168 | kProxy, |
| 12169 | AUTH_ASYNC, |
| 12170 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12171 | kServer, |
| 12172 | AUTH_NONE, |
| 12173 | OK, |
| 12174 | 3, |
| 12175 | kNoSSL, |
| 12176 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12177 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 12178 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12179 | // Authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12180 | {__LINE__, |
| 12181 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12182 | AUTH_SYNC, |
| 12183 | OK, |
| 12184 | kServer, |
| 12185 | AUTH_SYNC, |
| 12186 | OK, |
| 12187 | 3, |
| 12188 | kNoSSL, |
| 12189 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12190 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12191 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12192 | {__LINE__, |
| 12193 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12194 | AUTH_SYNC, |
| 12195 | OK, |
| 12196 | kServer, |
| 12197 | AUTH_SYNC, |
| 12198 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12199 | 3, |
| 12200 | kNoSSL, |
| 12201 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12202 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12203 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12204 | {__LINE__, |
| 12205 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12206 | AUTH_ASYNC, |
| 12207 | OK, |
| 12208 | kServer, |
| 12209 | AUTH_SYNC, |
| 12210 | OK, |
| 12211 | 3, |
| 12212 | kNoSSL, |
| 12213 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12214 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12215 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12216 | {__LINE__, |
| 12217 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12218 | AUTH_ASYNC, |
| 12219 | OK, |
| 12220 | kServer, |
| 12221 | AUTH_SYNC, |
| 12222 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12223 | 3, |
| 12224 | kNoSSL, |
| 12225 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12226 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12227 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12228 | {__LINE__, |
| 12229 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12230 | AUTH_SYNC, |
| 12231 | OK, |
| 12232 | kServer, |
| 12233 | AUTH_ASYNC, |
| 12234 | OK, |
| 12235 | 3, |
| 12236 | kNoSSL, |
| 12237 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12238 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12239 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12240 | {__LINE__, |
| 12241 | kProxy, |
| 12242 | AUTH_SYNC, |
| 12243 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12244 | kServer, |
| 12245 | AUTH_ASYNC, |
| 12246 | OK, |
| 12247 | 4, |
| 12248 | kNoSSL, |
| 12249 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12250 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 12251 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12252 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 12253 | {__LINE__, |
| 12254 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12255 | AUTH_SYNC, |
| 12256 | OK, |
| 12257 | kServer, |
| 12258 | AUTH_ASYNC, |
| 12259 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12260 | 3, |
| 12261 | kNoSSL, |
| 12262 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12263 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12264 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12265 | {__LINE__, |
| 12266 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12267 | AUTH_ASYNC, |
| 12268 | OK, |
| 12269 | kServer, |
| 12270 | AUTH_ASYNC, |
| 12271 | OK, |
| 12272 | 3, |
| 12273 | kNoSSL, |
| 12274 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12275 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12276 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12277 | {__LINE__, |
| 12278 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12279 | AUTH_ASYNC, |
| 12280 | OK, |
| 12281 | kServer, |
| 12282 | AUTH_ASYNC, |
| 12283 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12284 | 3, |
| 12285 | kNoSSL, |
| 12286 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12287 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12288 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12289 | {__LINE__, |
| 12290 | kProxy, |
| 12291 | AUTH_ASYNC, |
| 12292 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12293 | kServer, |
| 12294 | AUTH_ASYNC, |
| 12295 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12296 | 4, |
| 12297 | kNoSSL, |
| 12298 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12299 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 12300 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12301 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12302 | // Non-authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12303 | {__LINE__, |
| 12304 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12305 | AUTH_NONE, |
| 12306 | OK, |
| 12307 | kSecureServer, |
| 12308 | AUTH_NONE, |
| 12309 | OK, |
| 12310 | 1, |
| 12311 | 0, |
| 12312 | {TestRound(kGet, kSuccess, OK)}}, |
| 12313 | // Authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12314 | {__LINE__, |
| 12315 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12316 | AUTH_NONE, |
| 12317 | OK, |
| 12318 | kSecureServer, |
| 12319 | AUTH_SYNC, |
| 12320 | OK, |
| 12321 | 2, |
| 12322 | 0, |
| 12323 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12324 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12325 | {__LINE__, |
| 12326 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12327 | AUTH_NONE, |
| 12328 | OK, |
| 12329 | kSecureServer, |
| 12330 | AUTH_SYNC, |
| 12331 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12332 | 2, |
| 12333 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12334 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12335 | {__LINE__, |
| 12336 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12337 | AUTH_NONE, |
| 12338 | OK, |
| 12339 | kSecureServer, |
| 12340 | AUTH_ASYNC, |
| 12341 | OK, |
| 12342 | 2, |
| 12343 | 0, |
| 12344 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12345 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12346 | {__LINE__, |
| 12347 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12348 | AUTH_NONE, |
| 12349 | OK, |
| 12350 | kSecureServer, |
| 12351 | AUTH_ASYNC, |
| 12352 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12353 | 2, |
| 12354 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12355 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12356 | // Non-authenticating HTTPS server with a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12357 | {__LINE__, |
| 12358 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12359 | AUTH_NONE, |
| 12360 | OK, |
| 12361 | kSecureServer, |
| 12362 | AUTH_NONE, |
| 12363 | OK, |
| 12364 | 1, |
| 12365 | 0, |
| 12366 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 12367 | // Authenticating HTTPS server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12368 | {__LINE__, |
| 12369 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12370 | AUTH_NONE, |
| 12371 | OK, |
| 12372 | kSecureServer, |
| 12373 | AUTH_SYNC, |
| 12374 | OK, |
| 12375 | 2, |
| 12376 | 0, |
| 12377 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12378 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12379 | {__LINE__, |
| 12380 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12381 | AUTH_NONE, |
| 12382 | OK, |
| 12383 | kSecureServer, |
| 12384 | AUTH_SYNC, |
| 12385 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12386 | 2, |
| 12387 | 0, |
| 12388 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12389 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12390 | {__LINE__, |
| 12391 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12392 | AUTH_NONE, |
| 12393 | OK, |
| 12394 | kSecureServer, |
| 12395 | AUTH_ASYNC, |
| 12396 | OK, |
| 12397 | 2, |
| 12398 | 0, |
| 12399 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12400 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12401 | {__LINE__, |
| 12402 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12403 | AUTH_NONE, |
| 12404 | OK, |
| 12405 | kSecureServer, |
| 12406 | AUTH_ASYNC, |
| 12407 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12408 | 2, |
| 12409 | 0, |
| 12410 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12411 | TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12412 | // Non-Authenticating HTTPS server through an authenticating proxy. |
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_SYNC, |
| 12416 | OK, |
| 12417 | kSecureServer, |
| 12418 | AUTH_NONE, |
| 12419 | OK, |
| 12420 | 2, |
| 12421 | 1, |
| 12422 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12423 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12424 | {__LINE__, |
| 12425 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12426 | AUTH_SYNC, |
| 12427 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12428 | kSecureServer, |
| 12429 | AUTH_NONE, |
| 12430 | OK, |
| 12431 | 2, |
| 12432 | kNoSSL, |
| 12433 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12434 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12435 | {__LINE__, |
| 12436 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12437 | AUTH_SYNC, |
| 12438 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 12439 | kSecureServer, |
| 12440 | AUTH_NONE, |
| 12441 | OK, |
| 12442 | 2, |
| 12443 | kNoSSL, |
| 12444 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12445 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12446 | {__LINE__, |
| 12447 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12448 | AUTH_SYNC, |
| 12449 | ERR_UNEXPECTED, |
| 12450 | kSecureServer, |
| 12451 | AUTH_NONE, |
| 12452 | OK, |
| 12453 | 2, |
| 12454 | kNoSSL, |
| 12455 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12456 | TestRound(kConnect, kProxyConnected, ERR_UNEXPECTED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12457 | {__LINE__, |
| 12458 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12459 | AUTH_ASYNC, |
| 12460 | OK, |
| 12461 | kSecureServer, |
| 12462 | AUTH_NONE, |
| 12463 | OK, |
| 12464 | 2, |
| 12465 | 1, |
| 12466 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12467 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12468 | {__LINE__, |
| 12469 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12470 | AUTH_ASYNC, |
| 12471 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12472 | kSecureServer, |
| 12473 | AUTH_NONE, |
| 12474 | OK, |
| 12475 | 2, |
| 12476 | kNoSSL, |
| 12477 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12478 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12479 | // Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12480 | {__LINE__, |
| 12481 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12482 | AUTH_SYNC, |
| 12483 | OK, |
| 12484 | kSecureServer, |
| 12485 | AUTH_SYNC, |
| 12486 | OK, |
| 12487 | 3, |
| 12488 | 1, |
| 12489 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12490 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12491 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12492 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12493 | {__LINE__, |
| 12494 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12495 | AUTH_SYNC, |
| 12496 | OK, |
| 12497 | kSecureServer, |
| 12498 | AUTH_SYNC, |
| 12499 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12500 | 3, |
| 12501 | 1, |
| 12502 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12503 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12504 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12505 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12506 | {__LINE__, |
| 12507 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12508 | AUTH_ASYNC, |
| 12509 | OK, |
| 12510 | kSecureServer, |
| 12511 | AUTH_SYNC, |
| 12512 | OK, |
| 12513 | 3, |
| 12514 | 1, |
| 12515 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12516 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12517 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12518 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12519 | {__LINE__, |
| 12520 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12521 | AUTH_ASYNC, |
| 12522 | OK, |
| 12523 | kSecureServer, |
| 12524 | AUTH_SYNC, |
| 12525 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12526 | 3, |
| 12527 | 1, |
| 12528 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12529 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12530 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12531 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12532 | {__LINE__, |
| 12533 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12534 | AUTH_SYNC, |
| 12535 | OK, |
| 12536 | kSecureServer, |
| 12537 | AUTH_ASYNC, |
| 12538 | OK, |
| 12539 | 3, |
| 12540 | 1, |
| 12541 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12542 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12543 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12544 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12545 | {__LINE__, |
| 12546 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12547 | AUTH_SYNC, |
| 12548 | OK, |
| 12549 | kSecureServer, |
| 12550 | AUTH_ASYNC, |
| 12551 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12552 | 3, |
| 12553 | 1, |
| 12554 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12555 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12556 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12557 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12558 | {__LINE__, |
| 12559 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12560 | AUTH_ASYNC, |
| 12561 | OK, |
| 12562 | kSecureServer, |
| 12563 | AUTH_ASYNC, |
| 12564 | OK, |
| 12565 | 3, |
| 12566 | 1, |
| 12567 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12568 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12569 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12570 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12571 | {__LINE__, |
| 12572 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12573 | AUTH_ASYNC, |
| 12574 | OK, |
| 12575 | kSecureServer, |
| 12576 | AUTH_ASYNC, |
| 12577 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12578 | 3, |
| 12579 | 1, |
| 12580 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12581 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12582 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12583 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12584 | {__LINE__, |
| 12585 | kProxy, |
| 12586 | AUTH_ASYNC, |
| 12587 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12588 | kSecureServer, |
| 12589 | AUTH_ASYNC, |
| 12590 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12591 | 4, |
| 12592 | 2, |
| 12593 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12594 | TestRound(kConnect, kProxyChallenge, OK), |
| 12595 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12596 | &kServerChallenge), |
| 12597 | TestRound(kGet, kSuccess, OK)}}, |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12598 | }; |
| 12599 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12600 | for (const auto& test_config : test_configs) { |
| 12601 | SCOPED_TRACE(::testing::Message() << "Test config at " |
| 12602 | << test_config.line_number); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12603 | HttpAuthHandlerMock::Factory* auth_factory( |
| 12604 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12605 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 12606 | SSLInfo empty_ssl_info; |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 12607 | |
| 12608 | // Set up authentication handlers as necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12609 | if (test_config.proxy_auth_timing != AUTH_NONE) { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12610 | for (int n = 0; n < 3; n++) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12611 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 12612 | std::string auth_challenge = "Mock realm=proxy"; |
| 12613 | GURL origin(test_config.proxy_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 12614 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 12615 | auth_challenge.end()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12616 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12617 | empty_ssl_info, origin, |
| 12618 | NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12619 | auth_handler->SetGenerateExpectation( |
| 12620 | test_config.proxy_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12621 | n == 0 ? test_config.first_generate_proxy_token_rv : OK); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12622 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 12623 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12624 | } |
| 12625 | if (test_config.server_auth_timing != AUTH_NONE) { |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 12626 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12627 | std::string auth_challenge = "Mock realm=server"; |
| 12628 | GURL origin(test_config.server_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 12629 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 12630 | auth_challenge.end()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12631 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12632 | empty_ssl_info, origin, |
| 12633 | NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12634 | auth_handler->SetGenerateExpectation( |
| 12635 | test_config.server_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12636 | test_config.first_generate_server_token_rv); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12637 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12638 | |
| 12639 | // The second handler always succeeds. It should only be used where there |
| 12640 | // are multiple auth sessions for server auth in the same network |
| 12641 | // transaction using the same auth scheme. |
| 12642 | std::unique_ptr<HttpAuthHandlerMock> second_handler = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12643 | std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12644 | second_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 12645 | empty_ssl_info, origin, |
| 12646 | NetLogWithSource()); |
| 12647 | second_handler->SetGenerateExpectation(true, OK); |
| 12648 | auth_factory->AddMockHandler(second_handler.release(), |
| 12649 | HttpAuth::AUTH_SERVER); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12650 | } |
| 12651 | if (test_config.proxy_url) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12652 | session_deps_.proxy_service = |
| 12653 | ProxyService::CreateFixed(test_config.proxy_url); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12654 | } else { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12655 | session_deps_.proxy_service = ProxyService::CreateDirect(); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12656 | } |
| 12657 | |
| 12658 | HttpRequestInfo request; |
| 12659 | request.method = "GET"; |
| 12660 | request.url = GURL(test_config.server_url); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12661 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12662 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12663 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12664 | SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
| 12665 | |
| 12666 | std::vector<std::vector<MockRead>> mock_reads(1); |
| 12667 | std::vector<std::vector<MockWrite>> mock_writes(1); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12668 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 12669 | SCOPED_TRACE(round); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12670 | const TestRound& read_write_round = test_config.rounds[round]; |
| 12671 | |
| 12672 | // Set up expected reads and writes. |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12673 | mock_reads.back().push_back(read_write_round.read); |
| 12674 | mock_writes.back().push_back(read_write_round.write); |
| 12675 | |
| 12676 | // kProxyChallenge uses Proxy-Connection: close which means that the |
| 12677 | // socket is closed and a new one will be created for the next request. |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 12678 | if (read_write_round.read.data == kProxyChallenge.data) { |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12679 | mock_reads.push_back(std::vector<MockRead>()); |
| 12680 | mock_writes.push_back(std::vector<MockWrite>()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12681 | } |
| 12682 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12683 | if (read_write_round.extra_read) { |
| 12684 | mock_reads.back().push_back(*read_write_round.extra_read); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12685 | } |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12686 | if (read_write_round.extra_write) { |
| 12687 | mock_writes.back().push_back(*read_write_round.extra_write); |
| 12688 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12689 | |
| 12690 | // Add an SSL sequence if necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12691 | if (round >= test_config.first_ssl_round) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12692 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12693 | &ssl_socket_data_provider); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12694 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12695 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12696 | std::vector<std::unique_ptr<StaticSocketDataProvider>> data_providers; |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12697 | for (size_t i = 0; i < mock_reads.size(); ++i) { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12698 | data_providers.push_back(std::make_unique<StaticSocketDataProvider>( |
davidben | 5f8b6bc | 2015-11-25 03:19:54 | [diff] [blame] | 12699 | mock_reads[i].data(), mock_reads[i].size(), mock_writes[i].data(), |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12700 | mock_writes[i].size())); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12701 | session_deps_.socket_factory->AddSocketDataProvider( |
olli.raula | 525048c | 2015-12-10 07:38:32 | [diff] [blame] | 12702 | data_providers.back().get()); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12703 | } |
| 12704 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12705 | // Transaction must be created after DataProviders, so it's destroyed before |
| 12706 | // they are as well. |
| 12707 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 12708 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12709 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 12710 | SCOPED_TRACE(round); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12711 | const TestRound& read_write_round = test_config.rounds[round]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12712 | // Start or restart the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12713 | TestCompletionCallback callback; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12714 | int rv; |
| 12715 | if (round == 0) { |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12716 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12717 | } else { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12718 | rv = trans.RestartWithAuth( |
| 12719 | AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12720 | } |
| 12721 | if (rv == ERR_IO_PENDING) |
| 12722 | rv = callback.WaitForResult(); |
| 12723 | |
| 12724 | // Compare results with expected data. |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12725 | EXPECT_THAT(rv, IsError(read_write_round.expected_rv)); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12726 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | c0c82849 | 2015-05-15 01:25:55 | [diff] [blame] | 12727 | if (read_write_round.expected_rv != OK) { |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12728 | EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
| 12729 | continue; |
| 12730 | } |
| 12731 | if (round + 1 < test_config.num_auth_rounds) { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12732 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12733 | } else { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12734 | EXPECT_FALSE(response->auth_challenge); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12735 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12736 | } |
| 12737 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 12738 | } |
| 12739 | } |
| 12740 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12741 | TEST_F(HttpNetworkTransactionTest, MultiRoundAuth) { |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12742 | // Do multi-round authentication and make sure it works correctly. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12743 | HttpAuthHandlerMock::Factory* auth_factory( |
| 12744 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12745 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12746 | session_deps_.proxy_service = ProxyService::CreateDirect(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12747 | session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
| 12748 | session_deps_.host_resolver->set_synchronous_mode(true); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12749 | |
| 12750 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 12751 | auth_handler->set_connection_based(true); |
| 12752 | std::string auth_challenge = "Mock realm=server"; |
| 12753 | GURL origin("http://www.example.com"); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 12754 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 12755 | auth_challenge.end()); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 12756 | SSLInfo empty_ssl_info; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12757 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12758 | empty_ssl_info, origin, NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12759 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12760 | |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12761 | int rv = OK; |
| 12762 | const HttpResponseInfo* response = NULL; |
| 12763 | HttpRequestInfo request; |
| 12764 | request.method = "GET"; |
| 12765 | request.url = origin; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12766 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12767 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12768 | |
| 12769 | // Use a TCP Socket Pool with only one connection per group. This is used |
| 12770 | // to validate that the TCP socket is not released to the pool between |
| 12771 | // each round of multi-round authentication. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12772 | HttpNetworkSessionPeer session_peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12773 | TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12774 | 50, // Max sockets for pool |
| 12775 | 1, // Max sockets per group |
tbansal | 7b403bcc | 2016-04-13 22:33:21 | [diff] [blame] | 12776 | session_deps_.host_resolver.get(), session_deps_.socket_factory.get(), |
| 12777 | NULL, session_deps_.net_log); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12778 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 12779 | mock_pool_manager->SetTransportSocketPool(transport_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 12780 | session_peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12781 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12782 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12783 | TestCompletionCallback callback; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12784 | |
| 12785 | const MockWrite kGet( |
| 12786 | "GET / HTTP/1.1\r\n" |
| 12787 | "Host: www.example.com\r\n" |
| 12788 | "Connection: keep-alive\r\n\r\n"); |
| 12789 | const MockWrite kGetAuth( |
| 12790 | "GET / HTTP/1.1\r\n" |
| 12791 | "Host: www.example.com\r\n" |
| 12792 | "Connection: keep-alive\r\n" |
| 12793 | "Authorization: auth_token\r\n\r\n"); |
| 12794 | |
| 12795 | const MockRead kServerChallenge( |
| 12796 | "HTTP/1.1 401 Unauthorized\r\n" |
| 12797 | "WWW-Authenticate: Mock realm=server\r\n" |
| 12798 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12799 | "Content-Length: 14\r\n\r\n" |
| 12800 | "Unauthorized\r\n"); |
| 12801 | const MockRead kSuccess( |
| 12802 | "HTTP/1.1 200 OK\r\n" |
| 12803 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12804 | "Content-Length: 3\r\n\r\n" |
| 12805 | "Yes"); |
| 12806 | |
| 12807 | MockWrite writes[] = { |
| 12808 | // First round |
| 12809 | kGet, |
| 12810 | // Second round |
| 12811 | kGetAuth, |
| 12812 | // Third round |
| 12813 | kGetAuth, |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 12814 | // Fourth round |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12815 | kGetAuth, |
| 12816 | // Competing request |
| 12817 | kGet, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12818 | }; |
| 12819 | MockRead reads[] = { |
| 12820 | // First round |
| 12821 | kServerChallenge, |
| 12822 | // Second round |
| 12823 | kServerChallenge, |
| 12824 | // Third round |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 12825 | kServerChallenge, |
| 12826 | // Fourth round |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12827 | kSuccess, |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12828 | // Competing response |
| 12829 | kSuccess, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12830 | }; |
| 12831 | StaticSocketDataProvider data_provider(reads, arraysize(reads), |
| 12832 | writes, arraysize(writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12833 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12834 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 12835 | const char kSocketGroup[] = "www.example.com:80"; |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12836 | |
| 12837 | // First round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12838 | auth_handler->SetGenerateExpectation(false, OK); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12839 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12840 | if (rv == ERR_IO_PENDING) |
| 12841 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12842 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12843 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12844 | ASSERT_TRUE(response); |
| 12845 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12846 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12847 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 12848 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12849 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12850 | // In between rounds, another request comes in for the same domain. |
| 12851 | // It should not be able to grab the TCP socket that trans has already |
| 12852 | // claimed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12853 | HttpNetworkTransaction trans_compete(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12854 | TestCompletionCallback callback_compete; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12855 | rv = trans_compete.Start(&request, callback_compete.callback(), |
| 12856 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12857 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12858 | // callback_compete.WaitForResult at this point would stall forever, |
| 12859 | // since the HttpNetworkTransaction does not release the request back to |
| 12860 | // the pool until after authentication completes. |
| 12861 | |
| 12862 | // Second round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12863 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12864 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12865 | if (rv == ERR_IO_PENDING) |
| 12866 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12867 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12868 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12869 | ASSERT_TRUE(response); |
| 12870 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12871 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12872 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 12873 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12874 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12875 | // Third round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12876 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12877 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12878 | if (rv == ERR_IO_PENDING) |
| 12879 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12880 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12881 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12882 | ASSERT_TRUE(response); |
| 12883 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12884 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12885 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 12886 | auth_handler->state()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 12887 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12888 | // Fourth round of authentication, which completes successfully. |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 12889 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12890 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 12891 | if (rv == ERR_IO_PENDING) |
| 12892 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12893 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12894 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12895 | ASSERT_TRUE(response); |
| 12896 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12897 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12898 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12899 | // In WAIT_FOR_CHALLENGE, although in reality the auth handler is done. A real |
| 12900 | // auth handler should transition to a DONE state in concert with the remote |
| 12901 | // server. But that's not something we can test here with a mock handler. |
| 12902 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_CHALLENGE, |
| 12903 | auth_handler->state()); |
| 12904 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12905 | // Read the body since the fourth round was successful. This will also |
| 12906 | // release the socket back to the pool. |
| 12907 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(50)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12908 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12909 | if (rv == ERR_IO_PENDING) |
| 12910 | rv = callback.WaitForResult(); |
| 12911 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12912 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12913 | EXPECT_EQ(0, rv); |
| 12914 | // There are still 0 idle sockets, since the trans_compete transaction |
| 12915 | // will be handed it immediately after trans releases it to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12916 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12917 | |
| 12918 | // The competing request can now finish. Wait for the headers and then |
| 12919 | // read the body. |
| 12920 | rv = callback_compete.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12921 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12922 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12923 | if (rv == ERR_IO_PENDING) |
| 12924 | rv = callback.WaitForResult(); |
| 12925 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12926 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12927 | EXPECT_EQ(0, rv); |
| 12928 | |
| 12929 | // Finally, the socket is released to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12930 | EXPECT_EQ(1, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12931 | } |
| 12932 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12933 | // This tests the case that a request is issued via http instead of spdy after |
| 12934 | // npn is negotiated. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12935 | TEST_F(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12936 | HttpRequestInfo request; |
| 12937 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12938 | request.url = GURL("https://www.example.org/"); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12939 | |
| 12940 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12941 | MockWrite( |
| 12942 | "GET / HTTP/1.1\r\n" |
| 12943 | "Host: www.example.org\r\n" |
| 12944 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12945 | }; |
| 12946 | |
| 12947 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12948 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12949 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12950 | MockRead("\r\n"), |
| 12951 | MockRead("hello world"), |
| 12952 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12953 | }; |
| 12954 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12955 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12956 | ssl.next_proto = kProtoHTTP11; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12957 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12958 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12959 | |
| 12960 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 12961 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12962 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12963 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12964 | TestCompletionCallback callback; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12965 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12966 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12967 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12968 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12969 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12970 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12971 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12972 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12973 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12974 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12975 | ASSERT_TRUE(response); |
| 12976 | ASSERT_TRUE(response->headers); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12977 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12978 | |
| 12979 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12980 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12981 | EXPECT_EQ("hello world", response_data); |
| 12982 | |
| 12983 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12984 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12985 | } |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12986 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12987 | // Simulate the SSL handshake completing with an NPN negotiation followed by an |
| 12988 | // immediate server closing of the socket. |
| 12989 | // Regression test for https://crbug.com/46369. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12990 | TEST_F(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12991 | HttpRequestInfo request; |
| 12992 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12993 | request.url = GURL("https://www.example.org/"); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12994 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12995 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12996 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12997 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12998 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12999 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13000 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13001 | MockWrite spdy_writes[] = {CreateMockWrite(req, 1)}; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13002 | |
| 13003 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13004 | MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13005 | }; |
| 13006 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13007 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 13008 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13009 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13010 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13011 | TestCompletionCallback callback; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13012 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13013 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13014 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13015 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13016 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13017 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13018 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13019 | } |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 13020 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13021 | // A subclass of HttpAuthHandlerMock that records the request URL when |
| 13022 | // it gets it. This is needed since the auth handler may get destroyed |
| 13023 | // before we get a chance to query it. |
| 13024 | class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock { |
| 13025 | public: |
| 13026 | explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {} |
| 13027 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13028 | ~UrlRecordingHttpAuthHandlerMock() override {} |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13029 | |
| 13030 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13031 | int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 13032 | const HttpRequestInfo* request, |
| 13033 | const CompletionCallback& callback, |
| 13034 | std::string* auth_token) override { |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13035 | *url_ = request->url; |
| 13036 | return HttpAuthHandlerMock::GenerateAuthTokenImpl( |
| 13037 | credentials, request, callback, auth_token); |
| 13038 | } |
| 13039 | |
| 13040 | private: |
| 13041 | GURL* url_; |
| 13042 | }; |
| 13043 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13044 | // Test that if we cancel the transaction as the connection is completing, that |
| 13045 | // everything tears down correctly. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13046 | TEST_F(HttpNetworkTransactionTest, SimpleCancel) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13047 | // Setup everything about the connection to complete synchronously, so that |
| 13048 | // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
| 13049 | // for is the callback from the HttpStreamRequest. |
| 13050 | // Then cancel the transaction. |
| 13051 | // Verify that we don't crash. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 13052 | MockConnect mock_connect(SYNCHRONOUS, OK); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13053 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13054 | MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), |
| 13055 | MockRead(SYNCHRONOUS, "hello world"), |
| 13056 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13057 | }; |
| 13058 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13059 | HttpRequestInfo request; |
| 13060 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13061 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13062 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13063 | session_deps_.host_resolver->set_synchronous_mode(true); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13064 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13065 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13066 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13067 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13068 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 13069 | data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13070 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13071 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13072 | TestCompletionCallback callback; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13073 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13074 | BoundTestNetLog log; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13075 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13076 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13077 | trans.reset(); // Cancel the transaction here. |
| 13078 | |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 13079 | base::RunLoop().RunUntilIdle(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 13080 | } |
| 13081 | |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13082 | // Test that if a transaction is cancelled after receiving the headers, the |
| 13083 | // stream is drained properly and added back to the socket pool. The main |
| 13084 | // purpose of this test is to make sure that an HttpStreamParser can be read |
| 13085 | // from after the HttpNetworkTransaction and the objects it owns have been |
| 13086 | // deleted. |
| 13087 | // See http://crbug.com/368418 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13088 | TEST_F(HttpNetworkTransactionTest, CancelAfterHeaders) { |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13089 | MockRead data_reads[] = { |
| 13090 | MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"), |
| 13091 | MockRead(ASYNC, "Content-Length: 2\r\n"), |
| 13092 | MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"), |
| 13093 | MockRead(ASYNC, "1"), |
| 13094 | // 2 async reads are necessary to trigger a ReadResponseBody call after the |
| 13095 | // HttpNetworkTransaction has been deleted. |
| 13096 | MockRead(ASYNC, "2"), |
| 13097 | MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this. |
| 13098 | }; |
| 13099 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 13100 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13101 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13102 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13103 | |
| 13104 | { |
| 13105 | HttpRequestInfo request; |
| 13106 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13107 | request.url = GURL("http://www.example.org/"); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13108 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13109 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13110 | TestCompletionCallback callback; |
| 13111 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13112 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13113 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13114 | callback.WaitForResult(); |
| 13115 | |
| 13116 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13117 | ASSERT_TRUE(response); |
| 13118 | EXPECT_TRUE(response->headers); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13119 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13120 | |
| 13121 | // The transaction and HttpRequestInfo are deleted. |
| 13122 | } |
| 13123 | |
| 13124 | // Let the HttpResponseBodyDrainer drain the socket. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 13125 | base::RunLoop().RunUntilIdle(); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13126 | |
| 13127 | // Socket should now be idle, waiting to be reused. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13128 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13129 | } |
| 13130 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13131 | // Test a basic GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13132 | TEST_F(HttpNetworkTransactionTest, ProxyGet) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 13133 | session_deps_.proxy_service = |
| 13134 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13135 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13136 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13137 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13138 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13139 | HttpRequestInfo request; |
| 13140 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13141 | request.url = GURL("http://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13142 | |
| 13143 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13144 | MockWrite( |
| 13145 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 13146 | "Host: www.example.org\r\n" |
| 13147 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13148 | }; |
| 13149 | |
| 13150 | MockRead data_reads1[] = { |
| 13151 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13152 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 13153 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13154 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13155 | }; |
| 13156 | |
| 13157 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 13158 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13159 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13160 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13161 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13162 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13163 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13164 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13165 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13166 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 13167 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13168 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13169 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13170 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13171 | |
| 13172 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13173 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13174 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13175 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13176 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13177 | |
| 13178 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 13179 | EXPECT_EQ(200, response->headers->response_code()); |
| 13180 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 13181 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 13182 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 13183 | HostPortPair::FromString("myproxy:70")), |
| 13184 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13185 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 13186 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 13187 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13188 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13189 | |
| 13190 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13191 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13192 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 13193 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13194 | } |
| 13195 | |
| 13196 | // Test a basic HTTPS GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13197 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGet) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 13198 | session_deps_.proxy_service = |
| 13199 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13200 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13201 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13202 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13203 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13204 | HttpRequestInfo request; |
| 13205 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13206 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13207 | |
| 13208 | // Since we have proxy, should try to establish tunnel. |
| 13209 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13210 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 13211 | "Host: www.example.org:443\r\n" |
| 13212 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13213 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13214 | MockWrite("GET / HTTP/1.1\r\n" |
| 13215 | "Host: www.example.org\r\n" |
| 13216 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13217 | }; |
| 13218 | |
| 13219 | MockRead data_reads1[] = { |
| 13220 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 13221 | |
| 13222 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13223 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 13224 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13225 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13226 | }; |
| 13227 | |
| 13228 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 13229 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13230 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13231 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13232 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13233 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13234 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13235 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13236 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13237 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13238 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13239 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 13240 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13241 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13242 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13243 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13244 | |
| 13245 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13246 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 13247 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 13248 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13249 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13250 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 13251 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13252 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 13253 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13254 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 13255 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13256 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13257 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13258 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13259 | |
| 13260 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 13261 | EXPECT_EQ(200, response->headers->response_code()); |
| 13262 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 13263 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 13264 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 13265 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 13266 | HostPortPair::FromString("myproxy:70")), |
| 13267 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13268 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 13269 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 13270 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13271 | |
| 13272 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13273 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13274 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 13275 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13276 | } |
| 13277 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13278 | // Test a basic HTTPS GET request through a proxy, connecting to an IPv6 |
| 13279 | // literal host. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13280 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetIPv6) { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13281 | session_deps_.proxy_service = |
| 13282 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 13283 | BoundTestNetLog log; |
| 13284 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13285 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13286 | |
| 13287 | HttpRequestInfo request; |
| 13288 | request.method = "GET"; |
| 13289 | request.url = GURL("https://[::1]:443/"); |
| 13290 | |
| 13291 | // Since we have proxy, should try to establish tunnel. |
| 13292 | MockWrite data_writes1[] = { |
| 13293 | MockWrite("CONNECT [::1]:443 HTTP/1.1\r\n" |
| 13294 | "Host: [::1]:443\r\n" |
| 13295 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 13296 | |
| 13297 | MockWrite("GET / HTTP/1.1\r\n" |
| 13298 | "Host: [::1]\r\n" |
| 13299 | "Connection: keep-alive\r\n\r\n"), |
| 13300 | }; |
| 13301 | |
| 13302 | MockRead data_reads1[] = { |
| 13303 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 13304 | |
| 13305 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13306 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 13307 | MockRead("Content-Length: 100\r\n\r\n"), |
| 13308 | MockRead(SYNCHRONOUS, OK), |
| 13309 | }; |
| 13310 | |
| 13311 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 13312 | data_writes1, arraysize(data_writes1)); |
| 13313 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 13314 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 13315 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13316 | |
| 13317 | TestCompletionCallback callback1; |
| 13318 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13319 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13320 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13321 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13322 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13323 | |
| 13324 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13325 | EXPECT_THAT(rv, IsOk()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13326 | TestNetLogEntry::List entries; |
| 13327 | log.GetEntries(&entries); |
| 13328 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13329 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 13330 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13331 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13332 | entries, pos, |
| 13333 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 13334 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13335 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13336 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13337 | ASSERT_TRUE(response); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13338 | |
| 13339 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 13340 | EXPECT_EQ(200, response->headers->response_code()); |
| 13341 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 13342 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 13343 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 13344 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 13345 | HostPortPair::FromString("myproxy:70")), |
| 13346 | response->proxy_server); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13347 | |
| 13348 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13349 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13350 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 13351 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 13352 | } |
| 13353 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13354 | // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 13355 | // while establishing the tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13356 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 13357 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13358 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13359 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13360 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13361 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13362 | HttpRequestInfo request; |
| 13363 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13364 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13365 | |
| 13366 | // Since we have proxy, should try to establish tunnel. |
| 13367 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13368 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 13369 | "Host: www.example.org:443\r\n" |
| 13370 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13371 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13372 | MockWrite("GET / HTTP/1.1\r\n" |
| 13373 | "Host: www.example.org\r\n" |
| 13374 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13375 | }; |
| 13376 | |
| 13377 | MockRead data_reads1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13378 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13379 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13380 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13381 | }; |
| 13382 | |
| 13383 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 13384 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13385 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13386 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13387 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13388 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13389 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13390 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13391 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13392 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13393 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13394 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13395 | |
| 13396 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13397 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 13398 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 13399 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13400 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13401 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 13402 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13403 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 13404 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13405 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 13406 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13407 | } |
| 13408 | |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13409 | // Test for crbug.com/55424. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13410 | TEST_F(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13411 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13412 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13413 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13414 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13415 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13416 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13417 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13418 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13419 | }; |
| 13420 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13421 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 13422 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13423 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13424 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13425 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13426 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13427 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13428 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13429 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13430 | |
| 13431 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13432 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 13433 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 13434 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13435 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 13436 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13437 | |
| 13438 | HttpRequestInfo request; |
| 13439 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13440 | request.url = GURL("https://www.example.org/"); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13441 | |
| 13442 | // This is the important line that marks this as a preconnect. |
| 13443 | request.motivation = HttpRequestInfo::PRECONNECT_MOTIVATED; |
| 13444 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13445 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13446 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13447 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13448 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13449 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13450 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13451 | } |
| 13452 | |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13453 | // Given a net error, cause that error to be returned from the first Write() |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13454 | // call and verify that the HttpNetworkTransaction fails with that error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13455 | void HttpNetworkTransactionTest::CheckErrorIsPassedBack( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13456 | int error, IoMode mode) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13457 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13458 | request_info.url = GURL("https://www.example.com/"); |
| 13459 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13460 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13461 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13462 | SSLSocketDataProvider ssl_data(mode, OK); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13463 | MockWrite data_writes[] = { |
| 13464 | MockWrite(mode, error), |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13465 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13466 | StaticSocketDataProvider data(NULL, 0, data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13467 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13468 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13469 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13470 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13471 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13472 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13473 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13474 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13475 | if (rv == ERR_IO_PENDING) |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13476 | rv = callback.WaitForResult(); |
| 13477 | ASSERT_EQ(error, rv); |
| 13478 | } |
| 13479 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13480 | TEST_F(HttpNetworkTransactionTest, SSLWriteCertError) { |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13481 | // Just check a grab bag of cert errors. |
| 13482 | static const int kErrors[] = { |
| 13483 | ERR_CERT_COMMON_NAME_INVALID, |
| 13484 | ERR_CERT_AUTHORITY_INVALID, |
| 13485 | ERR_CERT_DATE_INVALID, |
| 13486 | }; |
| 13487 | for (size_t i = 0; i < arraysize(kErrors); i++) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13488 | CheckErrorIsPassedBack(kErrors[i], ASYNC); |
| 13489 | CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13490 | } |
| 13491 | } |
| 13492 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13493 | // Ensure that a client certificate is removed from the SSL client auth |
| 13494 | // cache when: |
| 13495 | // 1) No proxy is involved. |
| 13496 | // 2) TLS False Start is disabled. |
| 13497 | // 3) The initial TLS handshake requests a client certificate. |
| 13498 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13499 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_NoFalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13500 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13501 | request_info.url = GURL("https://www.example.com/"); |
| 13502 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13503 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13504 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13505 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13506 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13507 | |
| 13508 | // [ssl_]data1 contains the data for the first SSL handshake. When a |
| 13509 | // CertificateRequest is received for the first time, the handshake will |
| 13510 | // be aborted to allow the caller to provide a certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13511 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13512 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13513 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13514 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13515 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13516 | |
| 13517 | // [ssl_]data2 contains the data for the second SSL handshake. When TLS |
| 13518 | // False Start is not being used, the result of the SSL handshake will be |
| 13519 | // returned as part of the SSLClientSocket::Connect() call. This test |
| 13520 | // matches the result of a server sending a handshake_failure alert, |
| 13521 | // rather than a Finished message, because it requires a client |
| 13522 | // certificate and none was supplied. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13523 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13524 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13525 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13526 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13527 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13528 | |
| 13529 | // [ssl_]data3 contains the data for the third SSL handshake. When a |
| 13530 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 13531 | // HttpNetworkTransaction will attempt to fallback to TLSv1.1 if the previous |
| 13532 | // connection was attempted with TLSv1.2. This is transparent to the caller |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13533 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 13534 | // requiring a client certificate, this fallback handshake should also |
| 13535 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13536 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13537 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13538 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13539 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13540 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13541 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13542 | // [ssl_]data4 contains the data for the fourth SSL handshake. When a |
| 13543 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 13544 | // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous |
| 13545 | // connection was attempted with TLSv1.1. This is transparent to the caller |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13546 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 13547 | // requiring a client certificate, this fallback handshake should also |
| 13548 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13549 | SSLSocketDataProvider ssl_data4(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13550 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13551 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13552 | StaticSocketDataProvider data4(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13553 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13554 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13555 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13556 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13557 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13558 | // Begin the SSL handshake with the peer. This consumes ssl_data1. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13559 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13560 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13561 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13562 | |
| 13563 | // Complete the SSL handshake, which should abort due to requiring a |
| 13564 | // client certificate. |
| 13565 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13566 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13567 | |
| 13568 | // Indicate that no certificate should be supplied. From the perspective |
| 13569 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 13570 | // certificate, so this is the same as supply a |
| 13571 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13572 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13573 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13574 | |
| 13575 | // Ensure the certificate was added to the client auth cache before |
| 13576 | // allowing the connection to continue restarting. |
| 13577 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13578 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13579 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13580 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13581 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13582 | |
| 13583 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13584 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 13585 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13586 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13587 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13588 | |
| 13589 | // Ensure that the client certificate is removed from the cache on a |
| 13590 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13591 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13592 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13593 | } |
| 13594 | |
| 13595 | // Ensure that a client certificate is removed from the SSL client auth |
| 13596 | // cache when: |
| 13597 | // 1) No proxy is involved. |
| 13598 | // 2) TLS False Start is enabled. |
| 13599 | // 3) The initial TLS handshake requests a client certificate. |
| 13600 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13601 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_FalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13602 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13603 | request_info.url = GURL("https://www.example.com/"); |
| 13604 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13605 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13606 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13607 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13608 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13609 | |
| 13610 | // When TLS False Start is used, SSLClientSocket::Connect() calls will |
| 13611 | // return successfully after reading up to the peer's Certificate message. |
| 13612 | // This is to allow the caller to call SSLClientSocket::Write(), which can |
| 13613 | // enqueue application data to be sent in the same packet as the |
| 13614 | // ChangeCipherSpec and Finished messages. |
| 13615 | // The actual handshake will be finished when SSLClientSocket::Read() is |
| 13616 | // called, which expects to process the peer's ChangeCipherSpec and |
| 13617 | // Finished messages. If there was an error negotiating with the peer, |
| 13618 | // such as due to the peer requiring a client certificate when none was |
| 13619 | // supplied, the alert sent by the peer won't be processed until Read() is |
| 13620 | // called. |
| 13621 | |
| 13622 | // Like the non-False Start case, when a client certificate is requested by |
| 13623 | // the peer, the handshake is aborted during the Connect() call. |
| 13624 | // [ssl_]data1 represents the initial SSL handshake with the peer. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13625 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13626 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13627 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13628 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13629 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13630 | |
| 13631 | // When a client certificate is supplied, Connect() will not be aborted |
| 13632 | // when the peer requests the certificate. Instead, the handshake will |
| 13633 | // artificially succeed, allowing the caller to write the HTTP request to |
| 13634 | // the socket. The handshake messages are not processed until Read() is |
| 13635 | // called, which then detects that the handshake was aborted, due to the |
| 13636 | // peer sending a handshake_failure because it requires a client |
| 13637 | // certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13638 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13639 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13640 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13641 | MockRead data2_reads[] = { |
| 13642 | MockRead(ASYNC /* async */, ERR_SSL_PROTOCOL_ERROR), |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13643 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13644 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13645 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13646 | |
| 13647 | // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13648 | // the data for the SSL handshake once the TLSv1.1 connection falls back to |
| 13649 | // TLSv1. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13650 | SSLSocketDataProvider ssl_data3(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13651 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13652 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13653 | StaticSocketDataProvider data3(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13654 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13655 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13656 | // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection |
| 13657 | // falls back to SSLv3. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13658 | SSLSocketDataProvider ssl_data4(ASYNC, OK); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13659 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13660 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13661 | StaticSocketDataProvider data4(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13662 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13663 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 13664 | // Need one more if TLSv1.2 is enabled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13665 | SSLSocketDataProvider ssl_data5(ASYNC, OK); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 13666 | ssl_data5.cert_request_info = cert_request.get(); |
| 13667 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13668 | StaticSocketDataProvider data5(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 13669 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 13670 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13671 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13672 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13673 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13674 | // Begin the initial SSL handshake. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13675 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13676 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13677 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13678 | |
| 13679 | // Complete the SSL handshake, which should abort due to requiring a |
| 13680 | // client certificate. |
| 13681 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13682 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13683 | |
| 13684 | // Indicate that no certificate should be supplied. From the perspective |
| 13685 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 13686 | // certificate, so this is the same as supply a |
| 13687 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13688 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13689 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13690 | |
| 13691 | // Ensure the certificate was added to the client auth cache before |
| 13692 | // allowing the connection to continue restarting. |
| 13693 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13694 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13695 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13696 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13697 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13698 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13699 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13700 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 13701 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13702 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13703 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13704 | |
| 13705 | // Ensure that the client certificate is removed from the cache on a |
| 13706 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13707 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13708 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13709 | } |
| 13710 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13711 | // Ensure that a client certificate is removed from the SSL client auth |
| 13712 | // cache when: |
| 13713 | // 1) An HTTPS proxy is involved. |
| 13714 | // 3) The HTTPS proxy requests a client certificate. |
| 13715 | // 4) The client supplies an invalid/unacceptable certificate for the |
| 13716 | // proxy. |
| 13717 | // The test is repeated twice, first for connecting to an HTTPS endpoint, |
| 13718 | // then for connecting to an HTTP endpoint. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13719 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 13720 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13721 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13722 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13723 | |
| 13724 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13725 | cert_request->host_and_port = HostPortPair("proxy", 70); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13726 | |
| 13727 | // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of |
| 13728 | // [ssl_]data[1-3]. Rather than represending the endpoint |
| 13729 | // (www.example.com:443), they represent failures with the HTTPS proxy |
| 13730 | // (proxy:70). |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13731 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13732 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13733 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13734 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13735 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13736 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13737 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13738 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13739 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13740 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13741 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13742 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13743 | // TODO(wtc): find out why this unit test doesn't need [ssl_]data3. |
| 13744 | #if 0 |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13745 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13746 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13747 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13748 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13749 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13750 | #endif |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13751 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13752 | HttpRequestInfo requests[2]; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13753 | requests[0].url = GURL("https://www.example.com/"); |
| 13754 | requests[0].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13755 | requests[0].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13756 | |
| 13757 | requests[1].url = GURL("http://www.example.com/"); |
| 13758 | requests[1].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13759 | requests[1].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13760 | |
| 13761 | for (size_t i = 0; i < arraysize(requests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13762 | session_deps_.socket_factory->ResetNextMockIndexes(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13763 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13764 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13765 | |
| 13766 | // Begin the SSL handshake with the proxy. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13767 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13768 | int rv = trans.Start(&requests[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13769 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13770 | |
| 13771 | // Complete the SSL handshake, which should abort due to requiring a |
| 13772 | // client certificate. |
| 13773 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13774 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13775 | |
| 13776 | // Indicate that no certificate should be supplied. From the perspective |
| 13777 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 13778 | // certificate, so this is the same as supply a |
| 13779 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13780 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13781 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13782 | |
| 13783 | // Ensure the certificate was added to the client auth cache before |
| 13784 | // allowing the connection to continue restarting. |
| 13785 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13786 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13787 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13788 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13789 | ASSERT_FALSE(client_cert); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13790 | // Ensure the certificate was NOT cached for the endpoint. This only |
| 13791 | // applies to HTTPS requests, but is fine to check for HTTP requests. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13792 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13793 | HostPortPair("www.example.com", 443), &client_cert, |
| 13794 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13795 | |
| 13796 | // Restart the handshake. This will consume ssl_data2, which fails, and |
| 13797 | // then consume ssl_data3, which should also fail. The result code is |
| 13798 | // checked against what ssl_data3 should return. |
| 13799 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13800 | ASSERT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13801 | |
| 13802 | // Now that the new handshake has failed, ensure that the client |
| 13803 | // certificate was removed from the client auth cache. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13804 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13805 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13806 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13807 | HostPortPair("www.example.com", 443), &client_cert, |
| 13808 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13809 | } |
| 13810 | } |
| 13811 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13812 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPooling) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13813 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13814 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13815 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13816 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13817 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13818 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13819 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13820 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13821 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13822 | SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13823 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13824 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13825 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13826 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13827 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13828 | SpdySerializedFrame host1_resp_body( |
| 13829 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13830 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13831 | SpdySerializedFrame host2_resp_body( |
| 13832 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13833 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13834 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 13835 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13836 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13837 | }; |
| 13838 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 13839 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13840 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13841 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 13842 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13843 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13844 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 13845 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13846 | HttpRequestInfo request1; |
| 13847 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13848 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13849 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13850 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13851 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13852 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13853 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13854 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13855 | |
| 13856 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13857 | ASSERT_TRUE(response); |
| 13858 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13859 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13860 | |
| 13861 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13862 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13863 | EXPECT_EQ("hello!", response_data); |
| 13864 | |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13865 | // Preload mail.example.com into HostCache. |
| 13866 | HostPortPair host_port("mail.example.com", 443); |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 13867 | HostResolver::RequestInfo resolve_info(host_port); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13868 | AddressList ignored; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 13869 | std::unique_ptr<HostResolver::Request> request; |
| 13870 | rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 13871 | &ignored, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13872 | &request, NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13873 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 13874 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13875 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13876 | |
| 13877 | HttpRequestInfo request2; |
| 13878 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13879 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13880 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13881 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13882 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13883 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13884 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13885 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13886 | |
| 13887 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13888 | ASSERT_TRUE(response); |
| 13889 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13890 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13891 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13892 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13893 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13894 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13895 | } |
| 13896 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13897 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) { |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13898 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13899 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13900 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13901 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13902 | AddSSLSocketData(); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13903 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13904 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13905 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13906 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13907 | SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13908 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13909 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13910 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13911 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13912 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13913 | SpdySerializedFrame host1_resp_body( |
| 13914 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13915 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13916 | SpdySerializedFrame host2_resp_body( |
| 13917 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13918 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13919 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 13920 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13921 | MockRead(ASYNC, 0, 6), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13922 | }; |
| 13923 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 13924 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13925 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13926 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 13927 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13928 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13929 | |
| 13930 | TestCompletionCallback callback; |
| 13931 | HttpRequestInfo request1; |
| 13932 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13933 | request1.url = GURL("https://www.example.org/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13934 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13935 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13936 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13937 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13938 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13939 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13940 | |
| 13941 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13942 | ASSERT_TRUE(response); |
| 13943 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13944 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13945 | |
| 13946 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13947 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13948 | EXPECT_EQ("hello!", response_data); |
| 13949 | |
| 13950 | HttpRequestInfo request2; |
| 13951 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13952 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13953 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13954 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13955 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13956 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13957 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13958 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13959 | |
| 13960 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13961 | ASSERT_TRUE(response); |
| 13962 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13963 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13964 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13965 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13966 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13967 | EXPECT_EQ("hello!", response_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13968 | } |
| 13969 | |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 13970 | // Regression test for https://crbug.com/546991. |
| 13971 | // The server might not be able to serve an IP pooled request, and might send a |
| 13972 | // 421 Misdirected Request response status to indicate this. |
| 13973 | // HttpNetworkTransaction should reset the request and retry without IP pooling. |
| 13974 | TEST_F(HttpNetworkTransactionTest, RetryWithoutConnectionPooling) { |
| 13975 | // Two hosts resolve to the same IP address. |
| 13976 | const std::string ip_addr = "1.2.3.4"; |
| 13977 | IPAddress ip; |
| 13978 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 13979 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 13980 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13981 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 13982 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 13983 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 13984 | |
| 13985 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13986 | |
| 13987 | // Two requests on the first connection. |
| 13988 | SpdySerializedFrame req1( |
| 13989 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 13990 | spdy_util_.UpdateWithStreamDestruction(1); |
| 13991 | SpdySerializedFrame req2( |
| 13992 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
| 13993 | SpdySerializedFrame rst( |
| 13994 | spdy_util_.ConstructSpdyRstStream(3, ERROR_CODE_CANCEL)); |
| 13995 | MockWrite writes1[] = { |
| 13996 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 13997 | CreateMockWrite(rst, 6), |
| 13998 | }; |
| 13999 | |
| 14000 | // The first one succeeds, the second gets error 421 Misdirected Request. |
| 14001 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 14002 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 14003 | SpdyHeaderBlock response_headers; |
Bence Béky | bda8295 | 2017-10-02 17:35:27 | [diff] [blame] | 14004 | response_headers[kHttp2StatusHeader] = "421"; |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14005 | SpdySerializedFrame resp2( |
| 14006 | spdy_util_.ConstructSpdyReply(3, std::move(response_headers))); |
| 14007 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 14008 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 14009 | |
| 14010 | MockConnect connect1(ASYNC, OK, peer_addr); |
| 14011 | SequencedSocketData data1(connect1, reads1, arraysize(reads1), writes1, |
| 14012 | arraysize(writes1)); |
| 14013 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 14014 | |
| 14015 | AddSSLSocketData(); |
| 14016 | |
| 14017 | // Retry the second request on a second connection. |
| 14018 | SpdyTestUtil spdy_util2; |
| 14019 | SpdySerializedFrame req3( |
| 14020 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 14021 | MockWrite writes2[] = { |
| 14022 | CreateMockWrite(req3, 0), |
| 14023 | }; |
| 14024 | |
| 14025 | SpdySerializedFrame resp3(spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 14026 | SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 14027 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 14028 | MockRead(ASYNC, 0, 3)}; |
| 14029 | |
| 14030 | MockConnect connect2(ASYNC, OK, peer_addr); |
| 14031 | SequencedSocketData data2(connect2, reads2, arraysize(reads2), writes2, |
| 14032 | arraysize(writes2)); |
| 14033 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 14034 | |
| 14035 | AddSSLSocketData(); |
| 14036 | |
| 14037 | // Preload mail.example.org into HostCache. |
| 14038 | HostPortPair host_port("mail.example.org", 443); |
| 14039 | HostResolver::RequestInfo resolve_info(host_port); |
| 14040 | AddressList ignored; |
| 14041 | std::unique_ptr<HostResolver::Request> request; |
| 14042 | TestCompletionCallback callback; |
| 14043 | int rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 14044 | &ignored, callback.callback(), |
| 14045 | &request, NetLogWithSource()); |
| 14046 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14047 | rv = callback.WaitForResult(); |
| 14048 | EXPECT_THAT(rv, IsOk()); |
| 14049 | |
| 14050 | HttpRequestInfo request1; |
| 14051 | request1.method = "GET"; |
| 14052 | request1.url = GURL("https://www.example.org/"); |
| 14053 | request1.load_flags = 0; |
| 14054 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 14055 | |
| 14056 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 14057 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14058 | rv = callback.WaitForResult(); |
| 14059 | EXPECT_THAT(rv, IsOk()); |
| 14060 | |
| 14061 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 14062 | ASSERT_TRUE(response); |
| 14063 | ASSERT_TRUE(response->headers); |
| 14064 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 14065 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 14066 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 14067 | std::string response_data; |
| 14068 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 14069 | EXPECT_EQ("hello!", response_data); |
| 14070 | |
| 14071 | HttpRequestInfo request2; |
| 14072 | request2.method = "GET"; |
| 14073 | request2.url = GURL("https://mail.example.org/"); |
| 14074 | request2.load_flags = 0; |
| 14075 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 14076 | |
| 14077 | BoundTestNetLog log; |
| 14078 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 14079 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14080 | rv = callback.WaitForResult(); |
| 14081 | EXPECT_THAT(rv, IsOk()); |
| 14082 | |
| 14083 | response = trans2.GetResponseInfo(); |
| 14084 | ASSERT_TRUE(response); |
| 14085 | ASSERT_TRUE(response->headers); |
| 14086 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 14087 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 14088 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 14089 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 14090 | EXPECT_EQ("hello!", response_data); |
| 14091 | |
| 14092 | TestNetLogEntry::List entries; |
| 14093 | log.GetEntries(&entries); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14094 | ExpectLogContainsSomewhere( |
| 14095 | entries, 0, NetLogEventType::HTTP_TRANSACTION_RESTART_MISDIRECTED_REQUEST, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14096 | NetLogEventPhase::NONE); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14097 | } |
| 14098 | |
| 14099 | // Test that HTTP 421 responses are properly returned to the caller if received |
| 14100 | // on the retry as well. HttpNetworkTransaction should not infinite loop or lose |
| 14101 | // portions of the response. |
| 14102 | TEST_F(HttpNetworkTransactionTest, ReturnHTTP421OnRetry) { |
| 14103 | // Two hosts resolve to the same IP address. |
| 14104 | const std::string ip_addr = "1.2.3.4"; |
| 14105 | IPAddress ip; |
| 14106 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 14107 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 14108 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14109 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14110 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 14111 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 14112 | |
| 14113 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14114 | |
| 14115 | // Two requests on the first connection. |
| 14116 | SpdySerializedFrame req1( |
| 14117 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 14118 | spdy_util_.UpdateWithStreamDestruction(1); |
| 14119 | SpdySerializedFrame req2( |
| 14120 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
| 14121 | SpdySerializedFrame rst( |
| 14122 | spdy_util_.ConstructSpdyRstStream(3, ERROR_CODE_CANCEL)); |
| 14123 | MockWrite writes1[] = { |
| 14124 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 14125 | CreateMockWrite(rst, 6), |
| 14126 | }; |
| 14127 | |
| 14128 | // The first one succeeds, the second gets error 421 Misdirected Request. |
| 14129 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 14130 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 14131 | SpdyHeaderBlock response_headers; |
Bence Béky | bda8295 | 2017-10-02 17:35:27 | [diff] [blame] | 14132 | response_headers[kHttp2StatusHeader] = "421"; |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14133 | SpdySerializedFrame resp2( |
| 14134 | spdy_util_.ConstructSpdyReply(3, response_headers.Clone())); |
| 14135 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 14136 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 14137 | |
| 14138 | MockConnect connect1(ASYNC, OK, peer_addr); |
| 14139 | SequencedSocketData data1(connect1, reads1, arraysize(reads1), writes1, |
| 14140 | arraysize(writes1)); |
| 14141 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 14142 | |
| 14143 | AddSSLSocketData(); |
| 14144 | |
| 14145 | // Retry the second request on a second connection. It returns 421 Misdirected |
| 14146 | // Retry again. |
| 14147 | SpdyTestUtil spdy_util2; |
| 14148 | SpdySerializedFrame req3( |
| 14149 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 14150 | MockWrite writes2[] = { |
| 14151 | CreateMockWrite(req3, 0), |
| 14152 | }; |
| 14153 | |
| 14154 | SpdySerializedFrame resp3( |
| 14155 | spdy_util2.ConstructSpdyReply(1, std::move(response_headers))); |
| 14156 | SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 14157 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 14158 | MockRead(ASYNC, 0, 3)}; |
| 14159 | |
| 14160 | MockConnect connect2(ASYNC, OK, peer_addr); |
| 14161 | SequencedSocketData data2(connect2, reads2, arraysize(reads2), writes2, |
| 14162 | arraysize(writes2)); |
| 14163 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 14164 | |
| 14165 | AddSSLSocketData(); |
| 14166 | |
| 14167 | // Preload mail.example.org into HostCache. |
| 14168 | HostPortPair host_port("mail.example.org", 443); |
| 14169 | HostResolver::RequestInfo resolve_info(host_port); |
| 14170 | AddressList ignored; |
| 14171 | std::unique_ptr<HostResolver::Request> request; |
| 14172 | TestCompletionCallback callback; |
| 14173 | int rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 14174 | &ignored, callback.callback(), |
| 14175 | &request, NetLogWithSource()); |
| 14176 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14177 | rv = callback.WaitForResult(); |
| 14178 | EXPECT_THAT(rv, IsOk()); |
| 14179 | |
| 14180 | HttpRequestInfo request1; |
| 14181 | request1.method = "GET"; |
| 14182 | request1.url = GURL("https://www.example.org/"); |
| 14183 | request1.load_flags = 0; |
| 14184 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 14185 | |
| 14186 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 14187 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14188 | rv = callback.WaitForResult(); |
| 14189 | EXPECT_THAT(rv, IsOk()); |
| 14190 | |
| 14191 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 14192 | ASSERT_TRUE(response); |
| 14193 | ASSERT_TRUE(response->headers); |
| 14194 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 14195 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 14196 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 14197 | std::string response_data; |
| 14198 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 14199 | EXPECT_EQ("hello!", response_data); |
| 14200 | |
| 14201 | HttpRequestInfo request2; |
| 14202 | request2.method = "GET"; |
| 14203 | request2.url = GURL("https://mail.example.org/"); |
| 14204 | request2.load_flags = 0; |
| 14205 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 14206 | |
| 14207 | BoundTestNetLog log; |
| 14208 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 14209 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14210 | rv = callback.WaitForResult(); |
| 14211 | EXPECT_THAT(rv, IsOk()); |
| 14212 | |
| 14213 | // After a retry, the 421 Misdirected Request is reported back up to the |
| 14214 | // caller. |
| 14215 | response = trans2.GetResponseInfo(); |
| 14216 | ASSERT_TRUE(response); |
| 14217 | ASSERT_TRUE(response->headers); |
| 14218 | EXPECT_EQ("HTTP/1.1 421", response->headers->GetStatusLine()); |
| 14219 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 14220 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 14221 | EXPECT_TRUE(response->ssl_info.cert); |
| 14222 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 14223 | EXPECT_EQ("hello!", response_data); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14224 | } |
| 14225 | |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 14226 | class OneTimeCachingHostResolver : public MockHostResolverBase { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14227 | public: |
| 14228 | explicit OneTimeCachingHostResolver(const HostPortPair& host_port) |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 14229 | : MockHostResolverBase(/* use_caching = */ true), host_port_(host_port) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14230 | ~OneTimeCachingHostResolver() override {} |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14231 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14232 | int ResolveFromCache(const RequestInfo& info, |
| 14233 | AddressList* addresses, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14234 | const NetLogWithSource& net_log) override { |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 14235 | int rv = MockHostResolverBase::ResolveFromCache(info, addresses, net_log); |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 14236 | if (rv == OK && info.host_port_pair().Equals(host_port_)) |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 14237 | GetHostCache()->clear(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14238 | return rv; |
| 14239 | } |
| 14240 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14241 | private: |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14242 | const HostPortPair host_port_; |
| 14243 | }; |
| 14244 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14245 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 14246 | UseIPConnectionPoolingWithHostCacheExpiration) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14247 | // Set up a special HttpNetworkSession with a OneTimeCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14248 | session_deps_.host_resolver = std::make_unique<OneTimeCachingHostResolver>( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14249 | HostPortPair("mail.example.com", 443)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14250 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14251 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 14252 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14253 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14254 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14255 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14256 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14257 | SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14258 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14259 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14260 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14261 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14262 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14263 | SpdySerializedFrame host1_resp_body( |
| 14264 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14265 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14266 | SpdySerializedFrame host2_resp_body( |
| 14267 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14268 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14269 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 14270 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14271 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14272 | }; |
| 14273 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 14274 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14275 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14276 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 14277 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14278 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14279 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 14280 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14281 | HttpRequestInfo request1; |
| 14282 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14283 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14284 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14285 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14286 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14287 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14288 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14289 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14290 | |
| 14291 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14292 | ASSERT_TRUE(response); |
| 14293 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14294 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14295 | |
| 14296 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14297 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14298 | EXPECT_EQ("hello!", response_data); |
| 14299 | |
| 14300 | // Preload cache entries into HostCache. |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14301 | HostResolver::RequestInfo resolve_info(HostPortPair("mail.example.com", 443)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14302 | AddressList ignored; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 14303 | std::unique_ptr<HostResolver::Request> request; |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 14304 | rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 14305 | &ignored, callback.callback(), |
| 14306 | &request, NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14307 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 14308 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14309 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14310 | |
| 14311 | HttpRequestInfo request2; |
| 14312 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14313 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14314 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14315 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14316 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14317 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14318 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14319 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14320 | |
| 14321 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14322 | ASSERT_TRUE(response); |
| 14323 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14324 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14325 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14326 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14327 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14328 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14329 | } |
| 14330 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14331 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14332 | const std::string https_url = "https://www.example.org:8080/"; |
| 14333 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14334 | |
| 14335 | // SPDY GET for HTTPS URL |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14336 | SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14337 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14338 | |
| 14339 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14340 | CreateMockWrite(req1, 0), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14341 | }; |
| 14342 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14343 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14344 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 14345 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 14346 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3)}; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14347 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14348 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 14349 | arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14350 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 14351 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14352 | |
| 14353 | // HTTP GET for the HTTP URL |
| 14354 | MockWrite writes2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14355 | MockWrite(ASYNC, 0, |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 14356 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14357 | "Host: www.example.org:8080\r\n" |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 14358 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14359 | }; |
| 14360 | |
| 14361 | MockRead reads2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14362 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 14363 | MockRead(ASYNC, 2, "hello"), |
| 14364 | MockRead(ASYNC, OK, 3), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14365 | }; |
| 14366 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14367 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 14368 | arraysize(writes2)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14369 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14370 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14371 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14372 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14373 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 14374 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14375 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14376 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14377 | |
| 14378 | // Start the first transaction to set up the SpdySession |
| 14379 | HttpRequestInfo request1; |
| 14380 | request1.method = "GET"; |
| 14381 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14382 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14383 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14384 | TestCompletionCallback callback1; |
| 14385 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14386 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 14387 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14388 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14389 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14390 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 14391 | |
| 14392 | // Now, start the HTTP request |
| 14393 | HttpRequestInfo request2; |
| 14394 | request2.method = "GET"; |
| 14395 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14396 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14397 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14398 | TestCompletionCallback callback2; |
| 14399 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14400 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 14401 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14402 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14403 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14404 | EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 14405 | } |
| 14406 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14407 | // Alternative service requires HTTP/2 (or SPDY), but HTTP/1.1 is negotiated |
| 14408 | // with the alternative server. That connection should not be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14409 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceNotOnHttp11) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14410 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 14411 | HostPortPair alternative("www.example.org", 444); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14412 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14413 | // Negotiate HTTP/1.1 with alternative. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14414 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14415 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14416 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14417 | |
| 14418 | // No data should be read from the alternative, because HTTP/1.1 is |
| 14419 | // negotiated. |
| 14420 | StaticSocketDataProvider data; |
| 14421 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14422 | |
| 14423 | // 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] | 14424 | // negotiated. In order to test this, a failed connection to the server is |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14425 | // mocked. This way the request relies on the alternate Job. |
| 14426 | StaticSocketDataProvider data_refused; |
| 14427 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 14428 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 14429 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14430 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14431 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 14432 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14433 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 14434 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 14435 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 14436 | http_server_properties->SetHttp2AlternativeService( |
| 14437 | server, alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14438 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14439 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 14440 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14441 | request.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14442 | request.url = GURL("https://www.example.org:443"); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14443 | TestCompletionCallback callback; |
| 14444 | |
| 14445 | // HTTP/2 (or SPDY) is required for alternative service, if HTTP/1.1 is |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14446 | // negotiated, the alternate Job should fail with ERR_ALPN_NEGOTIATION_FAILED. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14447 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14448 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_ALPN_NEGOTIATION_FAILED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14449 | } |
| 14450 | |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14451 | // 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] | 14452 | // server, and an alternate one to the alternative server. If the former |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14453 | // succeeds, the request should succeed, even if the latter fails because |
| 14454 | // HTTP/1.1 is negotiated which is insufficient for alternative service. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14455 | TEST_F(HttpNetworkTransactionTest, FailedAlternativeServiceIsNotUserVisible) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14456 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 14457 | HostPortPair alternative("www.example.org", 444); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14458 | |
| 14459 | // Negotiate HTTP/1.1 with alternative. |
| 14460 | SSLSocketDataProvider alternative_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14461 | alternative_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14462 | session_deps_.socket_factory->AddSSLSocketDataProvider(&alternative_ssl); |
| 14463 | |
| 14464 | // No data should be read from the alternative, because HTTP/1.1 is |
| 14465 | // negotiated. |
| 14466 | StaticSocketDataProvider data; |
| 14467 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14468 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14469 | // Negotiate HTTP/1.1 with server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14470 | SSLSocketDataProvider origin_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14471 | origin_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14472 | session_deps_.socket_factory->AddSSLSocketDataProvider(&origin_ssl); |
| 14473 | |
| 14474 | MockWrite http_writes[] = { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14475 | MockWrite("GET / HTTP/1.1\r\n" |
| 14476 | "Host: www.example.org\r\n" |
| 14477 | "Connection: keep-alive\r\n\r\n"), |
| 14478 | MockWrite("GET /second HTTP/1.1\r\n" |
| 14479 | "Host: www.example.org\r\n" |
| 14480 | "Connection: keep-alive\r\n\r\n"), |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14481 | }; |
| 14482 | |
| 14483 | MockRead http_reads[] = { |
| 14484 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14485 | MockRead("Content-Type: text/html\r\n"), |
| 14486 | MockRead("Content-Length: 6\r\n\r\n"), |
| 14487 | MockRead("foobar"), |
| 14488 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14489 | MockRead("Content-Type: text/html\r\n"), |
| 14490 | MockRead("Content-Length: 7\r\n\r\n"), |
| 14491 | MockRead("another"), |
| 14492 | }; |
| 14493 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 14494 | http_writes, arraysize(http_writes)); |
| 14495 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 14496 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14497 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14498 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 14499 | HttpServerProperties* http_server_properties = |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14500 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 14501 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 14502 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 14503 | http_server_properties->SetHttp2AlternativeService( |
| 14504 | server, alternative_service, expiration); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14505 | |
| 14506 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 14507 | HttpRequestInfo request1; |
| 14508 | request1.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14509 | request1.url = GURL("https://www.example.org:443"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14510 | request1.load_flags = 0; |
| 14511 | TestCompletionCallback callback1; |
| 14512 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14513 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14514 | rv = callback1.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14515 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14516 | |
| 14517 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14518 | ASSERT_TRUE(response1); |
| 14519 | ASSERT_TRUE(response1->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14520 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 14521 | |
| 14522 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14523 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14524 | EXPECT_EQ("foobar", response_data1); |
| 14525 | |
| 14526 | // Alternative should be marked as broken, because HTTP/1.1 is not sufficient |
| 14527 | // for alternative service. |
| 14528 | EXPECT_TRUE( |
| 14529 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
| 14530 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14531 | // Since |alternative_service| is broken, a second transaction to server |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14532 | // should not start an alternate Job. It should pool to existing connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14533 | // to server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14534 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 14535 | HttpRequestInfo request2; |
| 14536 | request2.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14537 | request2.url = GURL("https://www.example.org:443/second"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14538 | request2.load_flags = 0; |
| 14539 | TestCompletionCallback callback2; |
| 14540 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14541 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14542 | rv = callback2.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14543 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14544 | |
| 14545 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14546 | ASSERT_TRUE(response2); |
| 14547 | ASSERT_TRUE(response2->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14548 | EXPECT_EQ("HTTP/1.1 200 OK", response2->headers->GetStatusLine()); |
| 14549 | |
| 14550 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14551 | ASSERT_THAT(ReadTransaction(&trans2, &response_data2), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14552 | EXPECT_EQ("another", response_data2); |
| 14553 | } |
| 14554 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14555 | // Alternative service requires HTTP/2 (or SPDY), but there is already a |
| 14556 | // HTTP/1.1 socket open to the alternative server. That socket should not be |
| 14557 | // used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14558 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceShouldNotPoolToHttp11) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14559 | url::SchemeHostPort server("https", "origin.example.org", 443); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14560 | HostPortPair alternative("alternative.example.org", 443); |
| 14561 | std::string origin_url = "https://origin.example.org:443"; |
| 14562 | std::string alternative_url = "https://alternative.example.org:443"; |
| 14563 | |
| 14564 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 14565 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14566 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14567 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14568 | |
| 14569 | // HTTP/1.1 data for |request1| and |request2|. |
| 14570 | MockWrite http_writes[] = { |
| 14571 | MockWrite( |
| 14572 | "GET / HTTP/1.1\r\n" |
| 14573 | "Host: alternative.example.org\r\n" |
| 14574 | "Connection: keep-alive\r\n\r\n"), |
| 14575 | MockWrite( |
| 14576 | "GET / HTTP/1.1\r\n" |
| 14577 | "Host: alternative.example.org\r\n" |
| 14578 | "Connection: keep-alive\r\n\r\n"), |
| 14579 | }; |
| 14580 | |
| 14581 | MockRead http_reads[] = { |
| 14582 | MockRead( |
| 14583 | "HTTP/1.1 200 OK\r\n" |
| 14584 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 14585 | "Content-Length: 40\r\n\r\n" |
| 14586 | "first HTTP/1.1 response from alternative"), |
| 14587 | MockRead( |
| 14588 | "HTTP/1.1 200 OK\r\n" |
| 14589 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 14590 | "Content-Length: 41\r\n\r\n" |
| 14591 | "second HTTP/1.1 response from alternative"), |
| 14592 | }; |
| 14593 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 14594 | http_writes, arraysize(http_writes)); |
| 14595 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 14596 | |
| 14597 | // This test documents that an alternate Job should not pool to an already |
| 14598 | // existing HTTP/1.1 connection. In order to test this, a failed connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14599 | // to the server is mocked. This way |request2| relies on the alternate Job. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14600 | StaticSocketDataProvider data_refused; |
| 14601 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 14602 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 14603 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14604 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14605 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 14606 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14607 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 14608 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 14609 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 14610 | http_server_properties->SetHttp2AlternativeService( |
| 14611 | server, alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14612 | |
| 14613 | // First transaction to alternative to open an HTTP/1.1 socket. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14614 | HttpRequestInfo request1; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 14615 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14616 | request1.method = "GET"; |
| 14617 | request1.url = GURL(alternative_url); |
| 14618 | request1.load_flags = 0; |
| 14619 | TestCompletionCallback callback1; |
| 14620 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14621 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14622 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14623 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14624 | ASSERT_TRUE(response1); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14625 | ASSERT_TRUE(response1->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14626 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14627 | EXPECT_TRUE(response1->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14628 | EXPECT_FALSE(response1->was_fetched_via_spdy); |
| 14629 | std::string response_data1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14630 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14631 | EXPECT_EQ("first HTTP/1.1 response from alternative", response_data1); |
| 14632 | |
| 14633 | // Request for origin.example.org, which has an alternative service. This |
| 14634 | // will start two Jobs: the alternative looks for connections to pool to, |
| 14635 | // 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] | 14636 | // open other connections to alternative server. The Job to server fails, so |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14637 | // this request fails. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14638 | HttpRequestInfo request2; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 14639 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14640 | request2.method = "GET"; |
| 14641 | request2.url = GURL(origin_url); |
| 14642 | request2.load_flags = 0; |
| 14643 | TestCompletionCallback callback2; |
| 14644 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14645 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14646 | EXPECT_THAT(callback2.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14647 | |
| 14648 | // Another transaction to alternative. This is to test that the HTTP/1.1 |
| 14649 | // socket is still open and in the pool. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14650 | HttpRequestInfo request3; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 14651 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14652 | request3.method = "GET"; |
| 14653 | request3.url = GURL(alternative_url); |
| 14654 | request3.load_flags = 0; |
| 14655 | TestCompletionCallback callback3; |
| 14656 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14657 | rv = trans3.Start(&request3, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14658 | EXPECT_THAT(callback3.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14659 | const HttpResponseInfo* response3 = trans3.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14660 | ASSERT_TRUE(response3); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14661 | ASSERT_TRUE(response3->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14662 | EXPECT_EQ("HTTP/1.1 200 OK", response3->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14663 | EXPECT_TRUE(response3->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14664 | EXPECT_FALSE(response3->was_fetched_via_spdy); |
| 14665 | std::string response_data3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14666 | ASSERT_THAT(ReadTransaction(&trans3, &response_data3), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14667 | EXPECT_EQ("second HTTP/1.1 response from alternative", response_data3); |
| 14668 | } |
| 14669 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14670 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14671 | const std::string https_url = "https://www.example.org:8080/"; |
| 14672 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14673 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14674 | // Separate SPDY util instance for naked and wrapped requests. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14675 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14676 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14677 | // SPDY GET for HTTPS URL (through CONNECT tunnel) |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14678 | const HostPortPair host_port_pair("www.example.org", 8080); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14679 | SpdySerializedFrame connect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 14680 | spdy_util_.ConstructSpdyConnect(NULL, 0, 1, LOWEST, host_port_pair)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14681 | SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14682 | spdy_util_wrapped.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14683 | SpdySerializedFrame wrapped_req1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 14684 | spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 14685 | |
| 14686 | // SPDY GET for HTTP URL (through the proxy, but not the tunnel). |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 14687 | SpdyHeaderBlock req2_block; |
Bence Béky | bda8295 | 2017-10-02 17:35:27 | [diff] [blame] | 14688 | req2_block[kHttp2MethodHeader] = "GET"; |
| 14689 | req2_block[kHttp2AuthorityHeader] = "www.example.org:8080"; |
| 14690 | req2_block[kHttp2SchemeHeader] = "http"; |
| 14691 | req2_block[kHttp2PathHeader] = "/"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14692 | SpdySerializedFrame req2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14693 | spdy_util_.ConstructSpdyHeaders(3, std::move(req2_block), MEDIUM, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14694 | |
| 14695 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14696 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_req1, 2), |
| 14697 | CreateMockWrite(req2, 6), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14698 | }; |
| 14699 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14700 | SpdySerializedFrame conn_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14701 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14702 | SpdySerializedFrame resp1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14703 | spdy_util_wrapped.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14704 | SpdySerializedFrame body1(spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 14705 | SpdySerializedFrame wrapped_resp1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14706 | spdy_util_wrapped.ConstructWrappedSpdyFrame(resp1, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14707 | SpdySerializedFrame wrapped_body1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14708 | spdy_util_wrapped.ConstructWrappedSpdyFrame(body1, 1)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14709 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14710 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14711 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14712 | CreateMockRead(conn_resp, 1), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14713 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14714 | CreateMockRead(wrapped_resp1, 4), |
| 14715 | CreateMockRead(wrapped_body1, 5), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14716 | MockRead(ASYNC, ERR_IO_PENDING, 7), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14717 | CreateMockRead(resp2, 8), |
| 14718 | CreateMockRead(body2, 9), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14719 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 10), |
| 14720 | }; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14721 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14722 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 14723 | arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14724 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 14725 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14726 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 14727 | session_deps_.proxy_service = |
| 14728 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14729 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14730 | session_deps_.net_log = &log; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14731 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14732 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14733 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14734 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14735 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14736 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 14737 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14738 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14739 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14740 | |
| 14741 | // Start the first transaction to set up the SpdySession |
| 14742 | HttpRequestInfo request1; |
| 14743 | request1.method = "GET"; |
| 14744 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14745 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14746 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14747 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14748 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14749 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14750 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 14751 | data1.RunUntilPaused(); |
| 14752 | base::RunLoop().RunUntilIdle(); |
| 14753 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14754 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14755 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 14756 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 14757 | LoadTimingInfo load_timing_info1; |
| 14758 | EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); |
| 14759 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 14760 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 14761 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14762 | // Now, start the HTTP request. |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14763 | HttpRequestInfo request2; |
| 14764 | request2.method = "GET"; |
| 14765 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14766 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14767 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14768 | TestCompletionCallback callback2; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14769 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14770 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14771 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 14772 | data1.RunUntilPaused(); |
| 14773 | base::RunLoop().RunUntilIdle(); |
| 14774 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14775 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14776 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14777 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 14778 | |
| 14779 | LoadTimingInfo load_timing_info2; |
| 14780 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
| 14781 | // The established SPDY sessions is considered reused by the HTTP request. |
| 14782 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 14783 | // HTTP requests over a SPDY session should have a different connection |
| 14784 | // socket_log_id than requests over a tunnel. |
| 14785 | 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] | 14786 | } |
| 14787 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14788 | // Test that in the case where we have a SPDY session to a SPDY proxy |
| 14789 | // that we do not pool other origins that resolve to the same IP when |
| 14790 | // the certificate does not match the new origin. |
| 14791 | // http://crbug.com/134690 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14792 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14793 | const std::string url1 = "http://www.example.org/"; |
| 14794 | const std::string url2 = "https://news.example.org/"; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14795 | const std::string ip_addr = "1.2.3.4"; |
| 14796 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14797 | // Second SpdyTestUtil instance for the second socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14798 | SpdyTestUtil spdy_util_secure; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14799 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14800 | // SPDY GET for HTTP URL (through SPDY proxy) |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 14801 | SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14802 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14803 | SpdySerializedFrame req1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14804 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14805 | |
| 14806 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14807 | CreateMockWrite(req1, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14808 | }; |
| 14809 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14810 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14811 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14812 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14813 | MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(resp1, 2), |
| 14814 | CreateMockRead(body1, 3), MockRead(ASYNC, OK, 4), // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14815 | }; |
| 14816 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14817 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 14818 | arraysize(writes1)); |
martijn | fe9636e | 2016-02-06 14:33:32 | [diff] [blame] | 14819 | IPAddress ip; |
martijn | 654c8c4 | 2016-02-10 22:10:59 | [diff] [blame] | 14820 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14821 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 14822 | MockConnect connect_data1(ASYNC, OK, peer_addr); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14823 | data1.set_connect_data(connect_data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14824 | |
| 14825 | // SPDY GET for HTTPS URL (direct) |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14826 | SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14827 | spdy_util_secure.ConstructSpdyGet(url2.c_str(), 1, MEDIUM)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14828 | |
| 14829 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14830 | CreateMockWrite(req2, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14831 | }; |
| 14832 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14833 | SpdySerializedFrame resp2(spdy_util_secure.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14834 | SpdySerializedFrame body2(spdy_util_secure.ConstructSpdyDataFrame(1, true)); |
| 14835 | MockRead reads2[] = {CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14836 | MockRead(ASYNC, OK, 3)}; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14837 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14838 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 14839 | arraysize(writes2)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14840 | MockConnect connect_data2(ASYNC, OK); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14841 | data2.set_connect_data(connect_data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14842 | |
| 14843 | // Set up a proxy config that sends HTTP requests to a proxy, and |
| 14844 | // all others direct. |
| 14845 | ProxyConfig proxy_config; |
| 14846 | proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14847 | session_deps_.proxy_service = std::make_unique<ProxyService>( |
| 14848 | std::make_unique<ProxyConfigServiceFixed>(proxy_config), nullptr, |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14849 | nullptr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14850 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14851 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14852 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14853 | // Load a valid cert. Note, that this does not need to |
| 14854 | // be valid for proxy because the MockSSLClientSocket does |
| 14855 | // not actually verify it. But SpdySession will use this |
| 14856 | // to see if it is valid for the new origin |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14857 | ssl1.cert = ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem"); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14858 | ASSERT_TRUE(ssl1.cert); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14859 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 14860 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14861 | |
| 14862 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14863 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14864 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 14865 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14866 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14867 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14868 | session_deps_.host_resolver->rules()->AddRule("news.example.org", ip_addr); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14869 | session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14870 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14871 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14872 | |
| 14873 | // Start the first transaction to set up the SpdySession |
| 14874 | HttpRequestInfo request1; |
| 14875 | request1.method = "GET"; |
| 14876 | request1.url = GURL(url1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14877 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14878 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14879 | TestCompletionCallback callback1; |
| 14880 | ASSERT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14881 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14882 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 14883 | data1.RunUntilPaused(); |
| 14884 | base::RunLoop().RunUntilIdle(); |
| 14885 | data1.Resume(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14886 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14887 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14888 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 14889 | |
| 14890 | // Now, start the HTTP request |
| 14891 | HttpRequestInfo request2; |
| 14892 | request2.method = "GET"; |
| 14893 | request2.url = GURL(url2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14894 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14895 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14896 | TestCompletionCallback callback2; |
| 14897 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14898 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 14899 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14900 | |
| 14901 | ASSERT_TRUE(callback2.have_result()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14902 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14903 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 14904 | } |
| 14905 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14906 | // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 14907 | // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 14908 | // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 14909 | // SpdySession) do work. http://crbug.com/224701 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14910 | TEST_F(HttpNetworkTransactionTest, ErrorSocketNotConnected) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14911 | const std::string https_url = "https://www.example.org/"; |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14912 | |
| 14913 | MockRead reads1[] = { |
| 14914 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 14915 | }; |
| 14916 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14917 | SequencedSocketData data1(reads1, arraysize(reads1), NULL, 0); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14918 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14919 | SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14920 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, MEDIUM)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14921 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14922 | CreateMockWrite(req2, 0), |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14923 | }; |
| 14924 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14925 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14926 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14927 | MockRead reads2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14928 | CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
| 14929 | MockRead(ASYNC, OK, 3) // EOF |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14930 | }; |
| 14931 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14932 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 14933 | arraysize(writes2)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14934 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14935 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14936 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14937 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 14938 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14939 | |
| 14940 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14941 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14942 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 14943 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14944 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14945 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14946 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14947 | |
| 14948 | // Start the first transaction to set up the SpdySession and verify that |
| 14949 | // connection was closed. |
| 14950 | HttpRequestInfo request1; |
| 14951 | request1.method = "GET"; |
| 14952 | request1.url = GURL(https_url); |
| 14953 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14954 | HttpNetworkTransaction trans1(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14955 | TestCompletionCallback callback1; |
| 14956 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14957 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14958 | EXPECT_THAT(callback1.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14959 | |
| 14960 | // Now, start the second request and make sure it succeeds. |
| 14961 | HttpRequestInfo request2; |
| 14962 | request2.method = "GET"; |
| 14963 | request2.url = GURL(https_url); |
| 14964 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14965 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14966 | TestCompletionCallback callback2; |
| 14967 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14968 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14969 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14970 | ASSERT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14971 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 14972 | } |
| 14973 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14974 | TEST_F(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14975 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 14976 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14977 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 14978 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14979 | |
| 14980 | // Use two different hosts with different IPs so they don't get pooled. |
| 14981 | session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); |
| 14982 | session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14983 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14984 | |
| 14985 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14986 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14987 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14988 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14989 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 14990 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 14991 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14992 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14993 | spdy_util_.ConstructSpdyGet("https://www.a.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14994 | MockWrite spdy1_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14995 | CreateMockWrite(host1_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14996 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14997 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14998 | SpdySerializedFrame host1_resp_body( |
| 14999 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15000 | MockRead spdy1_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15001 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 15002 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15003 | }; |
| 15004 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15005 | // Use a separate test instance for the separate SpdySession that will be |
| 15006 | // created. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15007 | SpdyTestUtil spdy_util_2; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15008 | auto spdy1_data = std::make_unique<SequencedSocketData>( |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15009 | spdy1_reads, arraysize(spdy1_reads), spdy1_writes, |
| 15010 | arraysize(spdy1_writes)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15011 | session_deps_.socket_factory->AddSocketDataProvider(spdy1_data.get()); |
| 15012 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15013 | SpdySerializedFrame host2_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15014 | spdy_util_2.ConstructSpdyGet("https://www.b.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15015 | MockWrite spdy2_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15016 | CreateMockWrite(host2_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15017 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15018 | SpdySerializedFrame host2_resp(spdy_util_2.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15019 | SpdySerializedFrame host2_resp_body( |
| 15020 | spdy_util_2.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15021 | MockRead spdy2_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15022 | CreateMockRead(host2_resp, 1), CreateMockRead(host2_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 15023 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15024 | }; |
| 15025 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15026 | auto spdy2_data = std::make_unique<SequencedSocketData>( |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15027 | spdy2_reads, arraysize(spdy2_reads), spdy2_writes, |
| 15028 | arraysize(spdy2_writes)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15029 | session_deps_.socket_factory->AddSocketDataProvider(spdy2_data.get()); |
| 15030 | |
| 15031 | MockWrite http_write[] = { |
| 15032 | MockWrite("GET / HTTP/1.1\r\n" |
| 15033 | "Host: www.a.com\r\n" |
| 15034 | "Connection: keep-alive\r\n\r\n"), |
| 15035 | }; |
| 15036 | |
| 15037 | MockRead http_read[] = { |
| 15038 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15039 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 15040 | MockRead("Content-Length: 6\r\n\r\n"), |
| 15041 | MockRead("hello!"), |
| 15042 | }; |
| 15043 | StaticSocketDataProvider http_data(http_read, arraysize(http_read), |
| 15044 | http_write, arraysize(http_write)); |
| 15045 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 15046 | |
| 15047 | HostPortPair host_port_pair_a("www.a.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 15048 | SpdySessionKey spdy_session_key_a( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 15049 | host_port_pair_a, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15050 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15051 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15052 | |
| 15053 | TestCompletionCallback callback; |
| 15054 | HttpRequestInfo request1; |
| 15055 | request1.method = "GET"; |
| 15056 | request1.url = GURL("https://www.a.com/"); |
| 15057 | request1.load_flags = 0; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15058 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15059 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15060 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15061 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15062 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15063 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15064 | |
| 15065 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15066 | ASSERT_TRUE(response); |
| 15067 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15068 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15069 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15070 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15071 | |
| 15072 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15073 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15074 | EXPECT_EQ("hello!", response_data); |
| 15075 | trans.reset(); |
| 15076 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15077 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15078 | |
| 15079 | HostPortPair host_port_pair_b("www.b.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 15080 | SpdySessionKey spdy_session_key_b( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 15081 | host_port_pair_b, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15082 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15083 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15084 | HttpRequestInfo request2; |
| 15085 | request2.method = "GET"; |
| 15086 | request2.url = GURL("https://www.b.com/"); |
| 15087 | request2.load_flags = 0; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15088 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15089 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15090 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15091 | rv = trans->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15092 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15093 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15094 | |
| 15095 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15096 | ASSERT_TRUE(response); |
| 15097 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15098 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15099 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15100 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15101 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15102 | EXPECT_EQ("hello!", response_data); |
| 15103 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15104 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15105 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15106 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15107 | |
| 15108 | HostPortPair host_port_pair_a1("www.a.com", 80); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 15109 | SpdySessionKey spdy_session_key_a1( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 15110 | host_port_pair_a1, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15111 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15112 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15113 | HttpRequestInfo request3; |
| 15114 | request3.method = "GET"; |
| 15115 | request3.url = GURL("http://www.a.com/"); |
| 15116 | request3.load_flags = 0; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15117 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15118 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15119 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15120 | rv = trans->Start(&request3, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15121 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15122 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15123 | |
| 15124 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15125 | ASSERT_TRUE(response); |
| 15126 | ASSERT_TRUE(response->headers); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15127 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 15128 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15129 | EXPECT_FALSE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15130 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15131 | EXPECT_EQ("hello!", response_data); |
| 15132 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15133 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15134 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15135 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15136 | } |
| 15137 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15138 | TEST_F(HttpNetworkTransactionTest, HttpSyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15139 | HttpRequestInfo request; |
| 15140 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15141 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15142 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15143 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15144 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15145 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15146 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15147 | StaticSocketDataProvider data; |
| 15148 | data.set_connect_data(mock_connect); |
| 15149 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15150 | |
| 15151 | TestCompletionCallback callback; |
| 15152 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15153 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15154 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15155 | |
| 15156 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15157 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15158 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15159 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 15160 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15161 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 15162 | |
| 15163 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15164 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 15165 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15166 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15167 | |
| 15168 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15169 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15170 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15171 | } |
| 15172 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15173 | TEST_F(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15174 | HttpRequestInfo request; |
| 15175 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15176 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15177 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15178 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15179 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15180 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15181 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15182 | StaticSocketDataProvider data; |
| 15183 | data.set_connect_data(mock_connect); |
| 15184 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15185 | |
| 15186 | TestCompletionCallback callback; |
| 15187 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15188 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15189 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15190 | |
| 15191 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15192 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15193 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15194 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 15195 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15196 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 15197 | |
| 15198 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15199 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 15200 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15201 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15202 | |
| 15203 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15204 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15205 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15206 | } |
| 15207 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15208 | TEST_F(HttpNetworkTransactionTest, HttpSyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15209 | HttpRequestInfo request; |
| 15210 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15211 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15212 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15213 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15214 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15215 | |
| 15216 | MockWrite data_writes[] = { |
| 15217 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15218 | }; |
| 15219 | MockRead data_reads[] = { |
| 15220 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 15221 | }; |
| 15222 | |
| 15223 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 15224 | data_writes, arraysize(data_writes)); |
| 15225 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15226 | |
| 15227 | TestCompletionCallback callback; |
| 15228 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15229 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15230 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15231 | |
| 15232 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15233 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15234 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15235 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15236 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15237 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 15238 | } |
| 15239 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15240 | TEST_F(HttpNetworkTransactionTest, HttpAsyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15241 | HttpRequestInfo request; |
| 15242 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15243 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15244 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15245 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15246 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15247 | |
| 15248 | MockWrite data_writes[] = { |
| 15249 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
| 15250 | }; |
| 15251 | MockRead data_reads[] = { |
| 15252 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 15253 | }; |
| 15254 | |
| 15255 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 15256 | data_writes, arraysize(data_writes)); |
| 15257 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15258 | |
| 15259 | TestCompletionCallback callback; |
| 15260 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15261 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15262 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15263 | |
| 15264 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15265 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15266 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15267 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15268 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15269 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 15270 | } |
| 15271 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15272 | TEST_F(HttpNetworkTransactionTest, HttpSyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15273 | HttpRequestInfo request; |
| 15274 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15275 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15276 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15277 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15278 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15279 | |
| 15280 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15281 | MockWrite( |
| 15282 | "GET / HTTP/1.1\r\n" |
| 15283 | "Host: www.example.org\r\n" |
| 15284 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15285 | }; |
| 15286 | MockRead data_reads[] = { |
| 15287 | MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15288 | }; |
| 15289 | |
| 15290 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 15291 | data_writes, arraysize(data_writes)); |
| 15292 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15293 | |
| 15294 | TestCompletionCallback callback; |
| 15295 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15296 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15297 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15298 | |
| 15299 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15300 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15301 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15302 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15303 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15304 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 15305 | } |
| 15306 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15307 | TEST_F(HttpNetworkTransactionTest, HttpAsyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15308 | HttpRequestInfo request; |
| 15309 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15310 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15311 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15312 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15313 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15314 | |
| 15315 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15316 | MockWrite( |
| 15317 | "GET / HTTP/1.1\r\n" |
| 15318 | "Host: www.example.org\r\n" |
| 15319 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15320 | }; |
| 15321 | MockRead data_reads[] = { |
| 15322 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 15323 | }; |
| 15324 | |
| 15325 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 15326 | data_writes, arraysize(data_writes)); |
| 15327 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15328 | |
| 15329 | TestCompletionCallback callback; |
| 15330 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15331 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15332 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15333 | |
| 15334 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15335 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15336 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15337 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15338 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15339 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 15340 | } |
| 15341 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15342 | TEST_F(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15343 | HttpRequestInfo request; |
| 15344 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15345 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15346 | request.extra_headers.SetHeader("X-Foo", "bar"); |
| 15347 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15348 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15349 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15350 | |
| 15351 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15352 | MockWrite( |
| 15353 | "GET / HTTP/1.1\r\n" |
| 15354 | "Host: www.example.org\r\n" |
| 15355 | "Connection: keep-alive\r\n" |
| 15356 | "X-Foo: bar\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15357 | }; |
| 15358 | MockRead data_reads[] = { |
| 15359 | MockRead("HTTP/1.1 200 OK\r\n" |
| 15360 | "Content-Length: 5\r\n\r\n" |
| 15361 | "hello"), |
| 15362 | MockRead(ASYNC, ERR_UNEXPECTED), |
| 15363 | }; |
| 15364 | |
| 15365 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 15366 | data_writes, arraysize(data_writes)); |
| 15367 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15368 | |
| 15369 | TestCompletionCallback callback; |
| 15370 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15371 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15372 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15373 | |
| 15374 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15375 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15376 | |
| 15377 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15378 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15379 | std::string foo; |
| 15380 | EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo)); |
| 15381 | EXPECT_EQ("bar", foo); |
| 15382 | } |
| 15383 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15384 | namespace { |
| 15385 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 15386 | // Fake HttpStream that simply records calls to SetPriority(). |
| 15387 | class FakeStream : public HttpStream, |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15388 | public base::SupportsWeakPtr<FakeStream> { |
| 15389 | public: |
| 15390 | explicit FakeStream(RequestPriority priority) : priority_(priority) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15391 | ~FakeStream() override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15392 | |
| 15393 | RequestPriority priority() const { return priority_; } |
| 15394 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15395 | int InitializeStream(const HttpRequestInfo* request_info, |
| 15396 | RequestPriority priority, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15397 | const NetLogWithSource& net_log, |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15398 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15399 | return ERR_IO_PENDING; |
| 15400 | } |
| 15401 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15402 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 15403 | HttpResponseInfo* response, |
| 15404 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15405 | ADD_FAILURE(); |
| 15406 | return ERR_UNEXPECTED; |
| 15407 | } |
| 15408 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15409 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15410 | ADD_FAILURE(); |
| 15411 | return ERR_UNEXPECTED; |
| 15412 | } |
| 15413 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15414 | int ReadResponseBody(IOBuffer* buf, |
| 15415 | int buf_len, |
| 15416 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15417 | ADD_FAILURE(); |
| 15418 | return ERR_UNEXPECTED; |
| 15419 | } |
| 15420 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15421 | void Close(bool not_reusable) override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15422 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15423 | bool IsResponseBodyComplete() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15424 | ADD_FAILURE(); |
| 15425 | return false; |
| 15426 | } |
| 15427 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15428 | bool IsConnectionReused() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15429 | ADD_FAILURE(); |
| 15430 | return false; |
| 15431 | } |
| 15432 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15433 | void SetConnectionReused() override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15434 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 15435 | bool CanReuseConnection() const override { return false; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15436 | |
sclittle | 4de1bab9 | 2015-09-22 21:28:24 | [diff] [blame] | 15437 | int64_t GetTotalReceivedBytes() const override { |
[email protected] | bc92bc97 | 2013-12-13 08:32:59 | [diff] [blame] | 15438 | ADD_FAILURE(); |
| 15439 | return 0; |
| 15440 | } |
| 15441 | |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 15442 | int64_t GetTotalSentBytes() const override { |
| 15443 | ADD_FAILURE(); |
| 15444 | return 0; |
| 15445 | } |
| 15446 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15447 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15448 | ADD_FAILURE(); |
| 15449 | return false; |
| 15450 | } |
| 15451 | |
rch | cd37901 | 2017-04-12 21:53:32 | [diff] [blame] | 15452 | bool GetAlternativeService( |
| 15453 | AlternativeService* alternative_service) const override { |
| 15454 | ADD_FAILURE(); |
| 15455 | return false; |
| 15456 | } |
| 15457 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15458 | void GetSSLInfo(SSLInfo* ssl_info) override { ADD_FAILURE(); } |
| 15459 | |
| 15460 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15461 | ADD_FAILURE(); |
| 15462 | } |
| 15463 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15464 | bool GetRemoteEndpoint(IPEndPoint* endpoint) override { return false; } |
| 15465 | |
nharper | 78e6d2b | 2016-09-21 05:42:35 | [diff] [blame] | 15466 | Error GetTokenBindingSignature(crypto::ECPrivateKey* key, |
| 15467 | TokenBindingType tb_type, |
| 15468 | std::vector<uint8_t>* out) override { |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 15469 | ADD_FAILURE(); |
| 15470 | return ERR_NOT_IMPLEMENTED; |
| 15471 | } |
| 15472 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15473 | void Drain(HttpNetworkSession* session) override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15474 | |
zhongyi | ca364fbb | 2015-12-12 03:39:12 | [diff] [blame] | 15475 | void PopulateNetErrorDetails(NetErrorDetails* details) override { return; } |
| 15476 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15477 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15478 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 15479 | HttpStream* RenewStreamForAuth() override { return NULL; } |
| 15480 | |
Andrey Kosyakov | 83a6eee | 2017-08-14 19:20:04 | [diff] [blame] | 15481 | void SetRequestHeadersCallback(RequestHeadersCallback callback) override {} |
| 15482 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15483 | private: |
| 15484 | RequestPriority priority_; |
| 15485 | |
| 15486 | DISALLOW_COPY_AND_ASSIGN(FakeStream); |
| 15487 | }; |
| 15488 | |
| 15489 | // Fake HttpStreamRequest that simply records calls to SetPriority() |
| 15490 | // and vends FakeStreams with its current priority. |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15491 | class FakeStreamRequest : public HttpStreamRequest, |
| 15492 | public base::SupportsWeakPtr<FakeStreamRequest> { |
| 15493 | public: |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15494 | FakeStreamRequest(RequestPriority priority, |
| 15495 | HttpStreamRequest::Delegate* delegate) |
| 15496 | : priority_(priority), |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15497 | delegate_(delegate), |
| 15498 | websocket_stream_create_helper_(NULL) {} |
| 15499 | |
| 15500 | FakeStreamRequest(RequestPriority priority, |
| 15501 | HttpStreamRequest::Delegate* delegate, |
| 15502 | WebSocketHandshakeStreamBase::CreateHelper* create_helper) |
| 15503 | : priority_(priority), |
| 15504 | delegate_(delegate), |
| 15505 | websocket_stream_create_helper_(create_helper) {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15506 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15507 | ~FakeStreamRequest() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15508 | |
| 15509 | RequestPriority priority() const { return priority_; } |
| 15510 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15511 | const WebSocketHandshakeStreamBase::CreateHelper* |
| 15512 | websocket_stream_create_helper() const { |
| 15513 | return websocket_stream_create_helper_; |
| 15514 | } |
| 15515 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15516 | // Create a new FakeStream and pass it to the request's |
| 15517 | // delegate. Returns a weak pointer to the FakeStream. |
| 15518 | base::WeakPtr<FakeStream> FinishStreamRequest() { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15519 | auto fake_stream = std::make_unique<FakeStream>(priority_); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15520 | // Do this before calling OnStreamReady() as OnStreamReady() may |
| 15521 | // immediately delete |fake_stream|. |
| 15522 | base::WeakPtr<FakeStream> weak_stream = fake_stream->AsWeakPtr(); |
bnc | 5029f463 | 2017-06-08 16:19:00 | [diff] [blame] | 15523 | delegate_->OnStreamReady(SSLConfig(), ProxyInfo(), std::move(fake_stream)); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15524 | return weak_stream; |
| 15525 | } |
| 15526 | |
asanka | 681f02d | 2017-02-22 17:06:39 | [diff] [blame] | 15527 | int RestartTunnelWithProxyAuth() override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15528 | ADD_FAILURE(); |
| 15529 | return ERR_UNEXPECTED; |
| 15530 | } |
| 15531 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15532 | LoadState GetLoadState() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15533 | ADD_FAILURE(); |
| 15534 | return LoadState(); |
| 15535 | } |
| 15536 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15537 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15538 | |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15539 | bool was_alpn_negotiated() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15540 | |
bnc | 6227b26e | 2016-08-12 02:00:43 | [diff] [blame] | 15541 | NextProto negotiated_protocol() const override { return kProtoUnknown; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15542 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15543 | bool using_spdy() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15544 | |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 15545 | const ConnectionAttempts& connection_attempts() const override { |
| 15546 | static ConnectionAttempts no_attempts; |
| 15547 | return no_attempts; |
| 15548 | } |
| 15549 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15550 | private: |
| 15551 | RequestPriority priority_; |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15552 | HttpStreamRequest::Delegate* const delegate_; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15553 | WebSocketHandshakeStreamBase::CreateHelper* websocket_stream_create_helper_; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15554 | |
| 15555 | DISALLOW_COPY_AND_ASSIGN(FakeStreamRequest); |
| 15556 | }; |
| 15557 | |
| 15558 | // Fake HttpStreamFactory that vends FakeStreamRequests. |
| 15559 | class FakeStreamFactory : public HttpStreamFactory { |
| 15560 | public: |
| 15561 | FakeStreamFactory() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15562 | ~FakeStreamFactory() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15563 | |
| 15564 | // Returns a WeakPtr<> to the last HttpStreamRequest returned by |
| 15565 | // RequestStream() (which may be NULL if it was destroyed already). |
| 15566 | base::WeakPtr<FakeStreamRequest> last_stream_request() { |
| 15567 | return last_stream_request_; |
| 15568 | } |
| 15569 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15570 | std::unique_ptr<HttpStreamRequest> RequestStream( |
| 15571 | const HttpRequestInfo& info, |
| 15572 | RequestPriority priority, |
| 15573 | const SSLConfig& server_ssl_config, |
| 15574 | const SSLConfig& proxy_ssl_config, |
| 15575 | HttpStreamRequest::Delegate* delegate, |
| 15576 | bool enable_ip_based_pooling, |
| 15577 | bool enable_alternative_services, |
| 15578 | const NetLogWithSource& net_log) override { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15579 | auto fake_request = std::make_unique<FakeStreamRequest>(priority, delegate); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15580 | last_stream_request_ = fake_request->AsWeakPtr(); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15581 | return std::move(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15582 | } |
| 15583 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15584 | std::unique_ptr<HttpStreamRequest> RequestBidirectionalStreamImpl( |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 15585 | const HttpRequestInfo& info, |
| 15586 | RequestPriority priority, |
| 15587 | const SSLConfig& server_ssl_config, |
| 15588 | const SSLConfig& proxy_ssl_config, |
| 15589 | HttpStreamRequest::Delegate* delegate, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15590 | bool enable_ip_based_pooling, |
bnc | accd496 | 2017-04-06 21:00:26 | [diff] [blame] | 15591 | bool enable_alternative_services, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15592 | const NetLogWithSource& net_log) override { |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 15593 | NOTREACHED(); |
| 15594 | return nullptr; |
| 15595 | } |
| 15596 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15597 | std::unique_ptr<HttpStreamRequest> RequestWebSocketHandshakeStream( |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15598 | const HttpRequestInfo& info, |
| 15599 | RequestPriority priority, |
| 15600 | const SSLConfig& server_ssl_config, |
| 15601 | const SSLConfig& proxy_ssl_config, |
| 15602 | HttpStreamRequest::Delegate* delegate, |
[email protected] | 467086b | 2013-11-12 08:19:46 | [diff] [blame] | 15603 | WebSocketHandshakeStreamBase::CreateHelper* create_helper, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15604 | bool enable_ip_based_pooling, |
bnc | accd496 | 2017-04-06 21:00:26 | [diff] [blame] | 15605 | bool enable_alternative_services, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15606 | const NetLogWithSource& net_log) override { |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15607 | auto fake_request = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15608 | std::make_unique<FakeStreamRequest>(priority, delegate, create_helper); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15609 | last_stream_request_ = fake_request->AsWeakPtr(); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15610 | return std::move(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15611 | } |
| 15612 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15613 | void PreconnectStreams(int num_streams, |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 15614 | const HttpRequestInfo& info) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15615 | ADD_FAILURE(); |
| 15616 | } |
| 15617 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15618 | const HostMappingRules* GetHostMappingRules() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15619 | ADD_FAILURE(); |
| 15620 | return NULL; |
| 15621 | } |
| 15622 | |
xunjieli | f5267de | 2017-01-20 21:18:57 | [diff] [blame] | 15623 | void DumpMemoryStats(base::trace_event::ProcessMemoryDump* pmd, |
| 15624 | const std::string& parent_absolute_name) const override { |
| 15625 | ADD_FAILURE(); |
| 15626 | } |
| 15627 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15628 | private: |
| 15629 | base::WeakPtr<FakeStreamRequest> last_stream_request_; |
| 15630 | |
| 15631 | DISALLOW_COPY_AND_ASSIGN(FakeStreamFactory); |
| 15632 | }; |
| 15633 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15634 | // TODO(ricea): Maybe unify this with the one in |
| 15635 | // url_request_http_job_unittest.cc ? |
| 15636 | class FakeWebSocketBasicHandshakeStream : public WebSocketHandshakeStreamBase { |
| 15637 | public: |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15638 | FakeWebSocketBasicHandshakeStream( |
| 15639 | std::unique_ptr<ClientSocketHandle> connection, |
| 15640 | bool using_proxy) |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 15641 | : state_(std::move(connection), using_proxy, false) {} |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15642 | |
| 15643 | // Fake implementation of HttpStreamBase methods. |
| 15644 | // This ends up being quite "real" because this object has to really send data |
| 15645 | // on the mock socket. It might be easier to use the real implementation, but |
| 15646 | // the fact that the WebSocket code is not compiled on iOS makes that |
| 15647 | // difficult. |
| 15648 | int InitializeStream(const HttpRequestInfo* request_info, |
| 15649 | RequestPriority priority, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15650 | const NetLogWithSource& net_log, |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15651 | const CompletionCallback& callback) override { |
| 15652 | state_.Initialize(request_info, priority, net_log, callback); |
| 15653 | return OK; |
| 15654 | } |
| 15655 | |
| 15656 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 15657 | HttpResponseInfo* response, |
| 15658 | const CompletionCallback& callback) override { |
| 15659 | return parser()->SendRequest(state_.GenerateRequestLine(), request_headers, |
| 15660 | response, callback); |
| 15661 | } |
| 15662 | |
| 15663 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
| 15664 | return parser()->ReadResponseHeaders(callback); |
| 15665 | } |
| 15666 | |
| 15667 | int ReadResponseBody(IOBuffer* buf, |
| 15668 | int buf_len, |
| 15669 | const CompletionCallback& callback) override { |
| 15670 | NOTREACHED(); |
| 15671 | return ERR_IO_PENDING; |
| 15672 | } |
| 15673 | |
| 15674 | void Close(bool not_reusable) override { |
| 15675 | if (parser()) |
| 15676 | parser()->Close(true); |
| 15677 | } |
| 15678 | |
| 15679 | bool IsResponseBodyComplete() const override { |
| 15680 | NOTREACHED(); |
| 15681 | return false; |
| 15682 | } |
| 15683 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15684 | bool IsConnectionReused() const override { |
| 15685 | NOTREACHED(); |
| 15686 | return false; |
| 15687 | } |
| 15688 | void SetConnectionReused() override { NOTREACHED(); } |
| 15689 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 15690 | bool CanReuseConnection() const override { return false; } |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15691 | |
sclittle | 4de1bab9 | 2015-09-22 21:28:24 | [diff] [blame] | 15692 | int64_t GetTotalReceivedBytes() const override { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15693 | NOTREACHED(); |
| 15694 | return 0; |
| 15695 | } |
| 15696 | |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 15697 | int64_t GetTotalSentBytes() const override { |
| 15698 | NOTREACHED(); |
| 15699 | return 0; |
| 15700 | } |
| 15701 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15702 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
| 15703 | NOTREACHED(); |
| 15704 | return false; |
| 15705 | } |
| 15706 | |
rch | cd37901 | 2017-04-12 21:53:32 | [diff] [blame] | 15707 | bool GetAlternativeService( |
| 15708 | AlternativeService* alternative_service) const override { |
| 15709 | ADD_FAILURE(); |
| 15710 | return false; |
| 15711 | } |
| 15712 | |
Adam Rice | cb76ac6 | 2015-02-20 05:33:25 | [diff] [blame] | 15713 | void GetSSLInfo(SSLInfo* ssl_info) override {} |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15714 | |
| 15715 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
| 15716 | NOTREACHED(); |
| 15717 | } |
| 15718 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15719 | bool GetRemoteEndpoint(IPEndPoint* endpoint) override { return false; } |
| 15720 | |
nharper | 78e6d2b | 2016-09-21 05:42:35 | [diff] [blame] | 15721 | Error GetTokenBindingSignature(crypto::ECPrivateKey* key, |
| 15722 | TokenBindingType tb_type, |
| 15723 | std::vector<uint8_t>* out) override { |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 15724 | ADD_FAILURE(); |
| 15725 | return ERR_NOT_IMPLEMENTED; |
| 15726 | } |
| 15727 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15728 | void Drain(HttpNetworkSession* session) override { NOTREACHED(); } |
| 15729 | |
zhongyi | ca364fbb | 2015-12-12 03:39:12 | [diff] [blame] | 15730 | void PopulateNetErrorDetails(NetErrorDetails* details) override { return; } |
| 15731 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15732 | void SetPriority(RequestPriority priority) override { NOTREACHED(); } |
| 15733 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15734 | HttpStream* RenewStreamForAuth() override { |
| 15735 | NOTREACHED(); |
| 15736 | return nullptr; |
| 15737 | } |
| 15738 | |
| 15739 | // Fake implementation of WebSocketHandshakeStreamBase method(s) |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15740 | std::unique_ptr<WebSocketStream> Upgrade() override { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15741 | NOTREACHED(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15742 | return std::unique_ptr<WebSocketStream>(); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15743 | } |
| 15744 | |
| 15745 | private: |
| 15746 | HttpStreamParser* parser() const { return state_.parser(); } |
| 15747 | HttpBasicState state_; |
| 15748 | |
| 15749 | DISALLOW_COPY_AND_ASSIGN(FakeWebSocketBasicHandshakeStream); |
| 15750 | }; |
| 15751 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15752 | // TODO(yhirano): Split this class out into a net/websockets file, if it is |
| 15753 | // worth doing. |
| 15754 | class FakeWebSocketStreamCreateHelper : |
| 15755 | public WebSocketHandshakeStreamBase::CreateHelper { |
| 15756 | public: |
bnc | 615cf2f | 2017-05-19 18:53:26 | [diff] [blame] | 15757 | std::unique_ptr<WebSocketHandshakeStreamBase> CreateBasicStream( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15758 | std::unique_ptr<ClientSocketHandle> connection, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 15759 | bool using_proxy) override { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15760 | return std::make_unique<FakeWebSocketBasicHandshakeStream>( |
bnc | 615cf2f | 2017-05-19 18:53:26 | [diff] [blame] | 15761 | std::move(connection), using_proxy); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15762 | } |
| 15763 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15764 | ~FakeWebSocketStreamCreateHelper() override {} |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15765 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15766 | virtual std::unique_ptr<WebSocketStream> Upgrade() { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15767 | NOTREACHED(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15768 | return std::unique_ptr<WebSocketStream>(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15769 | } |
| 15770 | }; |
| 15771 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15772 | } // namespace |
| 15773 | |
| 15774 | // Make sure that HttpNetworkTransaction passes on its priority to its |
| 15775 | // stream request on start. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15776 | TEST_F(HttpNetworkTransactionTest, SetStreamRequestPriorityOnStart) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15777 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15778 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15779 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15780 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15781 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15782 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15783 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15784 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15785 | ASSERT_FALSE(fake_factory->last_stream_request()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15786 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15787 | TestCompletionCallback callback; |
| 15788 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15789 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15790 | |
| 15791 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 15792 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15793 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15794 | EXPECT_EQ(LOW, fake_request->priority()); |
| 15795 | } |
| 15796 | |
| 15797 | // Make sure that HttpNetworkTransaction passes on its priority |
| 15798 | // updates to its stream request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15799 | TEST_F(HttpNetworkTransactionTest, SetStreamRequestPriority) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15800 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15801 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15802 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15803 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15804 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15805 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15806 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15807 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15808 | TestCompletionCallback callback; |
| 15809 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15810 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15811 | |
| 15812 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 15813 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15814 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15815 | EXPECT_EQ(LOW, fake_request->priority()); |
| 15816 | |
| 15817 | trans.SetPriority(LOWEST); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15818 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15819 | EXPECT_EQ(LOWEST, fake_request->priority()); |
| 15820 | } |
| 15821 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15822 | // Make sure that HttpNetworkTransaction passes on its priority |
| 15823 | // updates to its stream. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15824 | TEST_F(HttpNetworkTransactionTest, SetStreamPriority) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15825 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15826 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15827 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15828 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15829 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15830 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15831 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15832 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15833 | TestCompletionCallback callback; |
| 15834 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15835 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15836 | |
| 15837 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 15838 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15839 | ASSERT_TRUE(fake_request); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15840 | base::WeakPtr<FakeStream> fake_stream = fake_request->FinishStreamRequest(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15841 | ASSERT_TRUE(fake_stream); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15842 | EXPECT_EQ(LOW, fake_stream->priority()); |
| 15843 | |
| 15844 | trans.SetPriority(LOWEST); |
| 15845 | EXPECT_EQ(LOWEST, fake_stream->priority()); |
| 15846 | } |
| 15847 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15848 | TEST_F(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15849 | // The same logic needs to be tested for both ws: and wss: schemes, but this |
| 15850 | // test is already parameterised on NextProto, so it uses a loop to verify |
| 15851 | // that the different schemes work. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15852 | std::string test_cases[] = {"ws://www.example.org/", |
| 15853 | "wss://www.example.org/"}; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15854 | for (size_t i = 0; i < arraysize(test_cases); ++i) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15855 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15856 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15857 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
| 15858 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
[email protected] | 0191b51c | 2013-11-18 10:55:23 | [diff] [blame] | 15859 | peer.SetHttpStreamFactoryForWebSocket( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15860 | std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15861 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15862 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15863 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15864 | trans.SetWebSocketHandshakeStreamCreateHelper( |
| 15865 | &websocket_stream_create_helper); |
| 15866 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15867 | TestCompletionCallback callback; |
| 15868 | request.method = "GET"; |
| 15869 | request.url = GURL(test_cases[i]); |
| 15870 | |
| 15871 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15872 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15873 | |
| 15874 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 15875 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15876 | ASSERT_TRUE(fake_request); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15877 | EXPECT_EQ(&websocket_stream_create_helper, |
| 15878 | fake_request->websocket_stream_create_helper()); |
| 15879 | } |
| 15880 | } |
| 15881 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15882 | // Tests that when a used socket is returned to the SSL socket pool, it's closed |
| 15883 | // if the transport socket pool is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15884 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15885 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 15886 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15887 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 15888 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15889 | |
| 15890 | // Set up SSL request. |
| 15891 | |
| 15892 | HttpRequestInfo ssl_request; |
| 15893 | ssl_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15894 | ssl_request.url = GURL("https://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15895 | |
| 15896 | MockWrite ssl_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15897 | MockWrite( |
| 15898 | "GET / HTTP/1.1\r\n" |
| 15899 | "Host: www.example.org\r\n" |
| 15900 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15901 | }; |
| 15902 | MockRead ssl_reads[] = { |
| 15903 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15904 | MockRead("Content-Length: 11\r\n\r\n"), |
| 15905 | MockRead("hello world"), |
| 15906 | MockRead(SYNCHRONOUS, OK), |
| 15907 | }; |
| 15908 | StaticSocketDataProvider ssl_data(ssl_reads, arraysize(ssl_reads), |
| 15909 | ssl_writes, arraysize(ssl_writes)); |
| 15910 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 15911 | |
| 15912 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 15913 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15914 | |
| 15915 | // Set up HTTP request. |
| 15916 | |
| 15917 | HttpRequestInfo http_request; |
| 15918 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15919 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15920 | |
| 15921 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15922 | MockWrite( |
| 15923 | "GET / HTTP/1.1\r\n" |
| 15924 | "Host: www.example.org\r\n" |
| 15925 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15926 | }; |
| 15927 | MockRead http_reads[] = { |
| 15928 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15929 | MockRead("Content-Length: 7\r\n\r\n"), |
| 15930 | MockRead("falafel"), |
| 15931 | MockRead(SYNCHRONOUS, OK), |
| 15932 | }; |
| 15933 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 15934 | http_writes, arraysize(http_writes)); |
| 15935 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 15936 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15937 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15938 | |
| 15939 | // Start the SSL request. |
| 15940 | TestCompletionCallback ssl_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15941 | HttpNetworkTransaction ssl_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15942 | ASSERT_EQ(ERR_IO_PENDING, |
| 15943 | ssl_trans.Start(&ssl_request, ssl_callback.callback(), |
| 15944 | NetLogWithSource())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15945 | |
| 15946 | // Start the HTTP request. Pool should stall. |
| 15947 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15948 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15949 | ASSERT_EQ(ERR_IO_PENDING, |
| 15950 | http_trans.Start(&http_request, http_callback.callback(), |
| 15951 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15952 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15953 | |
| 15954 | // Wait for response from SSL request. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15955 | ASSERT_THAT(ssl_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15956 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15957 | ASSERT_THAT(ReadTransaction(&ssl_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15958 | EXPECT_EQ("hello world", response_data); |
| 15959 | |
| 15960 | // The SSL socket should automatically be closed, so the HTTP request can |
| 15961 | // start. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15962 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 15963 | ASSERT_FALSE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15964 | |
| 15965 | // The HTTP request can now complete. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15966 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15967 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15968 | EXPECT_EQ("falafel", response_data); |
| 15969 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15970 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15971 | } |
| 15972 | |
| 15973 | // Tests that when a SSL connection is established but there's no corresponding |
| 15974 | // request that needs it, the new socket is closed if the transport socket pool |
| 15975 | // is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15976 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15977 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 15978 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15979 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 15980 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15981 | |
| 15982 | // Set up an ssl request. |
| 15983 | |
| 15984 | HttpRequestInfo ssl_request; |
| 15985 | ssl_request.method = "GET"; |
| 15986 | ssl_request.url = GURL("https://www.foopy.com/"); |
| 15987 | |
| 15988 | // No data will be sent on the SSL socket. |
| 15989 | StaticSocketDataProvider ssl_data; |
| 15990 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 15991 | |
| 15992 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 15993 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15994 | |
| 15995 | // Set up HTTP request. |
| 15996 | |
| 15997 | HttpRequestInfo http_request; |
| 15998 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15999 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16000 | |
| 16001 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16002 | MockWrite( |
| 16003 | "GET / HTTP/1.1\r\n" |
| 16004 | "Host: www.example.org\r\n" |
| 16005 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16006 | }; |
| 16007 | MockRead http_reads[] = { |
| 16008 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16009 | MockRead("Content-Length: 7\r\n\r\n"), |
| 16010 | MockRead("falafel"), |
| 16011 | MockRead(SYNCHRONOUS, OK), |
| 16012 | }; |
| 16013 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 16014 | http_writes, arraysize(http_writes)); |
| 16015 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16016 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16017 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16018 | |
| 16019 | // Preconnect an SSL socket. A preconnect is needed because connect jobs are |
| 16020 | // cancelled when a normal transaction is cancelled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 16021 | HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 16022 | http_stream_factory->PreconnectStreams(1, ssl_request); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16023 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16024 | |
| 16025 | // Start the HTTP request. Pool should stall. |
| 16026 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16027 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16028 | ASSERT_EQ(ERR_IO_PENDING, |
| 16029 | http_trans.Start(&http_request, http_callback.callback(), |
| 16030 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16031 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16032 | |
| 16033 | // The SSL connection will automatically be closed once the connection is |
| 16034 | // established, to let the HTTP request start. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16035 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16036 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16037 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16038 | EXPECT_EQ("falafel", response_data); |
| 16039 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16040 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16041 | } |
| 16042 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16043 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16044 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16045 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16046 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16047 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16048 | |
| 16049 | HttpRequestInfo request; |
| 16050 | request.method = "POST"; |
| 16051 | request.url = GURL("http://www.foo.com/"); |
| 16052 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16053 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16054 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16055 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16056 | // Send headers successfully, but get an error while sending the body. |
| 16057 | MockWrite data_writes[] = { |
| 16058 | MockWrite("POST / HTTP/1.1\r\n" |
| 16059 | "Host: www.foo.com\r\n" |
| 16060 | "Connection: keep-alive\r\n" |
| 16061 | "Content-Length: 3\r\n\r\n"), |
| 16062 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16063 | }; |
| 16064 | |
| 16065 | MockRead data_reads[] = { |
| 16066 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 16067 | MockRead("hello world"), |
| 16068 | MockRead(SYNCHRONOUS, OK), |
| 16069 | }; |
| 16070 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16071 | arraysize(data_writes)); |
| 16072 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16073 | |
| 16074 | TestCompletionCallback callback; |
| 16075 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16076 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16077 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16078 | |
| 16079 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16080 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16081 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16082 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16083 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16084 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16085 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16086 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 16087 | |
| 16088 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16089 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16090 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16091 | EXPECT_EQ("hello world", response_data); |
| 16092 | } |
| 16093 | |
| 16094 | // This test makes sure the retry logic doesn't trigger when reading an error |
| 16095 | // response from a server that rejected a POST with a CONNECTION_RESET. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16096 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16097 | PostReadsErrorResponseAfterResetOnReusedSocket) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16098 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16099 | MockWrite data_writes[] = { |
| 16100 | MockWrite("GET / HTTP/1.1\r\n" |
| 16101 | "Host: www.foo.com\r\n" |
| 16102 | "Connection: keep-alive\r\n\r\n"), |
| 16103 | MockWrite("POST / HTTP/1.1\r\n" |
| 16104 | "Host: www.foo.com\r\n" |
| 16105 | "Connection: keep-alive\r\n" |
| 16106 | "Content-Length: 3\r\n\r\n"), |
| 16107 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16108 | }; |
| 16109 | |
| 16110 | MockRead data_reads[] = { |
| 16111 | MockRead("HTTP/1.1 200 Peachy\r\n" |
| 16112 | "Content-Length: 14\r\n\r\n"), |
| 16113 | MockRead("first response"), |
| 16114 | MockRead("HTTP/1.1 400 Not OK\r\n" |
| 16115 | "Content-Length: 15\r\n\r\n"), |
| 16116 | MockRead("second response"), |
| 16117 | MockRead(SYNCHRONOUS, OK), |
| 16118 | }; |
| 16119 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16120 | arraysize(data_writes)); |
| 16121 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16122 | |
| 16123 | TestCompletionCallback callback; |
| 16124 | HttpRequestInfo request1; |
| 16125 | request1.method = "GET"; |
| 16126 | request1.url = GURL("http://www.foo.com/"); |
| 16127 | request1.load_flags = 0; |
| 16128 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16129 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16130 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16131 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16132 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16133 | |
| 16134 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16135 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16136 | |
| 16137 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16138 | ASSERT_TRUE(response1); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16139 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16140 | EXPECT_TRUE(response1->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16141 | EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine()); |
| 16142 | |
| 16143 | std::string response_data1; |
| 16144 | rv = ReadTransaction(trans1.get(), &response_data1); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16145 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16146 | EXPECT_EQ("first response", response_data1); |
| 16147 | // Delete the transaction to release the socket back into the socket pool. |
| 16148 | trans1.reset(); |
| 16149 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16150 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16151 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16152 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16153 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16154 | |
| 16155 | HttpRequestInfo request2; |
| 16156 | request2.method = "POST"; |
| 16157 | request2.url = GURL("http://www.foo.com/"); |
| 16158 | request2.upload_data_stream = &upload_data_stream; |
| 16159 | request2.load_flags = 0; |
| 16160 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16161 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16162 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16163 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16164 | |
| 16165 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16166 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16167 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16168 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16169 | ASSERT_TRUE(response2); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16170 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16171 | EXPECT_TRUE(response2->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16172 | EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine()); |
| 16173 | |
| 16174 | std::string response_data2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16175 | rv = ReadTransaction(&trans2, &response_data2); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16176 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16177 | EXPECT_EQ("second response", response_data2); |
| 16178 | } |
| 16179 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16180 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16181 | PostReadsErrorResponseAfterResetPartialBodySent) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16182 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16183 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16184 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16185 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16186 | |
| 16187 | HttpRequestInfo request; |
| 16188 | request.method = "POST"; |
| 16189 | request.url = GURL("http://www.foo.com/"); |
| 16190 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16191 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16192 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16193 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16194 | // Send headers successfully, but get an error while sending the body. |
| 16195 | MockWrite data_writes[] = { |
| 16196 | MockWrite("POST / HTTP/1.1\r\n" |
| 16197 | "Host: www.foo.com\r\n" |
| 16198 | "Connection: keep-alive\r\n" |
| 16199 | "Content-Length: 3\r\n\r\n" |
| 16200 | "fo"), |
| 16201 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16202 | }; |
| 16203 | |
| 16204 | MockRead data_reads[] = { |
| 16205 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 16206 | MockRead("hello world"), |
| 16207 | MockRead(SYNCHRONOUS, OK), |
| 16208 | }; |
| 16209 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16210 | arraysize(data_writes)); |
| 16211 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16212 | |
| 16213 | TestCompletionCallback callback; |
| 16214 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16215 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16216 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16217 | |
| 16218 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16219 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16220 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16221 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16222 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16223 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16224 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16225 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 16226 | |
| 16227 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16228 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16229 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16230 | EXPECT_EQ("hello world", response_data); |
| 16231 | } |
| 16232 | |
| 16233 | // This tests the more common case than the previous test, where headers and |
| 16234 | // body are not merged into a single request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16235 | TEST_F(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) { |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 16236 | ChunkedUploadDataStream upload_data_stream(0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16237 | |
| 16238 | HttpRequestInfo request; |
| 16239 | request.method = "POST"; |
| 16240 | request.url = GURL("http://www.foo.com/"); |
| 16241 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16242 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16243 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16244 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16245 | // Send headers successfully, but get an error while sending the body. |
| 16246 | MockWrite data_writes[] = { |
| 16247 | MockWrite("POST / HTTP/1.1\r\n" |
| 16248 | "Host: www.foo.com\r\n" |
| 16249 | "Connection: keep-alive\r\n" |
| 16250 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 16251 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16252 | }; |
| 16253 | |
| 16254 | MockRead data_reads[] = { |
| 16255 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 16256 | MockRead("hello world"), |
| 16257 | MockRead(SYNCHRONOUS, OK), |
| 16258 | }; |
| 16259 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16260 | arraysize(data_writes)); |
| 16261 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16262 | |
| 16263 | TestCompletionCallback callback; |
| 16264 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16265 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16266 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16267 | // Make sure the headers are sent before adding a chunk. This ensures that |
| 16268 | // they can't be merged with the body in a single send. Not currently |
| 16269 | // necessary since a chunked body is never merged with headers, but this makes |
| 16270 | // the test more future proof. |
| 16271 | base::RunLoop().RunUntilIdle(); |
| 16272 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 16273 | upload_data_stream.AppendData("last chunk", 10, true); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16274 | |
| 16275 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16276 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16277 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16278 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16279 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16280 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16281 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16282 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 16283 | |
| 16284 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16285 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16286 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16287 | EXPECT_EQ("hello world", response_data); |
| 16288 | } |
| 16289 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16290 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16291 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16292 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16293 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16294 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16295 | |
| 16296 | HttpRequestInfo request; |
| 16297 | request.method = "POST"; |
| 16298 | request.url = GURL("http://www.foo.com/"); |
| 16299 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16300 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16301 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16302 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16303 | |
| 16304 | MockWrite data_writes[] = { |
| 16305 | MockWrite("POST / HTTP/1.1\r\n" |
| 16306 | "Host: www.foo.com\r\n" |
| 16307 | "Connection: keep-alive\r\n" |
| 16308 | "Content-Length: 3\r\n\r\n"), |
| 16309 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16310 | }; |
| 16311 | |
| 16312 | MockRead data_reads[] = { |
| 16313 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 16314 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 16315 | MockRead("hello world"), |
| 16316 | MockRead(SYNCHRONOUS, OK), |
| 16317 | }; |
| 16318 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16319 | arraysize(data_writes)); |
| 16320 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16321 | |
| 16322 | TestCompletionCallback callback; |
| 16323 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16324 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16325 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16326 | |
| 16327 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16328 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16329 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16330 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16331 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16332 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16333 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16334 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 16335 | |
| 16336 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16337 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16338 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16339 | EXPECT_EQ("hello world", response_data); |
| 16340 | } |
| 16341 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16342 | TEST_F(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16343 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16344 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16345 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16346 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16347 | |
| 16348 | HttpRequestInfo request; |
| 16349 | request.method = "POST"; |
| 16350 | request.url = GURL("http://www.foo.com/"); |
| 16351 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16352 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16353 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16354 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16355 | // Send headers successfully, but get an error while sending the body. |
| 16356 | MockWrite data_writes[] = { |
| 16357 | MockWrite("POST / HTTP/1.1\r\n" |
| 16358 | "Host: www.foo.com\r\n" |
| 16359 | "Connection: keep-alive\r\n" |
| 16360 | "Content-Length: 3\r\n\r\n"), |
| 16361 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16362 | }; |
| 16363 | |
| 16364 | MockRead data_reads[] = { |
| 16365 | MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"), |
| 16366 | MockRead("hello world"), |
| 16367 | MockRead(SYNCHRONOUS, OK), |
| 16368 | }; |
| 16369 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16370 | arraysize(data_writes)); |
| 16371 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16372 | |
| 16373 | TestCompletionCallback callback; |
| 16374 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16375 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16376 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16377 | |
| 16378 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16379 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16380 | } |
| 16381 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16382 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16383 | PostIgnoresNonErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16384 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16385 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16386 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16387 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16388 | |
| 16389 | HttpRequestInfo request; |
| 16390 | request.method = "POST"; |
| 16391 | request.url = GURL("http://www.foo.com/"); |
| 16392 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16393 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16394 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16395 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16396 | // Send headers successfully, but get an error while sending the body. |
| 16397 | MockWrite data_writes[] = { |
| 16398 | MockWrite("POST / HTTP/1.1\r\n" |
| 16399 | "Host: www.foo.com\r\n" |
| 16400 | "Connection: keep-alive\r\n" |
| 16401 | "Content-Length: 3\r\n\r\n"), |
| 16402 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16403 | }; |
| 16404 | |
| 16405 | MockRead data_reads[] = { |
| 16406 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 16407 | MockRead("HTTP/1.0 302 Redirect\r\n"), |
| 16408 | MockRead("Location: http://somewhere-else.com/\r\n"), |
| 16409 | MockRead("Content-Length: 0\r\n\r\n"), |
| 16410 | MockRead(SYNCHRONOUS, OK), |
| 16411 | }; |
| 16412 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16413 | arraysize(data_writes)); |
| 16414 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16415 | |
| 16416 | TestCompletionCallback callback; |
| 16417 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16418 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16419 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16420 | |
| 16421 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16422 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16423 | } |
| 16424 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16425 | TEST_F(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16426 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16427 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16428 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16429 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16430 | |
| 16431 | HttpRequestInfo request; |
| 16432 | request.method = "POST"; |
| 16433 | request.url = GURL("http://www.foo.com/"); |
| 16434 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16435 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16436 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16437 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16438 | // Send headers successfully, but get an error while sending the body. |
| 16439 | MockWrite data_writes[] = { |
| 16440 | MockWrite("POST / HTTP/1.1\r\n" |
| 16441 | "Host: www.foo.com\r\n" |
| 16442 | "Connection: keep-alive\r\n" |
| 16443 | "Content-Length: 3\r\n\r\n"), |
| 16444 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16445 | }; |
| 16446 | |
| 16447 | MockRead data_reads[] = { |
| 16448 | MockRead("HTTP 0.9 rocks!"), |
| 16449 | MockRead(SYNCHRONOUS, OK), |
| 16450 | }; |
| 16451 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16452 | arraysize(data_writes)); |
| 16453 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16454 | |
| 16455 | TestCompletionCallback callback; |
| 16456 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16457 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16458 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16459 | |
| 16460 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16461 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16462 | } |
| 16463 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16464 | TEST_F(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16465 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16466 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16467 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16468 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16469 | |
| 16470 | HttpRequestInfo request; |
| 16471 | request.method = "POST"; |
| 16472 | request.url = GURL("http://www.foo.com/"); |
| 16473 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16474 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16475 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16476 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16477 | // Send headers successfully, but get an error while sending the body. |
| 16478 | MockWrite data_writes[] = { |
| 16479 | MockWrite("POST / HTTP/1.1\r\n" |
| 16480 | "Host: www.foo.com\r\n" |
| 16481 | "Connection: keep-alive\r\n" |
| 16482 | "Content-Length: 3\r\n\r\n"), |
| 16483 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16484 | }; |
| 16485 | |
| 16486 | MockRead data_reads[] = { |
| 16487 | MockRead("HTTP/1.0 400 Not a Full Response\r\n"), |
| 16488 | MockRead(SYNCHRONOUS, OK), |
| 16489 | }; |
| 16490 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16491 | arraysize(data_writes)); |
| 16492 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16493 | |
| 16494 | TestCompletionCallback callback; |
| 16495 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16496 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16497 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16498 | |
| 16499 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16500 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16501 | } |
| 16502 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16503 | // Verify that proxy headers are not sent to the destination server when |
| 16504 | // establishing a tunnel for a secure WebSocket connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16505 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWssTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16506 | HttpRequestInfo request; |
| 16507 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16508 | request.url = GURL("wss://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16509 | AddWebSocketHeaders(&request.extra_headers); |
| 16510 | |
| 16511 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 16512 | session_deps_.proxy_service = |
| 16513 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16514 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16515 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16516 | |
| 16517 | // Since a proxy is configured, try to establish a tunnel. |
| 16518 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16519 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 16520 | "Host: www.example.org:443\r\n" |
| 16521 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16522 | |
| 16523 | // After calling trans->RestartWithAuth(), this is the request we should |
| 16524 | // be issuing -- the final header line contains the credentials. |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16525 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 16526 | "Host: www.example.org:443\r\n" |
| 16527 | "Proxy-Connection: keep-alive\r\n" |
| 16528 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16529 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16530 | MockWrite("GET / HTTP/1.1\r\n" |
| 16531 | "Host: www.example.org\r\n" |
| 16532 | "Connection: Upgrade\r\n" |
| 16533 | "Upgrade: websocket\r\n" |
| 16534 | "Origin: http://www.example.org\r\n" |
| 16535 | "Sec-WebSocket-Version: 13\r\n" |
| 16536 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16537 | }; |
| 16538 | |
| 16539 | // The proxy responds to the connect with a 407, using a persistent |
| 16540 | // connection. |
| 16541 | MockRead data_reads[] = { |
| 16542 | // No credentials. |
| 16543 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 16544 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 16545 | MockRead("Content-Length: 0\r\n"), |
| 16546 | MockRead("Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16547 | |
| 16548 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 16549 | |
| 16550 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 16551 | MockRead("Upgrade: websocket\r\n"), |
| 16552 | MockRead("Connection: Upgrade\r\n"), |
| 16553 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 16554 | }; |
| 16555 | |
| 16556 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16557 | arraysize(data_writes)); |
| 16558 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16559 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 16560 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16561 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16562 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16563 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16564 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 16565 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 16566 | &websocket_stream_create_helper); |
| 16567 | |
| 16568 | { |
| 16569 | TestCompletionCallback callback; |
| 16570 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16571 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16572 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16573 | |
| 16574 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16575 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16576 | } |
| 16577 | |
| 16578 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 16579 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16580 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16581 | EXPECT_EQ(407, response->headers->response_code()); |
| 16582 | |
| 16583 | { |
| 16584 | TestCompletionCallback callback; |
| 16585 | |
| 16586 | int rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 16587 | callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16588 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16589 | |
| 16590 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16591 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16592 | } |
| 16593 | |
| 16594 | response = trans->GetResponseInfo(); |
| 16595 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16596 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16597 | |
| 16598 | EXPECT_EQ(101, response->headers->response_code()); |
| 16599 | |
| 16600 | trans.reset(); |
| 16601 | session->CloseAllConnections(); |
| 16602 | } |
| 16603 | |
| 16604 | // Verify that proxy headers are not sent to the destination server when |
| 16605 | // establishing a tunnel for an insecure WebSocket connection. |
| 16606 | // This requires the authentication info to be injected into the auth cache |
| 16607 | // due to crbug.com/395064 |
| 16608 | // TODO(ricea): Change to use a 407 response once issue 395064 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16609 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWsTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16610 | HttpRequestInfo request; |
| 16611 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16612 | request.url = GURL("ws://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16613 | AddWebSocketHeaders(&request.extra_headers); |
| 16614 | |
| 16615 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 16616 | session_deps_.proxy_service = |
| 16617 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16618 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16619 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16620 | |
| 16621 | MockWrite data_writes[] = { |
| 16622 | // Try to establish a tunnel for the WebSocket connection, with |
| 16623 | // credentials. Because WebSockets have a separate set of socket pools, |
| 16624 | // they cannot and will not use the same TCP/IP connection as the |
| 16625 | // preflight HTTP request. |
| 16626 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16627 | "CONNECT www.example.org:80 HTTP/1.1\r\n" |
| 16628 | "Host: www.example.org:80\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16629 | "Proxy-Connection: keep-alive\r\n" |
| 16630 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 16631 | |
| 16632 | MockWrite( |
| 16633 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16634 | "Host: www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16635 | "Connection: Upgrade\r\n" |
| 16636 | "Upgrade: websocket\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16637 | "Origin: http://www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16638 | "Sec-WebSocket-Version: 13\r\n" |
| 16639 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
| 16640 | }; |
| 16641 | |
| 16642 | MockRead data_reads[] = { |
| 16643 | // HTTP CONNECT with credentials. |
| 16644 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 16645 | |
| 16646 | // WebSocket connection established inside tunnel. |
| 16647 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 16648 | MockRead("Upgrade: websocket\r\n"), |
| 16649 | MockRead("Connection: Upgrade\r\n"), |
| 16650 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 16651 | }; |
| 16652 | |
| 16653 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16654 | arraysize(data_writes)); |
| 16655 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16656 | |
| 16657 | session->http_auth_cache()->Add( |
| 16658 | GURL("http://myproxy:70/"), "MyRealm1", HttpAuth::AUTH_SCHEME_BASIC, |
| 16659 | "Basic realm=MyRealm1", AuthCredentials(kFoo, kBar), "/"); |
| 16660 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16661 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16662 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16663 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 16664 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 16665 | &websocket_stream_create_helper); |
| 16666 | |
| 16667 | TestCompletionCallback callback; |
| 16668 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16669 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16670 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16671 | |
| 16672 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16673 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16674 | |
| 16675 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 16676 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16677 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16678 | |
| 16679 | EXPECT_EQ(101, response->headers->response_code()); |
| 16680 | |
| 16681 | trans.reset(); |
| 16682 | session->CloseAllConnections(); |
| 16683 | } |
| 16684 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16685 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16686 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16687 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16688 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16689 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16690 | |
| 16691 | HttpRequestInfo request; |
| 16692 | request.method = "POST"; |
| 16693 | request.url = GURL("http://www.foo.com/"); |
| 16694 | request.upload_data_stream = &upload_data_stream; |
| 16695 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16696 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16697 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16698 | MockWrite data_writes[] = { |
| 16699 | MockWrite("POST / HTTP/1.1\r\n" |
| 16700 | "Host: www.foo.com\r\n" |
| 16701 | "Connection: keep-alive\r\n" |
| 16702 | "Content-Length: 3\r\n\r\n"), |
| 16703 | MockWrite("foo"), |
| 16704 | }; |
| 16705 | |
| 16706 | MockRead data_reads[] = { |
| 16707 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16708 | MockRead(SYNCHRONOUS, OK), |
| 16709 | }; |
| 16710 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16711 | arraysize(data_writes)); |
| 16712 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16713 | |
| 16714 | TestCompletionCallback callback; |
| 16715 | |
| 16716 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16717 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16718 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16719 | |
| 16720 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16721 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16722 | |
| 16723 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16724 | trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16725 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16726 | trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16727 | } |
| 16728 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16729 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost100Continue) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16730 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16731 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16732 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16733 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16734 | |
| 16735 | HttpRequestInfo request; |
| 16736 | request.method = "POST"; |
| 16737 | request.url = GURL("http://www.foo.com/"); |
| 16738 | request.upload_data_stream = &upload_data_stream; |
| 16739 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16740 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16741 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16742 | MockWrite data_writes[] = { |
| 16743 | MockWrite("POST / HTTP/1.1\r\n" |
| 16744 | "Host: www.foo.com\r\n" |
| 16745 | "Connection: keep-alive\r\n" |
| 16746 | "Content-Length: 3\r\n\r\n"), |
| 16747 | MockWrite("foo"), |
| 16748 | }; |
| 16749 | |
| 16750 | MockRead data_reads[] = { |
| 16751 | MockRead("HTTP/1.1 100 Continue\r\n\r\n"), |
| 16752 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16753 | MockRead(SYNCHRONOUS, OK), |
| 16754 | }; |
| 16755 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16756 | arraysize(data_writes)); |
| 16757 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16758 | |
| 16759 | TestCompletionCallback callback; |
| 16760 | |
| 16761 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16762 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16763 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16764 | |
| 16765 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16766 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16767 | |
| 16768 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16769 | trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16770 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16771 | trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16772 | } |
| 16773 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16774 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesChunkedPost) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16775 | ChunkedUploadDataStream upload_data_stream(0); |
| 16776 | |
| 16777 | HttpRequestInfo request; |
| 16778 | request.method = "POST"; |
| 16779 | request.url = GURL("http://www.foo.com/"); |
| 16780 | request.upload_data_stream = &upload_data_stream; |
| 16781 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16782 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16783 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16784 | // Send headers successfully, but get an error while sending the body. |
| 16785 | MockWrite data_writes[] = { |
| 16786 | MockWrite("POST / HTTP/1.1\r\n" |
| 16787 | "Host: www.foo.com\r\n" |
| 16788 | "Connection: keep-alive\r\n" |
| 16789 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 16790 | MockWrite("1\r\nf\r\n"), MockWrite("2\r\noo\r\n"), MockWrite("0\r\n\r\n"), |
| 16791 | }; |
| 16792 | |
| 16793 | MockRead data_reads[] = { |
| 16794 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16795 | MockRead(SYNCHRONOUS, OK), |
| 16796 | }; |
| 16797 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16798 | arraysize(data_writes)); |
| 16799 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16800 | |
| 16801 | TestCompletionCallback callback; |
| 16802 | |
| 16803 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16804 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16805 | |
| 16806 | base::RunLoop().RunUntilIdle(); |
| 16807 | upload_data_stream.AppendData("f", 1, false); |
| 16808 | |
| 16809 | base::RunLoop().RunUntilIdle(); |
| 16810 | upload_data_stream.AppendData("oo", 2, true); |
| 16811 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16812 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16813 | |
| 16814 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16815 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16816 | |
| 16817 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16818 | trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16819 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16820 | trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16821 | } |
| 16822 | |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16823 | // Confirm that transactions whose throttle is created in (and stays in) |
| 16824 | // the unthrottled state are not blocked. |
| 16825 | TEST_F(HttpNetworkTransactionTest, ThrottlingUnthrottled) { |
| 16826 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16827 | std::unique_ptr<HttpNetworkSession> session( |
| 16828 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16829 | |
| 16830 | // Send a simple request and make sure it goes through. |
| 16831 | HttpRequestInfo request; |
| 16832 | request.method = "GET"; |
| 16833 | request.url = GURL("http://www.example.org/"); |
| 16834 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16835 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16836 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16837 | |
| 16838 | MockWrite data_writes[] = { |
| 16839 | MockWrite("GET / HTTP/1.1\r\n" |
| 16840 | "Host: www.example.org\r\n" |
| 16841 | "Connection: keep-alive\r\n\r\n"), |
| 16842 | }; |
| 16843 | MockRead data_reads[] = { |
| 16844 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16845 | MockRead(SYNCHRONOUS, OK), |
| 16846 | }; |
| 16847 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16848 | arraysize(data_writes)); |
| 16849 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16850 | |
| 16851 | TestCompletionCallback callback; |
| 16852 | trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16853 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 16854 | } |
| 16855 | |
| 16856 | // Confirm requests can be blocked by a throttler, and are resumed |
| 16857 | // when the throttle is unblocked. |
| 16858 | TEST_F(HttpNetworkTransactionTest, ThrottlingBasic) { |
| 16859 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16860 | std::unique_ptr<HttpNetworkSession> session( |
| 16861 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16862 | |
| 16863 | // Send a simple request and make sure it goes through. |
| 16864 | HttpRequestInfo request; |
| 16865 | request.method = "GET"; |
| 16866 | request.url = GURL("http://www.example.org/"); |
| 16867 | |
| 16868 | MockWrite data_writes[] = { |
| 16869 | MockWrite("GET / HTTP/1.1\r\n" |
| 16870 | "Host: www.example.org\r\n" |
| 16871 | "Connection: keep-alive\r\n\r\n"), |
| 16872 | }; |
| 16873 | MockRead data_reads[] = { |
| 16874 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16875 | MockRead(SYNCHRONOUS, OK), |
| 16876 | }; |
| 16877 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16878 | arraysize(data_writes)); |
| 16879 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16880 | |
| 16881 | // Start a request that will be throttled at start; confirm it |
| 16882 | // doesn't complete. |
| 16883 | throttler->set_throttle_new_requests(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16884 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16885 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16886 | |
| 16887 | TestCompletionCallback callback; |
| 16888 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16889 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16890 | |
| 16891 | base::RunLoop().RunUntilIdle(); |
| 16892 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 16893 | EXPECT_FALSE(callback.have_result()); |
| 16894 | |
| 16895 | // Confirm the request goes on to complete when unthrottled. |
| 16896 | throttler->UnthrottleAllRequests(); |
| 16897 | base::RunLoop().RunUntilIdle(); |
| 16898 | ASSERT_TRUE(callback.have_result()); |
| 16899 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 16900 | } |
| 16901 | |
| 16902 | // Destroy a request while it's throttled. |
| 16903 | TEST_F(HttpNetworkTransactionTest, ThrottlingDestruction) { |
| 16904 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16905 | std::unique_ptr<HttpNetworkSession> session( |
| 16906 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16907 | |
| 16908 | // Send a simple request and make sure it goes through. |
| 16909 | HttpRequestInfo request; |
| 16910 | request.method = "GET"; |
| 16911 | request.url = GURL("http://www.example.org/"); |
| 16912 | |
| 16913 | MockWrite data_writes[] = { |
| 16914 | MockWrite("GET / HTTP/1.1\r\n" |
| 16915 | "Host: www.example.org\r\n" |
| 16916 | "Connection: keep-alive\r\n\r\n"), |
| 16917 | }; |
| 16918 | MockRead data_reads[] = { |
| 16919 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16920 | MockRead(SYNCHRONOUS, OK), |
| 16921 | }; |
| 16922 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16923 | arraysize(data_writes)); |
| 16924 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16925 | |
| 16926 | // Start a request that will be throttled at start; confirm it |
| 16927 | // doesn't complete. |
| 16928 | throttler->set_throttle_new_requests(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16929 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16930 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16931 | |
| 16932 | TestCompletionCallback callback; |
| 16933 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16934 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16935 | |
| 16936 | base::RunLoop().RunUntilIdle(); |
| 16937 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 16938 | EXPECT_FALSE(callback.have_result()); |
| 16939 | |
| 16940 | EXPECT_EQ(1u, throttler->num_outstanding_requests()); |
| 16941 | trans.reset(); |
| 16942 | EXPECT_EQ(0u, throttler->num_outstanding_requests()); |
| 16943 | } |
| 16944 | |
| 16945 | // Confirm the throttler receives SetPriority calls. |
| 16946 | TEST_F(HttpNetworkTransactionTest, ThrottlingPrioritySet) { |
| 16947 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16948 | std::unique_ptr<HttpNetworkSession> session( |
| 16949 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16950 | |
| 16951 | // Send a simple request and make sure it goes through. |
| 16952 | HttpRequestInfo request; |
| 16953 | request.method = "GET"; |
| 16954 | request.url = GURL("http://www.example.org/"); |
| 16955 | |
| 16956 | MockWrite data_writes[] = { |
| 16957 | MockWrite("GET / HTTP/1.1\r\n" |
| 16958 | "Host: www.example.org\r\n" |
| 16959 | "Connection: keep-alive\r\n\r\n"), |
| 16960 | }; |
| 16961 | MockRead data_reads[] = { |
| 16962 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16963 | MockRead(SYNCHRONOUS, OK), |
| 16964 | }; |
| 16965 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16966 | arraysize(data_writes)); |
| 16967 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16968 | |
| 16969 | throttler->set_throttle_new_requests(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16970 | auto trans = std::make_unique<HttpNetworkTransaction>(IDLE, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16971 | // Start the transaction to associate a throttle with it. |
| 16972 | TestCompletionCallback callback; |
| 16973 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16974 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16975 | |
| 16976 | EXPECT_EQ(0, throttler->num_set_priority_calls()); |
| 16977 | trans->SetPriority(LOW); |
| 16978 | EXPECT_EQ(1, throttler->num_set_priority_calls()); |
| 16979 | EXPECT_EQ(LOW, throttler->last_priority_set()); |
| 16980 | |
| 16981 | throttler->UnthrottleAllRequests(); |
| 16982 | base::RunLoop().RunUntilIdle(); |
| 16983 | ASSERT_TRUE(callback.have_result()); |
| 16984 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 16985 | } |
| 16986 | |
| 16987 | // Confirm that unthrottling from a SetPriority call by the |
| 16988 | // throttler works properly. |
| 16989 | TEST_F(HttpNetworkTransactionTest, ThrottlingPrioritySetUnthrottle) { |
| 16990 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16991 | std::unique_ptr<HttpNetworkSession> session( |
| 16992 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16993 | |
| 16994 | // Send a simple request and make sure it goes through. |
| 16995 | HttpRequestInfo request; |
| 16996 | request.method = "GET"; |
| 16997 | request.url = GURL("http://www.example.org/"); |
| 16998 | |
| 16999 | MockWrite data_writes[] = { |
| 17000 | MockWrite("GET / HTTP/1.1\r\n" |
| 17001 | "Host: www.example.org\r\n" |
| 17002 | "Connection: keep-alive\r\n\r\n"), |
| 17003 | }; |
| 17004 | MockRead data_reads[] = { |
| 17005 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17006 | MockRead(SYNCHRONOUS, OK), |
| 17007 | }; |
| 17008 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 17009 | arraysize(data_writes)); |
| 17010 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 17011 | |
| 17012 | StaticSocketDataProvider reads1(data_reads, arraysize(data_reads), |
| 17013 | data_writes, arraysize(data_writes)); |
| 17014 | session_deps_.socket_factory->AddSocketDataProvider(&reads1); |
| 17015 | |
| 17016 | // Start a request that will be throttled at start; confirm it |
| 17017 | // doesn't complete. |
| 17018 | throttler->set_throttle_new_requests(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17019 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17020 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17021 | |
| 17022 | TestCompletionCallback callback; |
| 17023 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 17024 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 17025 | |
| 17026 | base::RunLoop().RunUntilIdle(); |
| 17027 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 17028 | EXPECT_FALSE(callback.have_result()); |
| 17029 | |
| 17030 | // Create a new request, call SetPriority on it to unthrottle, |
| 17031 | // and make sure that allows the original request to complete. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17032 | auto trans1 = std::make_unique<HttpNetworkTransaction>(LOW, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17033 | throttler->set_priority_change_closure( |
| 17034 | base::Bind(&TestNetworkStreamThrottler::UnthrottleAllRequests, |
| 17035 | base::Unretained(throttler))); |
| 17036 | |
| 17037 | // Start the transaction to associate a throttle with it. |
| 17038 | TestCompletionCallback callback1; |
| 17039 | rv = trans1->Start(&request, callback1.callback(), NetLogWithSource()); |
| 17040 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 17041 | |
| 17042 | trans1->SetPriority(IDLE); |
| 17043 | |
| 17044 | base::RunLoop().RunUntilIdle(); |
| 17045 | ASSERT_TRUE(callback.have_result()); |
| 17046 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 17047 | ASSERT_TRUE(callback1.have_result()); |
| 17048 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 17049 | } |
| 17050 | |
| 17051 | // Transaction will be destroyed when the unique_ptr goes out of scope. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17052 | void DestroyTransaction(std::unique_ptr<HttpNetworkTransaction> transaction) {} |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17053 | |
| 17054 | // Confirm that destroying a transaction from a SetPriority call by the |
| 17055 | // throttler works properly. |
| 17056 | TEST_F(HttpNetworkTransactionTest, ThrottlingPrioritySetDestroy) { |
| 17057 | TestNetworkStreamThrottler* throttler(nullptr); |
| 17058 | std::unique_ptr<HttpNetworkSession> session( |
| 17059 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 17060 | |
| 17061 | // Send a simple request and make sure it goes through. |
| 17062 | HttpRequestInfo request; |
| 17063 | request.method = "GET"; |
| 17064 | request.url = GURL("http://www.example.org/"); |
| 17065 | |
| 17066 | MockWrite data_writes[] = { |
| 17067 | MockWrite("GET / HTTP/1.1\r\n" |
| 17068 | "Host: www.example.org\r\n" |
| 17069 | "Connection: keep-alive\r\n\r\n"), |
| 17070 | }; |
| 17071 | MockRead data_reads[] = { |
| 17072 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17073 | MockRead(SYNCHRONOUS, OK), |
| 17074 | }; |
| 17075 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 17076 | arraysize(data_writes)); |
| 17077 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 17078 | |
| 17079 | StaticSocketDataProvider reads1(data_reads, arraysize(data_reads), |
| 17080 | data_writes, arraysize(data_writes)); |
| 17081 | session_deps_.socket_factory->AddSocketDataProvider(&reads1); |
| 17082 | |
| 17083 | // Start a request that will be throttled at start; confirm it |
| 17084 | // doesn't complete. |
| 17085 | throttler->set_throttle_new_requests(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17086 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17087 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17088 | |
| 17089 | TestCompletionCallback callback; |
| 17090 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 17091 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 17092 | |
| 17093 | base::RunLoop().RunUntilIdle(); |
| 17094 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 17095 | EXPECT_FALSE(callback.have_result()); |
| 17096 | |
| 17097 | // Arrange for the set priority call on the above transaction to delete |
| 17098 | // the transaction. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17099 | HttpNetworkTransaction* trans_ptr(trans.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17100 | throttler->set_priority_change_closure( |
| 17101 | base::Bind(&DestroyTransaction, base::Passed(&trans))); |
| 17102 | |
| 17103 | // Call it and check results (partially a "doesn't crash" test). |
| 17104 | trans_ptr->SetPriority(IDLE); |
| 17105 | trans_ptr = nullptr; // No longer a valid pointer. |
| 17106 | |
| 17107 | base::RunLoop().RunUntilIdle(); |
| 17108 | ASSERT_FALSE(callback.have_result()); |
| 17109 | } |
| 17110 | |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17111 | #if !defined(OS_IOS) |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17112 | TEST_F(HttpNetworkTransactionTest, TokenBindingSpdy) { |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17113 | const std::string https_url = "https://www.example.com"; |
| 17114 | HttpRequestInfo request; |
| 17115 | request.url = GURL(https_url); |
| 17116 | request.method = "GET"; |
| 17117 | |
| 17118 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 17119 | ssl.token_binding_negotiated = true; |
| 17120 | ssl.token_binding_key_param = TB_PARAM_ECDSAP256; |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 17121 | ssl.next_proto = kProtoHTTP2; |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17122 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 17123 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 17124 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17125 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 17126 | MockRead reads[] = {CreateMockRead(resp), CreateMockRead(body), |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17127 | MockRead(ASYNC, ERR_IO_PENDING)}; |
| 17128 | StaticSocketDataProvider data(reads, arraysize(reads), nullptr, 0); |
| 17129 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17130 | session_deps_.channel_id_service = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17131 | std::make_unique<ChannelIDService>(new DefaultChannelIDStore(nullptr)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17132 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17133 | |
| 17134 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17135 | TestCompletionCallback callback; |
| 17136 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17137 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
fdoray | f33fede | 2017-05-11 21:18:10 | [diff] [blame] | 17138 | |
| 17139 | NetTestSuite::GetScopedTaskEnvironment()->RunUntilIdle(); |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17140 | |
| 17141 | EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); |
| 17142 | HttpRequestHeaders headers; |
| 17143 | ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); |
| 17144 | EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); |
| 17145 | } |
| 17146 | #endif // !defined(OS_IOS) |
| 17147 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17148 | void CheckContentEncodingMatching(SpdySessionDependencies* session_deps, |
| 17149 | const std::string& accept_encoding, |
| 17150 | const std::string& content_encoding, |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17151 | const std::string& location, |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17152 | bool should_match) { |
| 17153 | HttpRequestInfo request; |
| 17154 | request.method = "GET"; |
| 17155 | request.url = GURL("http://www.foo.com/"); |
| 17156 | request.extra_headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, |
| 17157 | accept_encoding); |
| 17158 | |
| 17159 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps)); |
| 17160 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17161 | // Send headers successfully, but get an error while sending the body. |
| 17162 | MockWrite data_writes[] = { |
| 17163 | MockWrite("GET / HTTP/1.1\r\n" |
| 17164 | "Host: www.foo.com\r\n" |
| 17165 | "Connection: keep-alive\r\n" |
| 17166 | "Accept-Encoding: "), |
| 17167 | MockWrite(accept_encoding.data()), MockWrite("\r\n\r\n"), |
| 17168 | }; |
| 17169 | |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17170 | std::string response_code = "200 OK"; |
| 17171 | std::string extra; |
| 17172 | if (!location.empty()) { |
| 17173 | response_code = "301 Redirect\r\nLocation: "; |
| 17174 | response_code.append(location); |
| 17175 | } |
| 17176 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17177 | MockRead data_reads[] = { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17178 | MockRead("HTTP/1.0 "), |
| 17179 | MockRead(response_code.data()), |
| 17180 | MockRead("\r\nContent-Encoding: "), |
| 17181 | MockRead(content_encoding.data()), |
| 17182 | MockRead("\r\n\r\n"), |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17183 | MockRead(SYNCHRONOUS, OK), |
| 17184 | }; |
| 17185 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 17186 | arraysize(data_writes)); |
| 17187 | session_deps->socket_factory->AddSocketDataProvider(&data); |
| 17188 | |
| 17189 | TestCompletionCallback callback; |
| 17190 | |
| 17191 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17192 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17193 | |
| 17194 | rv = callback.WaitForResult(); |
| 17195 | if (should_match) { |
| 17196 | EXPECT_THAT(rv, IsOk()); |
| 17197 | } else { |
| 17198 | EXPECT_THAT(rv, IsError(ERR_CONTENT_DECODING_FAILED)); |
| 17199 | } |
| 17200 | } |
| 17201 | |
| 17202 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding1) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17203 | CheckContentEncodingMatching(&session_deps_, "gzip,sdch", "br", "", false); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17204 | } |
| 17205 | |
| 17206 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding2) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17207 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "", "", |
| 17208 | true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17209 | } |
| 17210 | |
| 17211 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding3) { |
| 17212 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17213 | "", false); |
| 17214 | } |
| 17215 | |
| 17216 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding4) { |
| 17217 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
| 17218 | "www.foo.com/other", true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17219 | } |
| 17220 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17221 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsSync) { |
| 17222 | ProxyConfig proxy_config; |
| 17223 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 17224 | proxy_config.set_pac_mandatory(true); |
| 17225 | MockAsyncProxyResolver resolver; |
| 17226 | session_deps_.proxy_service.reset(new ProxyService( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17227 | std::make_unique<ProxyConfigServiceFixed>(proxy_config), |
Bence Béky | 8f9d7d395 | 2017-10-09 19:58:04 | [diff] [blame^] | 17228 | std::make_unique<FailingProxyResolverFactory>(), nullptr)); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17229 | |
| 17230 | HttpRequestInfo request; |
| 17231 | request.method = "GET"; |
| 17232 | request.url = GURL("http://www.example.org/"); |
| 17233 | |
| 17234 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 17235 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17236 | |
| 17237 | TestCompletionCallback callback; |
| 17238 | |
| 17239 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17240 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17241 | EXPECT_THAT(callback.WaitForResult(), |
| 17242 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 17243 | } |
| 17244 | |
| 17245 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsAsync) { |
| 17246 | ProxyConfig proxy_config; |
| 17247 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 17248 | proxy_config.set_pac_mandatory(true); |
| 17249 | MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 17250 | new MockAsyncProxyResolverFactory(false); |
| 17251 | MockAsyncProxyResolver resolver; |
| 17252 | session_deps_.proxy_service.reset( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17253 | new ProxyService(std::make_unique<ProxyConfigServiceFixed>(proxy_config), |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17254 | base::WrapUnique(proxy_resolver_factory), nullptr)); |
| 17255 | HttpRequestInfo request; |
| 17256 | request.method = "GET"; |
| 17257 | request.url = GURL("http://www.example.org/"); |
| 17258 | |
| 17259 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 17260 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17261 | |
| 17262 | TestCompletionCallback callback; |
| 17263 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17264 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17265 | |
| 17266 | proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder( |
| 17267 | ERR_FAILED, &resolver); |
| 17268 | EXPECT_THAT(callback.WaitForResult(), |
| 17269 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 17270 | } |
| 17271 | |
| 17272 | TEST_F(HttpNetworkTransactionTest, NoSupportedProxies) { |
| 17273 | session_deps_.proxy_service = |
| 17274 | ProxyService::CreateFixedFromPacResult("QUIC myproxy.org:443"); |
| 17275 | session_deps_.enable_quic = false; |
| 17276 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 17277 | |
| 17278 | HttpRequestInfo request; |
| 17279 | request.method = "GET"; |
| 17280 | request.url = GURL("http://www.example.org/"); |
| 17281 | |
| 17282 | TestCompletionCallback callback; |
| 17283 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17284 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17285 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17286 | |
| 17287 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_NO_SUPPORTED_PROXIES)); |
| 17288 | } |
| 17289 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 17290 | } // namespace net |