[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" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 45 | #include "net/cert/mock_cert_verifier.h" |
[email protected] | bc71b877 | 2013-04-10 20:55:16 | [diff] [blame] | 46 | #include "net/dns/host_cache.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 47 | #include "net/dns/mock_host_resolver.h" |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 48 | #include "net/http/http_auth_challenge_tokenizer.h" |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 49 | #include "net/http/http_auth_handler_digest.h" |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 50 | #include "net/http/http_auth_handler_mock.h" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 51 | #include "net/http/http_auth_handler_ntlm.h" |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 52 | #include "net/http/http_auth_scheme.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 53 | #include "net/http/http_basic_state.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 54 | #include "net/http/http_basic_stream.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 55 | #include "net/http/http_network_session.h" |
[email protected] | 87bfa3f | 2010-09-30 14:54:56 | [diff] [blame] | 56 | #include "net/http/http_network_session_peer.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 57 | #include "net/http/http_request_headers.h" |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 58 | #include "net/http/http_response_info.h" |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 59 | #include "net/http/http_server_properties_impl.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 60 | #include "net/http/http_stream.h" |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 61 | #include "net/http/http_stream_factory.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 62 | #include "net/http/http_stream_parser.h" |
[email protected] | c41737d | 2014-05-14 07:47:19 | [diff] [blame] | 63 | #include "net/http/http_transaction_test_util.h" |
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 64 | #include "net/log/net_log.h" |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 65 | #include "net/log/net_log_event_type.h" |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 66 | #include "net/log/net_log_source.h" |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 67 | #include "net/log/test_net_log.h" |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 68 | #include "net/log/test_net_log_entry.h" |
| 69 | #include "net/log/test_net_log_util.h" |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 70 | #include "net/proxy/mock_proxy_resolver.h" |
[email protected] | 51fff29d | 2008-12-19 22:17:53 | [diff] [blame] | 71 | #include "net/proxy/proxy_config_service_fixed.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 72 | #include "net/proxy/proxy_info.h" |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 73 | #include "net/proxy/proxy_resolver.h" |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 74 | #include "net/proxy/proxy_resolver_factory.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 75 | #include "net/proxy/proxy_server.h" |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 76 | #include "net/proxy/proxy_service.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 77 | #include "net/socket/client_socket_factory.h" |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 78 | #include "net/socket/client_socket_pool.h" |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 79 | #include "net/socket/client_socket_pool_manager.h" |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 80 | #include "net/socket/connection_attempts.h" |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 81 | #include "net/socket/mock_client_socket_pool_manager.h" |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 82 | #include "net/socket/next_proto.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 83 | #include "net/socket/socket_test_util.h" |
| 84 | #include "net/socket/ssl_client_socket.h" |
bnc | 8f8f7d30 | 2017-04-24 18:08:06 | [diff] [blame] | 85 | #include "net/spdy/chromium/spdy_session.h" |
| 86 | #include "net/spdy/chromium/spdy_session_pool.h" |
| 87 | #include "net/spdy/chromium/spdy_test_util_common.h" |
| 88 | #include "net/spdy/core/spdy_framer.h" |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 89 | #include "net/ssl/default_channel_id_store.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 90 | #include "net/ssl/ssl_cert_request_info.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 91 | #include "net/ssl/ssl_config_service.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 92 | #include "net/ssl/ssl_config_service_defaults.h" |
| 93 | #include "net/ssl/ssl_info.h" |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 94 | #include "net/ssl/ssl_private_key.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 95 | #include "net/test/cert_test_util.h" |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 96 | #include "net/test/gtest_util.h" |
fdoray | f33fede | 2017-05-11 21:18:10 | [diff] [blame] | 97 | #include "net/test/net_test_suite.h" |
rsleevi | a69c79a | 2016-06-22 03:28:43 | [diff] [blame] | 98 | #include "net/test/test_data_directory.h" |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 99 | #include "net/websockets/websocket_handshake_stream_base.h" |
bnc | f458840 | 2015-11-24 13:33:18 | [diff] [blame] | 100 | #include "testing/gmock/include/gmock/gmock.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 101 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 23887f04f | 2008-12-02 19:20:15 | [diff] [blame] | 102 | #include "testing/platform_test.h" |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 103 | #include "url/gurl.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 104 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 105 | using net::test::IsError; |
| 106 | using net::test::IsOk; |
| 107 | |
[email protected] | ad65a3e | 2013-12-25 18:18:01 | [diff] [blame] | 108 | using base::ASCIIToUTF16; |
| 109 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 110 | //----------------------------------------------------------------------------- |
| 111 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 112 | namespace net { |
| 113 | |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 114 | namespace { |
| 115 | |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 116 | class TestNetworkStreamThrottler : public NetworkThrottleManager { |
| 117 | public: |
| 118 | TestNetworkStreamThrottler() |
| 119 | : throttle_new_requests_(false), |
| 120 | num_set_priority_calls_(0), |
| 121 | last_priority_set_(IDLE) {} |
| 122 | |
| 123 | ~TestNetworkStreamThrottler() override { |
| 124 | EXPECT_TRUE(outstanding_throttles_.empty()); |
| 125 | } |
| 126 | |
| 127 | // NetworkThrottleManager |
| 128 | std::unique_ptr<Throttle> CreateThrottle(ThrottleDelegate* delegate, |
| 129 | RequestPriority priority, |
| 130 | bool ignore_limits) override { |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 131 | auto test_throttle = |
| 132 | base::MakeUnique<TestThrottle>(throttle_new_requests_, delegate, this); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 133 | outstanding_throttles_.insert(test_throttle.get()); |
| 134 | return std::move(test_throttle); |
| 135 | } |
| 136 | |
| 137 | void UnthrottleAllRequests() { |
| 138 | std::set<TestThrottle*> outstanding_throttles_copy(outstanding_throttles_); |
vmpstr | 6d9996c8 | 2017-02-23 00:43:25 | [diff] [blame] | 139 | for (auto* throttle : outstanding_throttles_copy) { |
rdsmith | bf8c3c1 | 2016-11-18 18:16:24 | [diff] [blame] | 140 | if (throttle->IsBlocked()) |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 141 | throttle->Unthrottle(); |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | void set_throttle_new_requests(bool throttle_new_requests) { |
| 146 | throttle_new_requests_ = throttle_new_requests; |
| 147 | } |
| 148 | |
| 149 | // Includes both throttled and unthrottled throttles. |
| 150 | size_t num_outstanding_requests() const { |
| 151 | return outstanding_throttles_.size(); |
| 152 | } |
| 153 | |
| 154 | int num_set_priority_calls() const { return num_set_priority_calls_; } |
| 155 | RequestPriority last_priority_set() const { return last_priority_set_; } |
| 156 | void set_priority_change_closure( |
| 157 | const base::Closure& priority_change_closure) { |
| 158 | priority_change_closure_ = priority_change_closure; |
| 159 | } |
| 160 | |
| 161 | private: |
| 162 | class TestThrottle : public NetworkThrottleManager::Throttle { |
| 163 | public: |
| 164 | ~TestThrottle() override { throttler_->OnThrottleDestroyed(this); } |
| 165 | |
| 166 | // Throttle |
rdsmith | bf8c3c1 | 2016-11-18 18:16:24 | [diff] [blame] | 167 | bool IsBlocked() const override { return throttled_; } |
| 168 | RequestPriority Priority() const override { |
| 169 | NOTREACHED(); |
| 170 | return IDLE; |
| 171 | } |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 172 | void SetPriority(RequestPriority priority) override { |
| 173 | throttler_->SetPriorityCalled(priority); |
| 174 | } |
| 175 | |
| 176 | TestThrottle(bool throttled, |
| 177 | ThrottleDelegate* delegate, |
| 178 | TestNetworkStreamThrottler* throttler) |
| 179 | : throttled_(throttled), delegate_(delegate), throttler_(throttler) {} |
| 180 | |
| 181 | void Unthrottle() { |
| 182 | EXPECT_TRUE(throttled_); |
| 183 | |
| 184 | throttled_ = false; |
rdsmith | bf8c3c1 | 2016-11-18 18:16:24 | [diff] [blame] | 185 | delegate_->OnThrottleUnblocked(this); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | bool throttled_; |
| 189 | ThrottleDelegate* delegate_; |
| 190 | TestNetworkStreamThrottler* throttler_; |
| 191 | }; |
| 192 | |
| 193 | void OnThrottleDestroyed(TestThrottle* throttle) { |
| 194 | EXPECT_NE(0u, outstanding_throttles_.count(throttle)); |
| 195 | outstanding_throttles_.erase(throttle); |
| 196 | } |
| 197 | |
| 198 | void SetPriorityCalled(RequestPriority priority) { |
| 199 | ++num_set_priority_calls_; |
| 200 | last_priority_set_ = priority; |
| 201 | if (!priority_change_closure_.is_null()) |
| 202 | priority_change_closure_.Run(); |
| 203 | } |
| 204 | |
| 205 | // Includes both throttled and unthrottled throttles. |
| 206 | std::set<TestThrottle*> outstanding_throttles_; |
| 207 | bool throttle_new_requests_; |
| 208 | int num_set_priority_calls_; |
| 209 | RequestPriority last_priority_set_; |
| 210 | base::Closure priority_change_closure_; |
| 211 | |
| 212 | DISALLOW_COPY_AND_ASSIGN(TestNetworkStreamThrottler); |
| 213 | }; |
| 214 | |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 215 | const base::string16 kBar(ASCIIToUTF16("bar")); |
| 216 | const base::string16 kBar2(ASCIIToUTF16("bar2")); |
| 217 | const base::string16 kBar3(ASCIIToUTF16("bar3")); |
| 218 | const base::string16 kBaz(ASCIIToUTF16("baz")); |
| 219 | const base::string16 kFirst(ASCIIToUTF16("first")); |
| 220 | const base::string16 kFoo(ASCIIToUTF16("foo")); |
| 221 | const base::string16 kFoo2(ASCIIToUTF16("foo2")); |
| 222 | const base::string16 kFoo3(ASCIIToUTF16("foo3")); |
| 223 | const base::string16 kFou(ASCIIToUTF16("fou")); |
| 224 | const base::string16 kSecond(ASCIIToUTF16("second")); |
| 225 | const base::string16 kTestingNTLM(ASCIIToUTF16("testing-ntlm")); |
| 226 | const base::string16 kWrongPassword(ASCIIToUTF16("wrongpassword")); |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 227 | |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 228 | const char kAlternativeServiceHttpHeader[] = |
| 229 | "Alt-Svc: h2=\"mail.example.org:443\"\r\n"; |
| 230 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 231 | int GetIdleSocketCountInTransportSocketPool(HttpNetworkSession* session) { |
| 232 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 233 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 234 | } |
| 235 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 236 | int GetIdleSocketCountInSSLSocketPool(HttpNetworkSession* session) { |
| 237 | return session->GetSSLSocketPool(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 | bool IsTransportSocketPoolStalled(HttpNetworkSession* session) { |
| 242 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 243 | ->IsStalled(); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 244 | } |
| 245 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 246 | // Takes in a Value created from a NetLogHttpResponseParameter, and returns |
| 247 | // a JSONified list of headers as a single string. Uses single quotes instead |
| 248 | // of double quotes for easier comparison. Returns false on failure. |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 249 | bool GetHeaders(base::DictionaryValue* params, std::string* headers) { |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 250 | if (!params) |
| 251 | return false; |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 252 | base::ListValue* header_list; |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 253 | if (!params->GetList("headers", &header_list)) |
| 254 | return false; |
| 255 | std::string double_quote_headers; |
estade | 8d04646 | 2015-05-16 01:02:34 | [diff] [blame] | 256 | base::JSONWriter::Write(*header_list, &double_quote_headers); |
[email protected] | 466c986 | 2013-12-03 22:05:28 | [diff] [blame] | 257 | base::ReplaceChars(double_quote_headers, "\"", "'", headers); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 258 | return true; |
| 259 | } |
| 260 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 261 | // Tests LoadTimingInfo in the case a socket is reused and no PAC script is |
| 262 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 263 | void TestLoadTimingReused(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 264 | EXPECT_TRUE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 265 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 266 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 267 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 268 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 269 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 270 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 271 | EXPECT_FALSE(load_timing_info.send_start.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 272 | |
| 273 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 274 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 275 | // Set at a higher level. |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 276 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 277 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 278 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 279 | } |
| 280 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 281 | // Tests LoadTimingInfo in the case a new socket is used and no PAC script is |
| 282 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 283 | void TestLoadTimingNotReused(const LoadTimingInfo& load_timing_info, |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 284 | int connect_timing_flags) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 285 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 286 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 287 | |
| 288 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 289 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 290 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 291 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 292 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 293 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 294 | load_timing_info.send_start); |
| 295 | |
| 296 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 297 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 298 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 299 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 300 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 301 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | // Tests LoadTimingInfo in the case a socket is reused and a PAC script is |
| 305 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 306 | void TestLoadTimingReusedWithPac(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 307 | EXPECT_TRUE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 308 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 309 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 310 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 311 | |
| 312 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 313 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 314 | load_timing_info.proxy_resolve_end); |
| 315 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 316 | load_timing_info.send_start); |
| 317 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 318 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 319 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 320 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 321 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 322 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | // Tests LoadTimingInfo in the case a new socket is used and a PAC script is |
| 326 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 327 | void TestLoadTimingNotReusedWithPac(const LoadTimingInfo& load_timing_info, |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 328 | int connect_timing_flags) { |
| 329 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 330 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 331 | |
| 332 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 333 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 334 | load_timing_info.proxy_resolve_end); |
| 335 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 336 | load_timing_info.connect_timing.connect_start); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 337 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 338 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 339 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 340 | load_timing_info.send_start); |
| 341 | |
| 342 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 343 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 344 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 345 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 346 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 347 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 348 | } |
| 349 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 350 | void AddWebSocketHeaders(HttpRequestHeaders* headers) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 351 | headers->SetHeader("Connection", "Upgrade"); |
| 352 | headers->SetHeader("Upgrade", "websocket"); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 353 | headers->SetHeader("Origin", "http://www.example.org"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 354 | headers->SetHeader("Sec-WebSocket-Version", "13"); |
| 355 | headers->SetHeader("Sec-WebSocket-Key", "dGhlIHNhbXBsZSBub25jZQ=="); |
| 356 | } |
| 357 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 358 | std::unique_ptr<HttpNetworkSession> CreateSession( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 359 | SpdySessionDependencies* session_deps) { |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 360 | return SpdySessionDependencies::SpdyCreateSession(session_deps); |
[email protected] | e8d53619 | 2008-10-17 22:21:14 | [diff] [blame] | 361 | } |
| 362 | |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 363 | // Note that the pointer written into |*throttler| will only be valid |
| 364 | // for the lifetime of the returned HttpNetworkSession. |
| 365 | std::unique_ptr<HttpNetworkSession> CreateSessionWithThrottler( |
| 366 | SpdySessionDependencies* session_deps, |
| 367 | TestNetworkStreamThrottler** throttler) { |
| 368 | std::unique_ptr<HttpNetworkSession> session( |
| 369 | SpdySessionDependencies::SpdyCreateSession(session_deps)); |
| 370 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 371 | auto owned_throttler = base::MakeUnique<TestNetworkStreamThrottler>(); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 372 | *throttler = owned_throttler.get(); |
| 373 | |
| 374 | HttpNetworkSessionPeer peer(session.get()); |
| 375 | peer.SetNetworkStreamThrottler(std::move(owned_throttler)); |
| 376 | |
| 377 | return session; |
| 378 | } |
| 379 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 380 | class FailingProxyResolverFactory : public ProxyResolverFactory { |
| 381 | public: |
| 382 | FailingProxyResolverFactory() : ProxyResolverFactory(false) {} |
| 383 | |
| 384 | // ProxyResolverFactory override. |
| 385 | int CreateProxyResolver( |
| 386 | const scoped_refptr<ProxyResolverScriptData>& script_data, |
| 387 | std::unique_ptr<ProxyResolver>* result, |
| 388 | const CompletionCallback& callback, |
| 389 | std::unique_ptr<Request>* request) override { |
| 390 | return ERR_PAC_SCRIPT_FAILED; |
| 391 | } |
| 392 | }; |
| 393 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 394 | } // namespace |
| 395 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 396 | class HttpNetworkTransactionTest : public PlatformTest { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 397 | public: |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 398 | ~HttpNetworkTransactionTest() override { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 399 | // Important to restore the per-pool limit first, since the pool limit must |
| 400 | // always be greater than group limit, and the tests reduce both limits. |
| 401 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 402 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_); |
| 403 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 404 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_group_sockets_); |
| 405 | } |
| 406 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 407 | protected: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 408 | HttpNetworkTransactionTest() |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 409 | : ssl_(ASYNC, OK), |
| 410 | old_max_group_sockets_(ClientSocketPoolManager::max_sockets_per_group( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 411 | HttpNetworkSession::NORMAL_SOCKET_POOL)), |
| 412 | old_max_pool_sockets_(ClientSocketPoolManager::max_sockets_per_pool( |
| 413 | HttpNetworkSession::NORMAL_SOCKET_POOL)) { |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 414 | session_deps_.enable_http2_alternative_service = true; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 415 | } |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 416 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 417 | struct SimpleGetHelperResult { |
| 418 | int rv; |
| 419 | std::string status_line; |
| 420 | std::string response_data; |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 421 | int64_t total_received_bytes; |
| 422 | int64_t total_sent_bytes; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 423 | LoadTimingInfo load_timing_info; |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 424 | ConnectionAttempts connection_attempts; |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 425 | IPEndPoint remote_endpoint_after_start; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 426 | }; |
| 427 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 428 | void SetUp() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 429 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 430 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 431 | } |
| 432 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 433 | void TearDown() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 434 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 435 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 436 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 437 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 438 | PlatformTest::TearDown(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 439 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 440 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 441 | } |
| 442 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 443 | // Either |write_failure| specifies a write failure or |read_failure| |
| 444 | // specifies a read failure when using a reused socket. In either case, the |
| 445 | // failure should cause the network transaction to resend the request, and the |
| 446 | // other argument should be NULL. |
| 447 | void KeepAliveConnectionResendRequestTest(const MockWrite* write_failure, |
| 448 | const MockRead* read_failure); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 449 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 450 | // Either |write_failure| specifies a write failure or |read_failure| |
| 451 | // specifies a read failure when using a reused socket. In either case, the |
| 452 | // failure should cause the network transaction to resend the request, and the |
| 453 | // other argument should be NULL. |
| 454 | void PreconnectErrorResendRequestTest(const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 455 | const MockRead* read_failure, |
| 456 | bool use_spdy); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 457 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 458 | SimpleGetHelperResult SimpleGetHelperForData(StaticSocketDataProvider* data[], |
| 459 | size_t data_count) { |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 460 | SimpleGetHelperResult out; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 461 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 462 | HttpRequestInfo request; |
| 463 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 464 | request.url = GURL("http://www.example.org/"); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 465 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 466 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 467 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 468 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 469 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 470 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 471 | for (size_t i = 0; i < data_count; ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 472 | session_deps_.socket_factory->AddSocketDataProvider(data[i]); |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 473 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 474 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 475 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 476 | |
eroman | 24bc6a1 | 2015-05-06 19:55:48 | [diff] [blame] | 477 | EXPECT_TRUE(log.bound().IsCapturing()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 478 | int rv = trans.Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 479 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 480 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 481 | out.rv = callback.WaitForResult(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 482 | out.total_received_bytes = trans.GetTotalReceivedBytes(); |
| 483 | out.total_sent_bytes = trans.GetTotalSentBytes(); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 484 | |
| 485 | // Even in the failure cases that use this function, connections are always |
| 486 | // successfully established before the error. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 487 | EXPECT_TRUE(trans.GetLoadTimingInfo(&out.load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 488 | TestLoadTimingNotReused(out.load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 489 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 490 | if (out.rv != OK) |
| 491 | return out; |
| 492 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 493 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 494 | // Can't use ASSERT_* inside helper functions like this, so |
| 495 | // return an error. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 496 | if (!response || !response->headers) { |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 497 | out.rv = ERR_UNEXPECTED; |
| 498 | return out; |
| 499 | } |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 500 | out.status_line = response->headers->GetStatusLine(); |
| 501 | |
[email protected] | 80a09a8 | 2012-11-16 17:40:06 | [diff] [blame] | 502 | EXPECT_EQ("127.0.0.1", response->socket_address.host()); |
| 503 | EXPECT_EQ(80, response->socket_address.port()); |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 504 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 505 | bool got_endpoint = |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 506 | trans.GetRemoteEndpoint(&out.remote_endpoint_after_start); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 507 | EXPECT_EQ(got_endpoint, |
| 508 | out.remote_endpoint_after_start.address().size() > 0); |
| 509 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 510 | rv = ReadTransaction(&trans, &out.response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 511 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 512 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 513 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 514 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 515 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 516 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_REQUEST_HEADERS, |
| 517 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 518 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 519 | entries, pos, NetLogEventType::HTTP_TRANSACTION_READ_RESPONSE_HEADERS, |
| 520 | NetLogEventPhase::NONE); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 521 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 522 | std::string line; |
| 523 | EXPECT_TRUE(entries[pos].GetStringValue("line", &line)); |
| 524 | EXPECT_EQ("GET / HTTP/1.1\r\n", line); |
| 525 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 526 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 527 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 528 | std::string value; |
| 529 | EXPECT_TRUE(request_headers.GetHeader("Host", &value)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 530 | EXPECT_EQ("www.example.org", value); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 531 | EXPECT_TRUE(request_headers.GetHeader("Connection", &value)); |
| 532 | EXPECT_EQ("keep-alive", value); |
| 533 | |
| 534 | std::string response_headers; |
| 535 | EXPECT_TRUE(GetHeaders(entries[pos].params.get(), &response_headers)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 536 | EXPECT_EQ("['Host: www.example.org','Connection: keep-alive']", |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 537 | response_headers); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 538 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 539 | out.total_received_bytes = trans.GetTotalReceivedBytes(); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 540 | // The total number of sent bytes should not have changed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 541 | EXPECT_EQ(out.total_sent_bytes, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 542 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 543 | trans.GetConnectionAttempts(&out.connection_attempts); |
[email protected] | aecfbf2 | 2008-10-16 02:02:47 | [diff] [blame] | 544 | return out; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 545 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 546 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 547 | SimpleGetHelperResult SimpleGetHelper(MockRead data_reads[], |
| 548 | size_t reads_count) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 549 | MockWrite data_writes[] = { |
| 550 | MockWrite("GET / HTTP/1.1\r\n" |
| 551 | "Host: www.example.org\r\n" |
| 552 | "Connection: keep-alive\r\n\r\n"), |
| 553 | }; |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 554 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 555 | StaticSocketDataProvider reads(data_reads, reads_count, data_writes, |
| 556 | arraysize(data_writes)); |
| 557 | StaticSocketDataProvider* data[] = {&reads}; |
| 558 | SimpleGetHelperResult out = SimpleGetHelperForData(data, 1); |
| 559 | |
| 560 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 561 | out.total_sent_bytes); |
| 562 | return out; |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 563 | } |
| 564 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 565 | void AddSSLSocketData() { |
| 566 | ssl_.next_proto = kProtoHTTP2; |
| 567 | ssl_.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 568 | ASSERT_TRUE(ssl_.cert); |
| 569 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_); |
| 570 | } |
| 571 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 572 | void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
| 573 | int expected_status); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 574 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 575 | void ConnectStatusHelper(const MockRead& status); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 576 | |
| 577 | void BypassHostCacheOnRefreshHelper(int load_flags); |
| 578 | |
| 579 | void CheckErrorIsPassedBack(int error, IoMode mode); |
| 580 | |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 581 | SpdyTestUtil spdy_util_; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 582 | SpdySessionDependencies session_deps_; |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 583 | SSLSocketDataProvider ssl_; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 584 | |
| 585 | // Original socket limits. Some tests set these. Safest to always restore |
| 586 | // them once each test has been run. |
| 587 | int old_max_group_sockets_; |
| 588 | int old_max_pool_sockets_; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 589 | }; |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 590 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 591 | namespace { |
| 592 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 593 | class BeforeHeadersSentHandler { |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 594 | public: |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 595 | BeforeHeadersSentHandler() |
| 596 | : observed_before_headers_sent_with_proxy_(false), |
| 597 | observed_before_headers_sent_(false) {} |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 598 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 599 | void OnBeforeHeadersSent(const ProxyInfo& proxy_info, |
| 600 | HttpRequestHeaders* request_headers) { |
| 601 | observed_before_headers_sent_ = true; |
| 602 | if (!proxy_info.is_http() && !proxy_info.is_https() && |
| 603 | !proxy_info.is_quic()) { |
| 604 | return; |
| 605 | } |
| 606 | observed_before_headers_sent_with_proxy_ = true; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 607 | observed_proxy_server_uri_ = proxy_info.proxy_server().ToURI(); |
| 608 | } |
| 609 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 610 | bool observed_before_headers_sent_with_proxy() const { |
| 611 | return observed_before_headers_sent_with_proxy_; |
| 612 | } |
| 613 | |
| 614 | bool observed_before_headers_sent() const { |
| 615 | return observed_before_headers_sent_; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | std::string observed_proxy_server_uri() const { |
| 619 | return observed_proxy_server_uri_; |
| 620 | } |
| 621 | |
| 622 | private: |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 623 | bool observed_before_headers_sent_with_proxy_; |
| 624 | bool observed_before_headers_sent_; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 625 | std::string observed_proxy_server_uri_; |
| 626 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 627 | DISALLOW_COPY_AND_ASSIGN(BeforeHeadersSentHandler); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 628 | }; |
| 629 | |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 630 | // Fill |str| with a long header list that consumes >= |size| bytes. |
| 631 | void FillLargeHeadersString(std::string* str, int size) { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 632 | const char row[] = |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 633 | "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"; |
| 634 | const int sizeof_row = strlen(row); |
| 635 | const int num_rows = static_cast<int>( |
| 636 | ceil(static_cast<float>(size) / sizeof_row)); |
| 637 | const int sizeof_data = num_rows * sizeof_row; |
| 638 | DCHECK(sizeof_data >= size); |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 639 | str->reserve(sizeof_data); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 640 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 641 | for (int i = 0; i < num_rows; ++i) |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 642 | str->append(row, sizeof_row); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 643 | } |
| 644 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 645 | #if defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 646 | // Alternative functions that eliminate randomness and dependency on the local |
| 647 | // host name so that the generated NTLM messages are reproducible. |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 648 | void MockGenerateRandom1(uint8_t* output, size_t n) { |
| 649 | static const uint8_t bytes[] = {0x55, 0x29, 0x66, 0x26, |
| 650 | 0x6b, 0x9c, 0x73, 0x54}; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 651 | static size_t current_byte = 0; |
| 652 | for (size_t i = 0; i < n; ++i) { |
| 653 | output[i] = bytes[current_byte++]; |
| 654 | current_byte %= arraysize(bytes); |
| 655 | } |
| 656 | } |
| 657 | |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 658 | void MockGenerateRandom2(uint8_t* output, size_t n) { |
| 659 | static const uint8_t bytes[] = {0x96, 0x79, 0x85, 0xe7, 0x49, 0x93, |
| 660 | 0x70, 0xa1, 0x4e, 0xe7, 0x87, 0x45, |
| 661 | 0x31, 0x5b, 0xd3, 0x1f}; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 662 | static size_t current_byte = 0; |
| 663 | for (size_t i = 0; i < n; ++i) { |
| 664 | output[i] = bytes[current_byte++]; |
| 665 | current_byte %= arraysize(bytes); |
| 666 | } |
| 667 | } |
| 668 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 669 | std::string MockGetHostName() { |
| 670 | return "WTC-WIN7"; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 671 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 672 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 673 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 674 | template<typename ParentPool> |
| 675 | class CaptureGroupNameSocketPool : public ParentPool { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 676 | public: |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 677 | CaptureGroupNameSocketPool(HostResolver* host_resolver, |
| 678 | CertVerifier* cert_verifier); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 679 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 680 | const std::string last_group_name_received() const { |
| 681 | return last_group_name_; |
| 682 | } |
| 683 | |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 684 | int RequestSocket(const std::string& group_name, |
| 685 | const void* socket_params, |
| 686 | RequestPriority priority, |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 687 | ClientSocketPool::RespectLimits respect_limits, |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 688 | ClientSocketHandle* handle, |
| 689 | const CompletionCallback& callback, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 690 | const NetLogWithSource& net_log) override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 691 | last_group_name_ = group_name; |
| 692 | return ERR_IO_PENDING; |
| 693 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 694 | void CancelRequest(const std::string& group_name, |
| 695 | ClientSocketHandle* handle) override {} |
| 696 | void ReleaseSocket(const std::string& group_name, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 697 | std::unique_ptr<StreamSocket> socket, |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 698 | int id) override {} |
| 699 | void CloseIdleSockets() override {} |
xunjieli | 92feb33 | 2017-03-03 17:19:23 | [diff] [blame] | 700 | void CloseIdleSocketsInGroup(const std::string& group_name) override {} |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 701 | int IdleSocketCount() const override { return 0; } |
| 702 | int IdleSocketCountInGroup(const std::string& group_name) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 703 | return 0; |
| 704 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 705 | LoadState GetLoadState(const std::string& group_name, |
| 706 | const ClientSocketHandle* handle) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 707 | return LOAD_STATE_IDLE; |
| 708 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 709 | base::TimeDelta ConnectionTimeout() const override { |
[email protected] | a796bcec | 2010-03-22 17:17:26 | [diff] [blame] | 710 | return base::TimeDelta(); |
| 711 | } |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 712 | |
| 713 | private: |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 714 | std::string last_group_name_; |
| 715 | }; |
| 716 | |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 717 | typedef CaptureGroupNameSocketPool<TransportClientSocketPool> |
| 718 | CaptureGroupNameTransportSocketPool; |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 719 | typedef CaptureGroupNameSocketPool<HttpProxyClientSocketPool> |
| 720 | CaptureGroupNameHttpProxySocketPool; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 721 | typedef CaptureGroupNameSocketPool<SOCKSClientSocketPool> |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 722 | CaptureGroupNameSOCKSSocketPool; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 723 | typedef CaptureGroupNameSocketPool<SSLClientSocketPool> |
| 724 | CaptureGroupNameSSLSocketPool; |
| 725 | |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 726 | template <typename ParentPool> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 727 | CaptureGroupNameSocketPool<ParentPool>::CaptureGroupNameSocketPool( |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 728 | HostResolver* host_resolver, |
| 729 | CertVerifier* /* cert_verifier */) |
tbansal | 7b403bcc | 2016-04-13 22:33:21 | [diff] [blame] | 730 | : ParentPool(0, 0, host_resolver, NULL, NULL, NULL) {} |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 731 | |
hashimoto | 0d3e4fb | 2015-01-09 05:02:50 | [diff] [blame] | 732 | template <> |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 733 | CaptureGroupNameHttpProxySocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 734 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 735 | CertVerifier* /* cert_verifier */) |
tbansal | 16196a1e | 2017-06-09 01:50:09 | [diff] [blame] | 736 | : HttpProxyClientSocketPool(0, 0, NULL, NULL, NULL, NULL) {} |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 737 | |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 738 | template <> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 739 | CaptureGroupNameSSLSocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 740 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 741 | CertVerifier* cert_verifier) |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 742 | : SSLClientSocketPool(0, |
| 743 | 0, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 744 | cert_verifier, |
| 745 | NULL, |
| 746 | NULL, |
[email protected] | 284303b6 | 2013-11-28 15:11:54 | [diff] [blame] | 747 | NULL, |
eranm | 6571b2b | 2014-12-03 15:53:23 | [diff] [blame] | 748 | NULL, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 749 | std::string(), |
| 750 | NULL, |
| 751 | NULL, |
| 752 | NULL, |
| 753 | NULL, |
| 754 | NULL, |
[email protected] | 8e45855 | 2014-08-05 00:02:15 | [diff] [blame] | 755 | NULL) { |
| 756 | } |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 757 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 758 | //----------------------------------------------------------------------------- |
| 759 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 760 | // Helper functions for validating that AuthChallengeInfo's are correctly |
| 761 | // configured for common cases. |
| 762 | bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 763 | if (!auth_challenge) |
| 764 | return false; |
| 765 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 766 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 767 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 768 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 769 | return true; |
| 770 | } |
| 771 | |
| 772 | bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 773 | if (!auth_challenge) |
| 774 | return false; |
| 775 | EXPECT_TRUE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 776 | EXPECT_EQ("http://myproxy:70", auth_challenge->challenger.Serialize()); |
| 777 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 778 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
| 779 | return true; |
| 780 | } |
| 781 | |
| 782 | bool CheckBasicSecureProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 783 | if (!auth_challenge) |
| 784 | return false; |
| 785 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 786 | EXPECT_EQ("https://myproxy:70", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 787 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 788 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 789 | return true; |
| 790 | } |
| 791 | |
| 792 | bool CheckDigestServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 793 | if (!auth_challenge) |
| 794 | return false; |
| 795 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 796 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 797 | EXPECT_EQ("digestive", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 798 | EXPECT_EQ(kDigestAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 799 | return true; |
| 800 | } |
| 801 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 802 | #if defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 803 | bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 804 | if (!auth_challenge) |
| 805 | return false; |
| 806 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 807 | EXPECT_EQ("http://172.22.68.17", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 808 | EXPECT_EQ(std::string(), auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 809 | EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 810 | return true; |
| 811 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 812 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 813 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 814 | } // namespace |
| 815 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 816 | TEST_F(HttpNetworkTransactionTest, Basic) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 817 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 818 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 819 | } |
| 820 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 821 | TEST_F(HttpNetworkTransactionTest, SimpleGET) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 822 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 823 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 824 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 825 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 826 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 827 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 828 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 829 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 830 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 831 | EXPECT_EQ("hello world", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 832 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 833 | EXPECT_EQ(reads_size, out.total_received_bytes); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 834 | EXPECT_EQ(0u, out.connection_attempts.size()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 835 | |
| 836 | EXPECT_FALSE(out.remote_endpoint_after_start.address().empty()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 837 | } |
| 838 | |
| 839 | // Response with no status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 840 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeaders) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 841 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 842 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 843 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 844 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 845 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 846 | arraysize(data_reads)); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 847 | EXPECT_THAT(out.rv, IsOk()); |
| 848 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 849 | EXPECT_EQ("hello world", out.response_data); |
| 850 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 851 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 852 | } |
| 853 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 854 | // Response with no status line, and a weird port. Should fail by default. |
| 855 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPort) { |
| 856 | MockRead data_reads[] = { |
| 857 | MockRead("hello world"), MockRead(SYNCHRONOUS, OK), |
| 858 | }; |
| 859 | |
| 860 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 861 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 862 | |
| 863 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 864 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 865 | HttpRequestInfo request; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 866 | auto trans = |
| 867 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 868 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 869 | request.method = "GET"; |
| 870 | request.url = GURL("http://www.example.com:2000/"); |
| 871 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 872 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 873 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_INVALID_HTTP_RESPONSE)); |
| 874 | } |
| 875 | |
| 876 | // Response with no status line, and a weird port. Option to allow weird ports |
| 877 | // enabled. |
| 878 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPortAllowed) { |
| 879 | MockRead data_reads[] = { |
| 880 | MockRead("hello world"), MockRead(SYNCHRONOUS, OK), |
| 881 | }; |
| 882 | |
| 883 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 884 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 885 | session_deps_.http_09_on_non_default_ports_enabled = true; |
| 886 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 887 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 888 | HttpRequestInfo request; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 889 | auto trans = |
| 890 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 891 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 892 | request.method = "GET"; |
| 893 | request.url = GURL("http://www.example.com:2000/"); |
| 894 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 895 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 896 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 897 | |
| 898 | const HttpResponseInfo* info = trans->GetResponseInfo(); |
| 899 | ASSERT_TRUE(info->headers); |
| 900 | EXPECT_EQ("HTTP/0.9 200 OK", info->headers->GetStatusLine()); |
| 901 | |
| 902 | // Don't bother to read the body - that's verified elsewhere, important thing |
| 903 | // is that the option to allow HTTP/0.9 on non-default ports is respected. |
| 904 | } |
| 905 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 906 | // Allow up to 4 bytes of junk to precede status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 907 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk3Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 908 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 909 | MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 910 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 911 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 912 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 913 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 914 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 915 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 916 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 917 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 918 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 919 | } |
| 920 | |
| 921 | // Allow up to 4 bytes of junk to precede status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 922 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 923 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 924 | MockRead("\n\nQJHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 925 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 926 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 927 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 928 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 929 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 930 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 931 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 932 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 933 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 934 | } |
| 935 | |
| 936 | // Beyond 4 bytes of slop and it should fail to find a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 937 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk5Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 938 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 939 | MockRead("xxxxxHTTP/1.1 404 Not Found\nServer: blah"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 940 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 941 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 942 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 943 | arraysize(data_reads)); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 944 | EXPECT_THAT(out.rv, IsOk()); |
| 945 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 946 | EXPECT_EQ("xxxxxHTTP/1.1 404 Not Found\nServer: blah", out.response_data); |
| 947 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 948 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 949 | } |
| 950 | |
| 951 | // Same as StatusLineJunk4Bytes, except the read chunks are smaller. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 952 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes_Slow) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 953 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 954 | MockRead("\n"), |
| 955 | MockRead("\n"), |
| 956 | MockRead("Q"), |
| 957 | MockRead("J"), |
| 958 | MockRead("HTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 959 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 960 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 961 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 962 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 963 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 964 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 965 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 966 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 967 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 968 | } |
| 969 | |
| 970 | // Close the connection before enough bytes to have a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 971 | TEST_F(HttpNetworkTransactionTest, StatusLinePartial) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 972 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 973 | MockRead("HTT"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 974 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 975 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 976 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 977 | arraysize(data_reads)); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 978 | EXPECT_THAT(out.rv, IsOk()); |
| 979 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 980 | EXPECT_EQ("HTT", out.response_data); |
| 981 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 982 | EXPECT_EQ(reads_size, out.total_received_bytes); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 983 | } |
| 984 | |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 985 | // Simulate a 204 response, lacking a Content-Length header, sent over a |
| 986 | // persistent connection. The response should still terminate since a 204 |
| 987 | // cannot have a response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 988 | TEST_F(HttpNetworkTransactionTest, StopsReading204) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 989 | char junk[] = "junk"; |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 990 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 991 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 992 | MockRead(junk), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 993 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 994 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 995 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 996 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 997 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 998 | EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); |
| 999 | EXPECT_EQ("", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 1000 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 1001 | int64_t response_size = reads_size - strlen(junk); |
| 1002 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 1003 | } |
| 1004 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1005 | // A simple request using chunked encoding with some extra data after. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1006 | TEST_F(HttpNetworkTransactionTest, ChunkedEncoding) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1007 | std::string final_chunk = "0\r\n\r\n"; |
| 1008 | std::string extra_data = "HTTP/1.1 200 OK\r\n"; |
| 1009 | std::string last_read = final_chunk + extra_data; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1010 | MockRead data_reads[] = { |
| 1011 | MockRead("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"), |
| 1012 | MockRead("5\r\nHello\r\n"), |
| 1013 | MockRead("1\r\n"), |
| 1014 | MockRead(" \r\n"), |
| 1015 | MockRead("5\r\nworld\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1016 | MockRead(last_read.data()), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1017 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1018 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1019 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1020 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1021 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1022 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1023 | EXPECT_EQ("Hello world", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 1024 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 1025 | int64_t response_size = reads_size - extra_data.size(); |
| 1026 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1027 | } |
| 1028 | |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1029 | // Next tests deal with http://crbug.com/56344. |
| 1030 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1031 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1032 | MultipleContentLengthHeadersNoTransferEncoding) { |
| 1033 | MockRead data_reads[] = { |
| 1034 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1035 | MockRead("Content-Length: 10\r\n"), |
| 1036 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1037 | }; |
| 1038 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1039 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1040 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1041 | } |
| 1042 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1043 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1044 | DuplicateContentLengthHeadersNoTransferEncoding) { |
| 1045 | MockRead data_reads[] = { |
| 1046 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1047 | MockRead("Content-Length: 5\r\n"), |
| 1048 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1049 | MockRead("Hello"), |
| 1050 | }; |
| 1051 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1052 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1053 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1054 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1055 | EXPECT_EQ("Hello", out.response_data); |
| 1056 | } |
| 1057 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1058 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1059 | ComplexContentLengthHeadersNoTransferEncoding) { |
| 1060 | // More than 2 dupes. |
| 1061 | { |
| 1062 | MockRead data_reads[] = { |
| 1063 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1064 | MockRead("Content-Length: 5\r\n"), |
| 1065 | MockRead("Content-Length: 5\r\n"), |
| 1066 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1067 | MockRead("Hello"), |
| 1068 | }; |
| 1069 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1070 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1071 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1072 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1073 | EXPECT_EQ("Hello", out.response_data); |
| 1074 | } |
| 1075 | // HTTP/1.0 |
| 1076 | { |
| 1077 | MockRead data_reads[] = { |
| 1078 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1079 | MockRead("Content-Length: 5\r\n"), |
| 1080 | MockRead("Content-Length: 5\r\n"), |
| 1081 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1082 | MockRead("Hello"), |
| 1083 | }; |
| 1084 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1085 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1086 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1087 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 1088 | EXPECT_EQ("Hello", out.response_data); |
| 1089 | } |
| 1090 | // 2 dupes and one mismatched. |
| 1091 | { |
| 1092 | MockRead data_reads[] = { |
| 1093 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1094 | MockRead("Content-Length: 10\r\n"), |
| 1095 | MockRead("Content-Length: 10\r\n"), |
| 1096 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1097 | }; |
| 1098 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1099 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1100 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1101 | } |
| 1102 | } |
| 1103 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1104 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1105 | MultipleContentLengthHeadersTransferEncoding) { |
| 1106 | MockRead data_reads[] = { |
| 1107 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1108 | MockRead("Content-Length: 666\r\n"), |
| 1109 | MockRead("Content-Length: 1337\r\n"), |
| 1110 | MockRead("Transfer-Encoding: chunked\r\n\r\n"), |
| 1111 | MockRead("5\r\nHello\r\n"), |
| 1112 | MockRead("1\r\n"), |
| 1113 | MockRead(" \r\n"), |
| 1114 | MockRead("5\r\nworld\r\n"), |
| 1115 | MockRead("0\r\n\r\nHTTP/1.1 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1116 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1117 | }; |
| 1118 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1119 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1120 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1121 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1122 | EXPECT_EQ("Hello world", out.response_data); |
| 1123 | } |
| 1124 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1125 | // Next tests deal with http://crbug.com/98895. |
| 1126 | |
| 1127 | // Checks that a single Content-Disposition header results in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1128 | TEST_F(HttpNetworkTransactionTest, SingleContentDispositionHeader) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1129 | MockRead data_reads[] = { |
| 1130 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1131 | MockRead("Content-Disposition: attachment;filename=\"salutations.txt\"r\n"), |
| 1132 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1133 | MockRead("Hello"), |
| 1134 | }; |
| 1135 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1136 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1137 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1138 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1139 | EXPECT_EQ("Hello", out.response_data); |
| 1140 | } |
| 1141 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1142 | // Checks that two identical Content-Disposition headers result in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1143 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1144 | MockRead data_reads[] = { |
| 1145 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1146 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1147 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1148 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1149 | MockRead("Hello"), |
| 1150 | }; |
| 1151 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1152 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1153 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1154 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1155 | EXPECT_EQ("Hello", out.response_data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1156 | } |
| 1157 | |
| 1158 | // Checks that two distinct Content-Disposition headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1159 | TEST_F(HttpNetworkTransactionTest, TwoDistinctContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1160 | MockRead data_reads[] = { |
| 1161 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1162 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1163 | MockRead("Content-Disposition: attachment;filename=\"hi.txt\"r\n"), |
| 1164 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1165 | MockRead("Hello"), |
| 1166 | }; |
| 1167 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1168 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1169 | EXPECT_THAT(out.rv, |
| 1170 | IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1171 | } |
| 1172 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1173 | // Checks that two identical Location headers result in no error. |
| 1174 | // Also tests Location header behavior. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1175 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1176 | MockRead data_reads[] = { |
| 1177 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1178 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1179 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1180 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1181 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1182 | }; |
| 1183 | |
| 1184 | HttpRequestInfo request; |
| 1185 | request.method = "GET"; |
| 1186 | request.url = GURL("http://redirect.com/"); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1187 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1188 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1189 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1190 | |
| 1191 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1192 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1193 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1194 | TestCompletionCallback callback; |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1195 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1196 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1197 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1198 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1199 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1200 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1201 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1202 | ASSERT_TRUE(response); |
| 1203 | ASSERT_TRUE(response->headers); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1204 | EXPECT_EQ("HTTP/1.1 302 Redirect", response->headers->GetStatusLine()); |
| 1205 | std::string url; |
| 1206 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 1207 | EXPECT_EQ("http://good.com/", url); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1208 | EXPECT_TRUE(response->proxy_server.is_direct()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1209 | } |
| 1210 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1211 | // Checks that two distinct Location headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1212 | TEST_F(HttpNetworkTransactionTest, TwoDistinctLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1213 | MockRead data_reads[] = { |
| 1214 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1215 | MockRead("Location: http://good.com/\r\n"), |
| 1216 | MockRead("Location: http://evil.com/\r\n"), |
| 1217 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1218 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1219 | }; |
| 1220 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1221 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1222 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1223 | } |
| 1224 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1225 | // Do a request using the HEAD method. Verify that we don't try to read the |
| 1226 | // message body (since HEAD has none). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1227 | TEST_F(HttpNetworkTransactionTest, Head) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1228 | HttpRequestInfo request; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1229 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1230 | request.url = GURL("http://www.example.org/"); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1231 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1232 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1233 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1234 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1235 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1236 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 1237 | base::Unretained(&headers_handler))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1238 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1239 | MockWrite data_writes1[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 1240 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 1241 | "Host: www.example.org\r\n" |
| 1242 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1243 | }; |
| 1244 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1245 | MockRead("HTTP/1.1 404 Not Found\r\n"), MockRead("Server: Blah\r\n"), |
| 1246 | MockRead("Content-Length: 1234\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1247 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1248 | // No response body because the test stops reading here. |
| 1249 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1250 | }; |
| 1251 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1252 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 1253 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1254 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1255 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1256 | TestCompletionCallback callback1; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1257 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1258 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1259 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1260 | |
| 1261 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1262 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1263 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1264 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1265 | ASSERT_TRUE(response); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1266 | |
| 1267 | // Check that the headers got parsed. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1268 | EXPECT_TRUE(response->headers); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1269 | EXPECT_EQ(1234, response->headers->GetContentLength()); |
| 1270 | EXPECT_EQ("HTTP/1.1 404 Not Found", response->headers->GetStatusLine()); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1271 | EXPECT_TRUE(response->proxy_server.is_direct()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1272 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 1273 | EXPECT_FALSE(headers_handler.observed_before_headers_sent_with_proxy()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1274 | |
| 1275 | std::string server_header; |
olli.raula | ee489a5 | 2016-01-25 08:37:10 | [diff] [blame] | 1276 | size_t iter = 0; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1277 | bool has_server_header = response->headers->EnumerateHeader( |
| 1278 | &iter, "Server", &server_header); |
| 1279 | EXPECT_TRUE(has_server_header); |
| 1280 | EXPECT_EQ("Blah", server_header); |
| 1281 | |
| 1282 | // Reading should give EOF right away, since there is no message body |
| 1283 | // (despite non-zero content-length). |
| 1284 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1285 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1286 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1287 | EXPECT_EQ("", response_data); |
| 1288 | } |
| 1289 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1290 | TEST_F(HttpNetworkTransactionTest, ReuseConnection) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1291 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1292 | |
| 1293 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1294 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1295 | MockRead("hello"), |
| 1296 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1297 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1298 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1299 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1300 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1301 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1302 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1303 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1304 | "hello", "world" |
| 1305 | }; |
| 1306 | |
| 1307 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1308 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1309 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1310 | request.url = GURL("http://www.example.org/"); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1311 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1312 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1313 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1314 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1315 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1316 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1317 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1318 | |
| 1319 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1320 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1321 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1322 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1323 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1324 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1325 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1326 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1327 | EXPECT_TRUE(response->proxy_server.is_direct()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1328 | |
| 1329 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1330 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1331 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1332 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1333 | } |
| 1334 | } |
| 1335 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1336 | TEST_F(HttpNetworkTransactionTest, Ignores100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1337 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1338 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 1339 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1340 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1341 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1342 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1343 | request.method = "POST"; |
| 1344 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1345 | request.upload_data_stream = &upload_data_stream; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1346 | |
shivanisha | b9a14395 | 2016-09-19 17:23:41 | [diff] [blame] | 1347 | // Check the upload progress returned before initialization is correct. |
| 1348 | UploadProgress progress = request.upload_data_stream->GetUploadProgress(); |
| 1349 | EXPECT_EQ(0u, progress.size()); |
| 1350 | EXPECT_EQ(0u, progress.position()); |
| 1351 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1352 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1353 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1354 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1355 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1356 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 1357 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 1358 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1359 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1360 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1361 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1362 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1363 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1364 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1365 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1366 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1367 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1368 | |
| 1369 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1370 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1371 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1372 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1373 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1374 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1375 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1376 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1377 | |
| 1378 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1379 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1380 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1381 | EXPECT_EQ("hello world", response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1382 | } |
| 1383 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1384 | // This test is almost the same as Ignores100 above, but the response contains |
| 1385 | // 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] | 1386 | // HTTP/1.1 and the two status headers are read in one read. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1387 | TEST_F(HttpNetworkTransactionTest, Ignores1xx) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1388 | HttpRequestInfo request; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1389 | request.method = "GET"; |
| 1390 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1391 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1392 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1393 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1394 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1395 | MockRead data_reads[] = { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1396 | MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n" |
| 1397 | "HTTP/1.1 200 OK\r\n\r\n"), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1398 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1399 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1400 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1401 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1402 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1403 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1404 | TestCompletionCallback callback; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1405 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1406 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1407 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1408 | |
| 1409 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1410 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1411 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1412 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1413 | ASSERT_TRUE(response); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1414 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1415 | EXPECT_TRUE(response->headers); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1416 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1417 | |
| 1418 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1419 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1420 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1421 | EXPECT_EQ("hello world", response_data); |
| 1422 | } |
| 1423 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1424 | TEST_F(HttpNetworkTransactionTest, Incomplete100ThenEOF) { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1425 | HttpRequestInfo request; |
| 1426 | request.method = "POST"; |
| 1427 | request.url = GURL("http://www.foo.com/"); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1428 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1429 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1430 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1431 | |
| 1432 | MockRead data_reads[] = { |
| 1433 | MockRead(SYNCHRONOUS, "HTTP/1.0 100 Continue\r\n"), |
| 1434 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1435 | }; |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1436 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 1437 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1438 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1439 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1440 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1441 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1442 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1443 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1444 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1445 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1446 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1447 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1448 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1449 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1450 | EXPECT_EQ("", response_data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1451 | } |
| 1452 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1453 | TEST_F(HttpNetworkTransactionTest, EmptyResponse) { |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1454 | HttpRequestInfo request; |
| 1455 | request.method = "POST"; |
| 1456 | request.url = GURL("http://www.foo.com/"); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1457 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1458 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1459 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1460 | |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1461 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1462 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1463 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1464 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1465 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1466 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1467 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1468 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1469 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1470 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1471 | |
| 1472 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1473 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1474 | } |
| 1475 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1476 | void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest( |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1477 | const MockWrite* write_failure, |
| 1478 | const MockRead* read_failure) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1479 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1480 | request.method = "GET"; |
| 1481 | request.url = GURL("http://www.foo.com/"); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1482 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1483 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1484 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1485 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1486 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1487 | // Written data for successfully sending both requests. |
| 1488 | MockWrite data1_writes[] = { |
| 1489 | MockWrite("GET / HTTP/1.1\r\n" |
| 1490 | "Host: www.foo.com\r\n" |
| 1491 | "Connection: keep-alive\r\n\r\n"), |
| 1492 | MockWrite("GET / HTTP/1.1\r\n" |
| 1493 | "Host: www.foo.com\r\n" |
| 1494 | "Connection: keep-alive\r\n\r\n") |
| 1495 | }; |
| 1496 | |
| 1497 | // Read results for the first request. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1498 | MockRead data1_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1499 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1500 | MockRead("hello"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1501 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1502 | }; |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1503 | |
| 1504 | if (write_failure) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1505 | ASSERT_FALSE(read_failure); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1506 | data1_writes[1] = *write_failure; |
| 1507 | } else { |
| 1508 | ASSERT_TRUE(read_failure); |
| 1509 | data1_reads[2] = *read_failure; |
| 1510 | } |
| 1511 | |
| 1512 | StaticSocketDataProvider data1(data1_reads, arraysize(data1_reads), |
| 1513 | data1_writes, arraysize(data1_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1514 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1515 | |
| 1516 | MockRead data2_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1517 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1518 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1519 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1520 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1521 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1522 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1523 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 1524 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1525 | "hello", "world" |
| 1526 | }; |
| 1527 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 1528 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1529 | for (int i = 0; i < 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1530 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1531 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1532 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1533 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1534 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1535 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1536 | |
| 1537 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1538 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1539 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1540 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1541 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1542 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1543 | if (i == 0) { |
| 1544 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1545 | } else { |
| 1546 | // The second request should be using a new socket. |
| 1547 | EXPECT_NE(first_socket_log_id, load_timing_info.socket_log_id); |
| 1548 | } |
| 1549 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1550 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1551 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1552 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1553 | EXPECT_TRUE(response->headers); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1554 | EXPECT_TRUE(response->proxy_server.is_direct()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1555 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1556 | |
| 1557 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1558 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1559 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1560 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1561 | } |
| 1562 | } |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1563 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1564 | void HttpNetworkTransactionTest::PreconnectErrorResendRequestTest( |
| 1565 | const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1566 | const MockRead* read_failure, |
| 1567 | bool use_spdy) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1568 | HttpRequestInfo request; |
| 1569 | request.method = "GET"; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1570 | request.url = GURL("https://www.foo.com/"); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1571 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1572 | TestNetLog net_log; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1573 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1574 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1575 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1576 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 1577 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 1578 | if (use_spdy) { |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 1579 | ssl1.next_proto = kProtoHTTP2; |
| 1580 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1581 | } |
| 1582 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 1583 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1584 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1585 | // SPDY versions of the request and response. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1586 | SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1587 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1588 | SpdySerializedFrame spdy_response( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1589 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1590 | SpdySerializedFrame spdy_data( |
| 1591 | spdy_util_.ConstructSpdyDataFrame(1, "hello", 5, true)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1592 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1593 | // HTTP/1.1 versions of the request and response. |
| 1594 | const char kHttpRequest[] = "GET / HTTP/1.1\r\n" |
| 1595 | "Host: www.foo.com\r\n" |
| 1596 | "Connection: keep-alive\r\n\r\n"; |
| 1597 | const char kHttpResponse[] = "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"; |
| 1598 | const char kHttpData[] = "hello"; |
| 1599 | |
| 1600 | std::vector<MockRead> data1_reads; |
| 1601 | std::vector<MockWrite> data1_writes; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1602 | if (write_failure) { |
| 1603 | ASSERT_FALSE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1604 | data1_writes.push_back(*write_failure); |
| 1605 | data1_reads.push_back(MockRead(ASYNC, OK)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1606 | } else { |
| 1607 | ASSERT_TRUE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1608 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1609 | data1_writes.push_back(CreateMockWrite(spdy_request)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1610 | } else { |
| 1611 | data1_writes.push_back(MockWrite(kHttpRequest)); |
| 1612 | } |
| 1613 | data1_reads.push_back(*read_failure); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1614 | } |
| 1615 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1616 | StaticSocketDataProvider data1(&data1_reads[0], data1_reads.size(), |
| 1617 | &data1_writes[0], data1_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1618 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1619 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1620 | std::vector<MockRead> data2_reads; |
| 1621 | std::vector<MockWrite> data2_writes; |
| 1622 | |
| 1623 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1624 | data2_writes.push_back(CreateMockWrite(spdy_request, 0, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1625 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1626 | data2_reads.push_back(CreateMockRead(spdy_response, 1, ASYNC)); |
| 1627 | data2_reads.push_back(CreateMockRead(spdy_data, 2, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1628 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1629 | } else { |
| 1630 | data2_writes.push_back( |
| 1631 | MockWrite(ASYNC, kHttpRequest, strlen(kHttpRequest), 0)); |
| 1632 | |
| 1633 | data2_reads.push_back( |
| 1634 | MockRead(ASYNC, kHttpResponse, strlen(kHttpResponse), 1)); |
| 1635 | data2_reads.push_back(MockRead(ASYNC, kHttpData, strlen(kHttpData), 2)); |
| 1636 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1637 | } |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 1638 | SequencedSocketData data2(&data2_reads[0], data2_reads.size(), |
| 1639 | &data2_writes[0], data2_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1640 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1641 | |
| 1642 | // Preconnect a socket. |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 1643 | session->http_stream_factory()->PreconnectStreams(1, request); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1644 | // Wait for the preconnect to complete. |
| 1645 | // TODO(davidben): Some way to wait for an idle socket count might be handy. |
| 1646 | base::RunLoop().RunUntilIdle(); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1647 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1648 | |
| 1649 | // Make the request. |
| 1650 | TestCompletionCallback callback; |
| 1651 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1652 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1653 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1654 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1655 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1656 | |
| 1657 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1658 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1659 | |
| 1660 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1661 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1662 | TestLoadTimingNotReused( |
| 1663 | load_timing_info, |
| 1664 | CONNECT_TIMING_HAS_DNS_TIMES|CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1665 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1666 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1667 | ASSERT_TRUE(response); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1668 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1669 | EXPECT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1670 | if (response->was_fetched_via_spdy) { |
| 1671 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 1672 | } else { |
| 1673 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1674 | } |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1675 | |
| 1676 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1677 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1678 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1679 | EXPECT_EQ(kHttpData, response_data); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1680 | } |
| 1681 | |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame^] | 1682 | // Test that we do not retry indefinitely when a server sends an error like |
| 1683 | // ERR_SPDY_PING_FAILED, ERR_SPDY_SERVER_REFUSED_STREAM, |
| 1684 | // ERR_QUIC_HANDSHAKE_FAILED or ERR_QUIC_PROTOCOL_ERROR. |
| 1685 | TEST_F(HttpNetworkTransactionTest, FiniteRetriesOnIOError) { |
| 1686 | HttpRequestInfo request; |
| 1687 | request.method = "GET"; |
| 1688 | request.url = GURL("https://www.foo.com/"); |
| 1689 | |
| 1690 | // Check whether we give up after the third try. |
| 1691 | |
| 1692 | // Construct an HTTP2 request and a "Go away" response. |
| 1693 | SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
| 1694 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
| 1695 | SpdySerializedFrame spdy_response_go_away(spdy_util_.ConstructSpdyGoAway()); |
| 1696 | MockRead data_read1 = CreateMockRead(spdy_response_go_away); |
| 1697 | MockWrite data_write = CreateMockWrite(spdy_request, 0); |
| 1698 | |
| 1699 | // Three go away responses. |
| 1700 | StaticSocketDataProvider data1(&data_read1, 1, &data_write, 1); |
| 1701 | StaticSocketDataProvider data2(&data_read1, 1, &data_write, 1); |
| 1702 | StaticSocketDataProvider data3(&data_read1, 1, &data_write, 1); |
| 1703 | |
| 1704 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1705 | AddSSLSocketData(); |
| 1706 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1707 | AddSSLSocketData(); |
| 1708 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 1709 | AddSSLSocketData(); |
| 1710 | |
| 1711 | TestCompletionCallback callback; |
| 1712 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1713 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1714 | |
| 1715 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1716 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1717 | |
| 1718 | rv = callback.WaitForResult(); |
| 1719 | EXPECT_THAT(rv, IsError(ERR_SPDY_SERVER_REFUSED_STREAM)); |
| 1720 | } |
| 1721 | |
| 1722 | TEST_F(HttpNetworkTransactionTest, RetryTwiceOnIOError) { |
| 1723 | HttpRequestInfo request; |
| 1724 | request.method = "GET"; |
| 1725 | request.url = GURL("https://www.foo.com/"); |
| 1726 | |
| 1727 | // Check whether we try atleast thrice before giving up. |
| 1728 | |
| 1729 | // Construct an HTTP2 request and a "Go away" response. |
| 1730 | SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
| 1731 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
| 1732 | SpdySerializedFrame spdy_response_go_away(spdy_util_.ConstructSpdyGoAway()); |
| 1733 | MockRead data_read1 = CreateMockRead(spdy_response_go_away); |
| 1734 | MockWrite data_write = CreateMockWrite(spdy_request, 0); |
| 1735 | |
| 1736 | // Construct a non error HTTP2 response. |
| 1737 | SpdySerializedFrame spdy_response_no_error( |
| 1738 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 1739 | SpdySerializedFrame spdy_data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 1740 | MockRead data_read2[] = {CreateMockRead(spdy_response_no_error, 1), |
| 1741 | CreateMockRead(spdy_data, 2)}; |
| 1742 | |
| 1743 | // Two error responses. |
| 1744 | StaticSocketDataProvider data1(&data_read1, 1, &data_write, 1); |
| 1745 | StaticSocketDataProvider data2(&data_read1, 1, &data_write, 1); |
| 1746 | // Followed by a success response. |
| 1747 | SequencedSocketData data3(data_read2, 2, &data_write, 1); |
| 1748 | |
| 1749 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1750 | AddSSLSocketData(); |
| 1751 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1752 | AddSSLSocketData(); |
| 1753 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 1754 | AddSSLSocketData(); |
| 1755 | |
| 1756 | TestCompletionCallback callback; |
| 1757 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1758 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1759 | |
| 1760 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1761 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1762 | |
| 1763 | rv = callback.WaitForResult(); |
| 1764 | EXPECT_THAT(rv, IsOk()); |
| 1765 | } |
| 1766 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1767 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionNotConnectedOnWrite) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1768 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1769 | KeepAliveConnectionResendRequestTest(&write_failure, NULL); |
| 1770 | } |
| 1771 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1772 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionReset) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1773 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[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 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1777 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1778 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1779 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1780 | } |
| 1781 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1782 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1783 | // if the socket was a reused keep alive socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1784 | TEST_F(HttpNetworkTransactionTest, KeepAlive408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1785 | MockRead read_failure(SYNCHRONOUS, |
| 1786 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1787 | "Connection: Keep-Alive\r\n" |
| 1788 | "Content-Length: 6\r\n\r\n" |
| 1789 | "Pickle"); |
| 1790 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1791 | } |
| 1792 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1793 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorNotConnectedOnWrite) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1794 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1795 | PreconnectErrorResendRequestTest(&write_failure, NULL, 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, PreconnectErrorReset) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1799 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1800 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1801 | } |
| 1802 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1803 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorEOF) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1804 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1805 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1806 | } |
| 1807 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1808 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1809 | MockRead read_failure(ASYNC, OK); // EOF |
| 1810 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1811 | } |
| 1812 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1813 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1814 | // if the socket was a preconnected (UNUSED_IDLE) socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1815 | TEST_F(HttpNetworkTransactionTest, RetryOnIdle408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1816 | MockRead read_failure(SYNCHRONOUS, |
| 1817 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1818 | "Connection: Keep-Alive\r\n" |
| 1819 | "Content-Length: 6\r\n\r\n" |
| 1820 | "Pickle"); |
| 1821 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1822 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1823 | } |
| 1824 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1825 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorNotConnectedOnWrite) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1826 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
| 1827 | PreconnectErrorResendRequestTest(&write_failure, NULL, true); |
| 1828 | } |
| 1829 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1830 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorReset) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1831 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
| 1832 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1833 | } |
| 1834 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1835 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1836 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
| 1837 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1838 | } |
| 1839 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1840 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1841 | MockRead read_failure(ASYNC, OK); // EOF |
| 1842 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1843 | } |
| 1844 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1845 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1846 | HttpRequestInfo request; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1847 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1848 | request.url = GURL("http://www.example.org/"); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1849 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1850 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1851 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1852 | |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1853 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1854 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1855 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1856 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1857 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1858 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1859 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1860 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1861 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1862 | TestCompletionCallback callback; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1863 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1864 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1865 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1866 | |
| 1867 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1868 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 1869 | |
| 1870 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1871 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 1872 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1873 | } |
| 1874 | |
| 1875 | // What do various browsers do when the server closes a non-keepalive |
| 1876 | // connection without sending any response header or body? |
| 1877 | // |
| 1878 | // IE7: error page |
| 1879 | // Safari 3.1.2 (Windows): error page |
| 1880 | // Firefox 3.0.1: blank page |
| 1881 | // Opera 9.52: after five attempts, blank page |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1882 | // Us with WinHTTP: error page (ERR_INVALID_RESPONSE) |
| 1883 | // Us: error page (EMPTY_RESPONSE) |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1884 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionEOF) { |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1885 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1886 | MockRead(SYNCHRONOUS, OK), // EOF |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1887 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1888 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1889 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1890 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1891 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1892 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1893 | EXPECT_THAT(out.rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1894 | } |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1895 | |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1896 | // Next 2 cases (KeepAliveEarlyClose and KeepAliveEarlyClose2) are regression |
| 1897 | // tests. There was a bug causing HttpNetworkTransaction to hang in the |
| 1898 | // destructor in such situations. |
| 1899 | // See http://crbug.com/154712 and http://crbug.com/156609. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1900 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1901 | HttpRequestInfo request; |
| 1902 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1903 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1904 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1905 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 1906 | auto trans = |
| 1907 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1908 | |
| 1909 | MockRead data_reads[] = { |
| 1910 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1911 | MockRead("Connection: keep-alive\r\n"), |
| 1912 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1913 | MockRead("hello"), |
| 1914 | MockRead(SYNCHRONOUS, 0), |
| 1915 | }; |
| 1916 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1917 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1918 | |
| 1919 | TestCompletionCallback callback; |
| 1920 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1921 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1922 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1923 | |
| 1924 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1925 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1926 | |
| 1927 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1928 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1929 | if (rv == ERR_IO_PENDING) |
| 1930 | rv = callback.WaitForResult(); |
| 1931 | EXPECT_EQ(5, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1932 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1933 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1934 | |
| 1935 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 1936 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1937 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1938 | } |
| 1939 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1940 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose2) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1941 | HttpRequestInfo request; |
| 1942 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1943 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1944 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1945 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 1946 | auto trans = |
| 1947 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1948 | |
| 1949 | MockRead data_reads[] = { |
| 1950 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1951 | MockRead("Connection: keep-alive\r\n"), |
| 1952 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1953 | MockRead(SYNCHRONOUS, 0), |
| 1954 | }; |
| 1955 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1956 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1957 | |
| 1958 | TestCompletionCallback callback; |
| 1959 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1960 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1961 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1962 | |
| 1963 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1964 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1965 | |
| 1966 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1967 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1968 | if (rv == ERR_IO_PENDING) |
| 1969 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1970 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1971 | |
| 1972 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 1973 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1974 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1975 | } |
| 1976 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1977 | // Test that we correctly reuse a keep-alive connection after not explicitly |
| 1978 | // reading the body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1979 | TEST_F(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) { |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1980 | HttpRequestInfo request; |
| 1981 | request.method = "GET"; |
| 1982 | request.url = GURL("http://www.foo.com/"); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1983 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1984 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1985 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1986 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1987 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1988 | const char* request_data = |
| 1989 | "GET / HTTP/1.1\r\n" |
| 1990 | "Host: www.foo.com\r\n" |
| 1991 | "Connection: keep-alive\r\n\r\n"; |
| 1992 | MockWrite data_writes[] = { |
| 1993 | MockWrite(ASYNC, 0, request_data), MockWrite(ASYNC, 2, request_data), |
| 1994 | MockWrite(ASYNC, 4, request_data), MockWrite(ASYNC, 6, request_data), |
| 1995 | MockWrite(ASYNC, 8, request_data), MockWrite(ASYNC, 10, request_data), |
| 1996 | MockWrite(ASYNC, 12, request_data), MockWrite(ASYNC, 14, request_data), |
| 1997 | MockWrite(ASYNC, 17, request_data), MockWrite(ASYNC, 20, request_data), |
| 1998 | }; |
| 1999 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2000 | // Note that because all these reads happen in the same |
| 2001 | // StaticSocketDataProvider, it shows that the same socket is being reused for |
| 2002 | // all transactions. |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2003 | MockRead data_reads[] = { |
| 2004 | MockRead(ASYNC, 1, "HTTP/1.1 204 No Content\r\n\r\n"), |
| 2005 | MockRead(ASYNC, 3, "HTTP/1.1 205 Reset Content\r\n\r\n"), |
| 2006 | MockRead(ASYNC, 5, "HTTP/1.1 304 Not Modified\r\n\r\n"), |
| 2007 | MockRead(ASYNC, 7, |
| 2008 | "HTTP/1.1 302 Found\r\n" |
| 2009 | "Content-Length: 0\r\n\r\n"), |
| 2010 | MockRead(ASYNC, 9, |
| 2011 | "HTTP/1.1 302 Found\r\n" |
| 2012 | "Content-Length: 5\r\n\r\n" |
| 2013 | "hello"), |
| 2014 | MockRead(ASYNC, 11, |
| 2015 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 2016 | "Content-Length: 0\r\n\r\n"), |
| 2017 | MockRead(ASYNC, 13, |
| 2018 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 2019 | "Content-Length: 5\r\n\r\n" |
| 2020 | "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2021 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2022 | // In the next two rounds, IsConnectedAndIdle returns false, due to |
| 2023 | // the set_busy_before_sync_reads(true) call, while the |
| 2024 | // HttpNetworkTransaction is being shut down, but the socket is still |
| 2025 | // reuseable. See http://crbug.com/544255. |
| 2026 | MockRead(ASYNC, 15, |
| 2027 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 2028 | "Content-Length: 5\r\n\r\n"), |
| 2029 | MockRead(SYNCHRONOUS, 16, "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2030 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2031 | MockRead(ASYNC, 18, |
| 2032 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 2033 | "Content-Length: 5\r\n\r\n" |
| 2034 | "he"), |
| 2035 | MockRead(SYNCHRONOUS, 19, "llo"), |
| 2036 | |
| 2037 | // The body of the final request is actually read. |
| 2038 | MockRead(ASYNC, 21, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 2039 | MockRead(ASYNC, 22, "hello"), |
| 2040 | }; |
| 2041 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 2042 | arraysize(data_writes)); |
| 2043 | data.set_busy_before_sync_reads(true); |
| 2044 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 2045 | |
| 2046 | const int kNumUnreadBodies = arraysize(data_writes) - 1; |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2047 | std::string response_lines[kNumUnreadBodies]; |
| 2048 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 2049 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2050 | for (size_t i = 0; i < kNumUnreadBodies; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2051 | TestCompletionCallback callback; |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2052 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2053 | auto trans = base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
| 2054 | session.get()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2055 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2056 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2057 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2058 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2059 | LoadTimingInfo load_timing_info; |
| 2060 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2061 | if (i == 0) { |
| 2062 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2063 | first_socket_log_id = load_timing_info.socket_log_id; |
| 2064 | } else { |
| 2065 | TestLoadTimingReused(load_timing_info); |
| 2066 | EXPECT_EQ(first_socket_log_id, load_timing_info.socket_log_id); |
| 2067 | } |
| 2068 | |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2069 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2070 | ASSERT_TRUE(response); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2071 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2072 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2073 | response_lines[i] = response->headers->GetStatusLine(); |
| 2074 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2075 | // Delete the transaction without reading the response bodies. Then spin |
| 2076 | // the message loop, so the response bodies are drained. |
| 2077 | trans.reset(); |
| 2078 | base::RunLoop().RunUntilIdle(); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2079 | } |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2080 | |
| 2081 | const char* const kStatusLines[] = { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2082 | "HTTP/1.1 204 No Content", |
| 2083 | "HTTP/1.1 205 Reset Content", |
| 2084 | "HTTP/1.1 304 Not Modified", |
| 2085 | "HTTP/1.1 302 Found", |
| 2086 | "HTTP/1.1 302 Found", |
| 2087 | "HTTP/1.1 301 Moved Permanently", |
| 2088 | "HTTP/1.1 301 Moved Permanently", |
| 2089 | "HTTP/1.1 200 Hunky-Dory", |
| 2090 | "HTTP/1.1 200 Hunky-Dory", |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2091 | }; |
| 2092 | |
mostynb | 91e0da98 | 2015-01-20 19:17:27 | [diff] [blame] | 2093 | static_assert(kNumUnreadBodies == arraysize(kStatusLines), |
| 2094 | "forgot to update kStatusLines"); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2095 | |
| 2096 | for (int i = 0; i < kNumUnreadBodies; ++i) |
| 2097 | EXPECT_EQ(kStatusLines[i], response_lines[i]); |
| 2098 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2099 | TestCompletionCallback callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2100 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2101 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2102 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2103 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2104 | ASSERT_TRUE(response); |
| 2105 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2106 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 2107 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2108 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2109 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2110 | EXPECT_EQ("hello", response_data); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2111 | } |
| 2112 | |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2113 | // Sockets that receive extra data after a response is complete should not be |
| 2114 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2115 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData1) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2116 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2117 | MockWrite data_writes1[] = { |
| 2118 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 2119 | "Host: www.borked.com\r\n" |
| 2120 | "Connection: keep-alive\r\n\r\n"), |
| 2121 | }; |
| 2122 | |
| 2123 | MockRead data_reads1[] = { |
| 2124 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2125 | "Connection: keep-alive\r\n" |
| 2126 | "Content-Length: 22\r\n\r\n" |
| 2127 | "This server is borked."), |
| 2128 | }; |
| 2129 | |
| 2130 | MockWrite data_writes2[] = { |
| 2131 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2132 | "Host: www.borked.com\r\n" |
| 2133 | "Connection: keep-alive\r\n\r\n"), |
| 2134 | }; |
| 2135 | |
| 2136 | MockRead data_reads2[] = { |
| 2137 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2138 | "Content-Length: 3\r\n\r\n" |
| 2139 | "foo"), |
| 2140 | }; |
| 2141 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2142 | data_writes1, arraysize(data_writes1)); |
| 2143 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2144 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2145 | data_writes2, arraysize(data_writes2)); |
| 2146 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2147 | |
| 2148 | TestCompletionCallback callback; |
| 2149 | HttpRequestInfo request1; |
| 2150 | request1.method = "HEAD"; |
| 2151 | request1.url = GURL("http://www.borked.com/"); |
| 2152 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2153 | auto trans1 = |
| 2154 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2155 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2156 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2157 | |
| 2158 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2159 | ASSERT_TRUE(response1); |
| 2160 | ASSERT_TRUE(response1->headers); |
| 2161 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2162 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2163 | |
| 2164 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2165 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2166 | EXPECT_EQ("", response_data1); |
| 2167 | // Deleting the transaction attempts to release the socket back into the |
| 2168 | // socket pool. |
| 2169 | trans1.reset(); |
| 2170 | |
| 2171 | HttpRequestInfo request2; |
| 2172 | request2.method = "GET"; |
| 2173 | request2.url = GURL("http://www.borked.com/foo"); |
| 2174 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2175 | auto trans2 = |
| 2176 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2177 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2178 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2179 | |
| 2180 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2181 | ASSERT_TRUE(response2); |
| 2182 | ASSERT_TRUE(response2->headers); |
| 2183 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2184 | |
| 2185 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2186 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2187 | EXPECT_EQ("foo", response_data2); |
| 2188 | } |
| 2189 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2190 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData2) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2191 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2192 | MockWrite data_writes1[] = { |
| 2193 | MockWrite("GET / HTTP/1.1\r\n" |
| 2194 | "Host: www.borked.com\r\n" |
| 2195 | "Connection: keep-alive\r\n\r\n"), |
| 2196 | }; |
| 2197 | |
| 2198 | MockRead data_reads1[] = { |
| 2199 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2200 | "Connection: keep-alive\r\n" |
| 2201 | "Content-Length: 22\r\n\r\n" |
| 2202 | "This server is borked." |
| 2203 | "Bonus data!"), |
| 2204 | }; |
| 2205 | |
| 2206 | MockWrite data_writes2[] = { |
| 2207 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2208 | "Host: www.borked.com\r\n" |
| 2209 | "Connection: keep-alive\r\n\r\n"), |
| 2210 | }; |
| 2211 | |
| 2212 | MockRead data_reads2[] = { |
| 2213 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2214 | "Content-Length: 3\r\n\r\n" |
| 2215 | "foo"), |
| 2216 | }; |
| 2217 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2218 | data_writes1, arraysize(data_writes1)); |
| 2219 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2220 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2221 | data_writes2, arraysize(data_writes2)); |
| 2222 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2223 | |
| 2224 | TestCompletionCallback callback; |
| 2225 | HttpRequestInfo request1; |
| 2226 | request1.method = "GET"; |
| 2227 | request1.url = GURL("http://www.borked.com/"); |
| 2228 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2229 | auto trans1 = |
| 2230 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2231 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2232 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2233 | |
| 2234 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2235 | ASSERT_TRUE(response1); |
| 2236 | ASSERT_TRUE(response1->headers); |
| 2237 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2238 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2239 | |
| 2240 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2241 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2242 | EXPECT_EQ("This server is borked.", response_data1); |
| 2243 | // Deleting the transaction attempts to release the socket back into the |
| 2244 | // socket pool. |
| 2245 | trans1.reset(); |
| 2246 | |
| 2247 | HttpRequestInfo request2; |
| 2248 | request2.method = "GET"; |
| 2249 | request2.url = GURL("http://www.borked.com/foo"); |
| 2250 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2251 | auto trans2 = |
| 2252 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2253 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2254 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2255 | |
| 2256 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2257 | ASSERT_TRUE(response2); |
| 2258 | ASSERT_TRUE(response2->headers); |
| 2259 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2260 | |
| 2261 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2262 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2263 | EXPECT_EQ("foo", response_data2); |
| 2264 | } |
| 2265 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2266 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData3) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2267 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2268 | MockWrite data_writes1[] = { |
| 2269 | MockWrite("GET / HTTP/1.1\r\n" |
| 2270 | "Host: www.borked.com\r\n" |
| 2271 | "Connection: keep-alive\r\n\r\n"), |
| 2272 | }; |
| 2273 | |
| 2274 | MockRead data_reads1[] = { |
| 2275 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2276 | "Connection: keep-alive\r\n" |
| 2277 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2278 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2279 | MockRead("0\r\n\r\nBonus data!"), |
| 2280 | }; |
| 2281 | |
| 2282 | MockWrite data_writes2[] = { |
| 2283 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2284 | "Host: www.borked.com\r\n" |
| 2285 | "Connection: keep-alive\r\n\r\n"), |
| 2286 | }; |
| 2287 | |
| 2288 | MockRead data_reads2[] = { |
| 2289 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2290 | "Content-Length: 3\r\n\r\n" |
| 2291 | "foo"), |
| 2292 | }; |
| 2293 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2294 | data_writes1, arraysize(data_writes1)); |
| 2295 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2296 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2297 | data_writes2, arraysize(data_writes2)); |
| 2298 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2299 | |
| 2300 | TestCompletionCallback callback; |
| 2301 | HttpRequestInfo request1; |
| 2302 | request1.method = "GET"; |
| 2303 | request1.url = GURL("http://www.borked.com/"); |
| 2304 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2305 | auto trans1 = |
| 2306 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2307 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2308 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2309 | |
| 2310 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2311 | ASSERT_TRUE(response1); |
| 2312 | ASSERT_TRUE(response1->headers); |
| 2313 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2314 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2315 | |
| 2316 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2317 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2318 | EXPECT_EQ("This server is borked.", response_data1); |
| 2319 | // Deleting the transaction attempts to release the socket back into the |
| 2320 | // socket pool. |
| 2321 | trans1.reset(); |
| 2322 | |
| 2323 | HttpRequestInfo request2; |
| 2324 | request2.method = "GET"; |
| 2325 | request2.url = GURL("http://www.borked.com/foo"); |
| 2326 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2327 | auto trans2 = |
| 2328 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2329 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2330 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2331 | |
| 2332 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2333 | ASSERT_TRUE(response2); |
| 2334 | ASSERT_TRUE(response2->headers); |
| 2335 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2336 | |
| 2337 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2338 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2339 | EXPECT_EQ("foo", response_data2); |
| 2340 | } |
| 2341 | |
| 2342 | // This is a little different from the others - it tests the case that the |
| 2343 | // HttpStreamParser doesn't know if there's extra data on a socket or not when |
| 2344 | // the HttpNetworkTransaction is torn down, because the response body hasn't |
| 2345 | // been read from yet, but the request goes through the HttpResponseBodyDrainer. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2346 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData4) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2347 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2348 | MockWrite data_writes1[] = { |
| 2349 | MockWrite("GET / HTTP/1.1\r\n" |
| 2350 | "Host: www.borked.com\r\n" |
| 2351 | "Connection: keep-alive\r\n\r\n"), |
| 2352 | }; |
| 2353 | |
| 2354 | MockRead data_reads1[] = { |
| 2355 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2356 | "Connection: keep-alive\r\n" |
| 2357 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2358 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2359 | MockRead("0\r\n\r\nBonus data!"), |
| 2360 | }; |
| 2361 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2362 | data_writes1, arraysize(data_writes1)); |
| 2363 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2364 | |
| 2365 | TestCompletionCallback callback; |
| 2366 | HttpRequestInfo request1; |
| 2367 | request1.method = "GET"; |
| 2368 | request1.url = GURL("http://www.borked.com/"); |
| 2369 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2370 | auto trans = |
| 2371 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 2372 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2373 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2374 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2375 | const HttpResponseInfo* response1 = trans->GetResponseInfo(); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2376 | ASSERT_TRUE(response1); |
| 2377 | ASSERT_TRUE(response1->headers); |
| 2378 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2379 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2380 | |
| 2381 | // Deleting the transaction creates an HttpResponseBodyDrainer to read the |
| 2382 | // response body. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2383 | trans.reset(); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2384 | |
| 2385 | // Let the HttpResponseBodyDrainer drain the socket. It should determine the |
| 2386 | // socket can't be reused, rather than returning it to the socket pool. |
| 2387 | base::RunLoop().RunUntilIdle(); |
| 2388 | |
| 2389 | // There should be no idle sockets in the pool. |
| 2390 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2391 | } |
| 2392 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2393 | // Test the request-challenge-retry sequence for basic auth. |
| 2394 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2395 | TEST_F(HttpNetworkTransactionTest, BasicAuth) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2396 | HttpRequestInfo request; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2397 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2398 | request.url = GURL("http://www.example.org/"); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2399 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2400 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2401 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2402 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2403 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2404 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2405 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2406 | MockWrite( |
| 2407 | "GET / HTTP/1.1\r\n" |
| 2408 | "Host: www.example.org\r\n" |
| 2409 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2410 | }; |
| 2411 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2412 | MockRead data_reads1[] = { |
| 2413 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2414 | // Give a couple authenticate options (only the middle one is actually |
| 2415 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 2416 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2417 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2418 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2419 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2420 | // Large content-length -- won't matter, as connection will be reset. |
| 2421 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2422 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2423 | }; |
| 2424 | |
| 2425 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2426 | // be issuing -- the final header line contains the credentials. |
| 2427 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2428 | MockWrite( |
| 2429 | "GET / HTTP/1.1\r\n" |
| 2430 | "Host: www.example.org\r\n" |
| 2431 | "Connection: keep-alive\r\n" |
| 2432 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2433 | }; |
| 2434 | |
| 2435 | // Lastly, the server responds with the actual content. |
| 2436 | MockRead data_reads2[] = { |
| 2437 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2438 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2439 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2440 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2441 | }; |
| 2442 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2443 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2444 | data_writes1, arraysize(data_writes1)); |
| 2445 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2446 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2447 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2448 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2449 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2450 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2451 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2452 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2453 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2454 | |
| 2455 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2456 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2457 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2458 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2459 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2460 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2461 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2462 | int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2463 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2464 | int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2465 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2466 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2467 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2468 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2469 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2470 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2471 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2472 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2473 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2474 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2475 | |
| 2476 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2477 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2478 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2479 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2480 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2481 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2482 | // The load timing after restart should have a new socket ID, and times after |
| 2483 | // those of the first load timing. |
| 2484 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2485 | load_timing_info2.connect_timing.connect_start); |
| 2486 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2487 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2488 | int64_t writes_size2 = CountWriteBytes(data_writes2, arraysize(data_writes2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2489 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2490 | int64_t reads_size2 = CountReadBytes(data_reads2, arraysize(data_reads2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2491 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2492 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2493 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2494 | ASSERT_TRUE(response); |
| 2495 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2496 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2497 | } |
| 2498 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2499 | // Test the request-challenge-retry sequence for basic auth. |
| 2500 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2501 | TEST_F(HttpNetworkTransactionTest, BasicAuthWithAddressChange) { |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2502 | HttpRequestInfo request; |
| 2503 | request.method = "GET"; |
| 2504 | request.url = GURL("http://www.example.org/"); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2505 | |
| 2506 | TestNetLog log; |
| 2507 | MockHostResolver* resolver = new MockHostResolver(); |
| 2508 | session_deps_.net_log = &log; |
| 2509 | session_deps_.host_resolver.reset(resolver); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2510 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2511 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2512 | |
| 2513 | resolver->rules()->ClearRules(); |
| 2514 | resolver->rules()->AddRule("www.example.org", "127.0.0.1"); |
| 2515 | |
| 2516 | MockWrite data_writes1[] = { |
| 2517 | MockWrite("GET / HTTP/1.1\r\n" |
| 2518 | "Host: www.example.org\r\n" |
| 2519 | "Connection: keep-alive\r\n\r\n"), |
| 2520 | }; |
| 2521 | |
| 2522 | MockRead data_reads1[] = { |
| 2523 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2524 | // Give a couple authenticate options (only the middle one is actually |
| 2525 | // supported). |
| 2526 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 2527 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2528 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2529 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2530 | // Large content-length -- won't matter, as connection will be reset. |
| 2531 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 2532 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 2533 | }; |
| 2534 | |
| 2535 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2536 | // be issuing -- the final header line contains the credentials. |
| 2537 | MockWrite data_writes2[] = { |
| 2538 | MockWrite("GET / HTTP/1.1\r\n" |
| 2539 | "Host: www.example.org\r\n" |
| 2540 | "Connection: keep-alive\r\n" |
| 2541 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2542 | }; |
| 2543 | |
| 2544 | // Lastly, the server responds with the actual content. |
| 2545 | MockRead data_reads2[] = { |
| 2546 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2547 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2548 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, OK), |
| 2549 | }; |
| 2550 | |
| 2551 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2552 | data_writes1, arraysize(data_writes1)); |
| 2553 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2554 | data_writes2, arraysize(data_writes2)); |
| 2555 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2556 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2557 | |
| 2558 | TestCompletionCallback callback1; |
| 2559 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2560 | EXPECT_EQ(OK, callback1.GetResult(trans.Start(&request, callback1.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2561 | NetLogWithSource()))); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2562 | |
| 2563 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2564 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2565 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2566 | |
| 2567 | int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2568 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2569 | int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2570 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2571 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2572 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2573 | ASSERT_TRUE(response); |
| 2574 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 2575 | |
| 2576 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2577 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2578 | ASSERT_FALSE(endpoint.address().empty()); |
| 2579 | EXPECT_EQ("127.0.0.1:80", endpoint.ToString()); |
| 2580 | |
| 2581 | resolver->rules()->ClearRules(); |
| 2582 | resolver->rules()->AddRule("www.example.org", "127.0.0.2"); |
| 2583 | |
| 2584 | TestCompletionCallback callback2; |
| 2585 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2586 | EXPECT_EQ(OK, callback2.GetResult(trans.RestartWithAuth( |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2587 | AuthCredentials(kFoo, kBar), callback2.callback()))); |
| 2588 | |
| 2589 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2590 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2591 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2592 | // The load timing after restart should have a new socket ID, and times after |
| 2593 | // those of the first load timing. |
| 2594 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2595 | load_timing_info2.connect_timing.connect_start); |
| 2596 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2597 | |
| 2598 | int64_t writes_size2 = CountWriteBytes(data_writes2, arraysize(data_writes2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2599 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2600 | int64_t reads_size2 = CountReadBytes(data_reads2, arraysize(data_reads2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2601 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2602 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2603 | response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2604 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2605 | EXPECT_FALSE(response->auth_challenge); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2606 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 2607 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2608 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2609 | ASSERT_FALSE(endpoint.address().empty()); |
| 2610 | EXPECT_EQ("127.0.0.2:80", endpoint.ToString()); |
| 2611 | } |
| 2612 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2613 | TEST_F(HttpNetworkTransactionTest, DoNotSendAuth) { |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2614 | HttpRequestInfo request; |
| 2615 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2616 | request.url = GURL("http://www.example.org/"); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2617 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2618 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2619 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2620 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2621 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2622 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2623 | MockWrite( |
| 2624 | "GET / HTTP/1.1\r\n" |
| 2625 | "Host: www.example.org\r\n" |
| 2626 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2627 | }; |
| 2628 | |
| 2629 | MockRead data_reads[] = { |
| 2630 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2631 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2632 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2633 | // Large content-length -- won't matter, as connection will be reset. |
| 2634 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2635 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2636 | }; |
| 2637 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2638 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 2639 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2640 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2641 | TestCompletionCallback callback; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2642 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2643 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2644 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2645 | |
| 2646 | rv = callback.WaitForResult(); |
| 2647 | EXPECT_EQ(0, rv); |
| 2648 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2649 | int64_t writes_size = CountWriteBytes(data_writes, arraysize(data_writes)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2650 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2651 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2652 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2653 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2654 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2655 | ASSERT_TRUE(response); |
| 2656 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2657 | } |
| 2658 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2659 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2660 | // connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2661 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAlive) { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2662 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 2663 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 2664 | // reused. See http://crbug.com/544255. |
| 2665 | for (int i = 0; i < 2; ++i) { |
| 2666 | HttpRequestInfo request; |
| 2667 | request.method = "GET"; |
| 2668 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2669 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2670 | TestNetLog log; |
| 2671 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2672 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2673 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2674 | MockWrite data_writes[] = { |
| 2675 | MockWrite(ASYNC, 0, |
| 2676 | "GET / HTTP/1.1\r\n" |
| 2677 | "Host: www.example.org\r\n" |
| 2678 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2679 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2680 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2681 | // be issuing -- the final header line contains the credentials. |
| 2682 | MockWrite(ASYNC, 6, |
| 2683 | "GET / HTTP/1.1\r\n" |
| 2684 | "Host: www.example.org\r\n" |
| 2685 | "Connection: keep-alive\r\n" |
| 2686 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2687 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2688 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2689 | MockRead data_reads[] = { |
| 2690 | MockRead(ASYNC, 1, "HTTP/1.1 401 Unauthorized\r\n"), |
| 2691 | MockRead(ASYNC, 2, "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2692 | MockRead(ASYNC, 3, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2693 | MockRead(ASYNC, 4, "Content-Length: 14\r\n\r\n"), |
| 2694 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 5, "Unauthorized\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2695 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2696 | // Lastly, the server responds with the actual content. |
| 2697 | MockRead(ASYNC, 7, "HTTP/1.1 200 OK\r\n"), |
| 2698 | MockRead(ASYNC, 8, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2699 | MockRead(ASYNC, 9, "Content-Length: 5\r\n\r\n"), |
| 2700 | MockRead(ASYNC, 10, "Hello"), |
| 2701 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2702 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2703 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 2704 | arraysize(data_writes)); |
| 2705 | data.set_busy_before_sync_reads(true); |
| 2706 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2707 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2708 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2709 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2710 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2711 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2712 | ASSERT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2713 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2714 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2715 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2716 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2717 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2718 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2719 | ASSERT_TRUE(response); |
| 2720 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2721 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2722 | TestCompletionCallback callback2; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2723 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2724 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 2725 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2726 | ASSERT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2727 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2728 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2729 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2730 | TestLoadTimingReused(load_timing_info2); |
| 2731 | // The load timing after restart should have the same socket ID, and times |
| 2732 | // those of the first load timing. |
| 2733 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2734 | load_timing_info2.send_start); |
| 2735 | 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] | 2736 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2737 | response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2738 | ASSERT_TRUE(response); |
| 2739 | EXPECT_FALSE(response->auth_challenge); |
| 2740 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2741 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2742 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2743 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2744 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2745 | int64_t writes_size = CountWriteBytes(data_writes, arraysize(data_writes)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2746 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2747 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2748 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2749 | } |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2750 | } |
| 2751 | |
| 2752 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2753 | // connection and with no response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2754 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2755 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2756 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2757 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2758 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2759 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2760 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2761 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2762 | MockWrite("GET / HTTP/1.1\r\n" |
| 2763 | "Host: www.example.org\r\n" |
| 2764 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2765 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2766 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2767 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2768 | MockWrite("GET / HTTP/1.1\r\n" |
| 2769 | "Host: www.example.org\r\n" |
| 2770 | "Connection: keep-alive\r\n" |
| 2771 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2772 | }; |
| 2773 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2774 | MockRead data_reads1[] = { |
| 2775 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2776 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2777 | MockRead("Content-Length: 0\r\n\r\n"), // No response body. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2778 | |
| 2779 | // Lastly, the server responds with the actual content. |
| 2780 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2781 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2782 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2783 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2784 | }; |
| 2785 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2786 | // An incorrect reconnect would cause this to be read. |
| 2787 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2788 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2789 | }; |
| 2790 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2791 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2792 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2793 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2794 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2795 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2796 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2797 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2798 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2799 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2800 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2801 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2802 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2803 | |
| 2804 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2805 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2806 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2807 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2808 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2809 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2810 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2811 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2812 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2813 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2814 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2815 | |
| 2816 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2817 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2818 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2819 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2820 | ASSERT_TRUE(response); |
| 2821 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2822 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2823 | } |
| 2824 | |
| 2825 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2826 | // connection and with a large response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2827 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2828 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2829 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2830 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2831 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2832 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2833 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2834 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2835 | MockWrite("GET / HTTP/1.1\r\n" |
| 2836 | "Host: www.example.org\r\n" |
| 2837 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2838 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2839 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2840 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2841 | MockWrite("GET / HTTP/1.1\r\n" |
| 2842 | "Host: www.example.org\r\n" |
| 2843 | "Connection: keep-alive\r\n" |
| 2844 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2845 | }; |
| 2846 | |
| 2847 | // Respond with 5 kb of response body. |
| 2848 | std::string large_body_string("Unauthorized"); |
| 2849 | large_body_string.append(5 * 1024, ' '); |
| 2850 | large_body_string.append("\r\n"); |
| 2851 | |
| 2852 | MockRead data_reads1[] = { |
| 2853 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2854 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2855 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2856 | // 5134 = 12 + 5 * 1024 + 2 |
| 2857 | MockRead("Content-Length: 5134\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2858 | MockRead(ASYNC, large_body_string.data(), large_body_string.size()), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2859 | |
| 2860 | // Lastly, the server responds with the actual content. |
| 2861 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2862 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2863 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2864 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2865 | }; |
| 2866 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2867 | // An incorrect reconnect would cause this to be read. |
| 2868 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2869 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2870 | }; |
| 2871 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2872 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2873 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2874 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2875 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2876 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2877 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2878 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2879 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2880 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2881 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2882 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2883 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2884 | |
| 2885 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2886 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2887 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2888 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2889 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2890 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2891 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2892 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2893 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2894 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2895 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2896 | |
| 2897 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2898 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2899 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2900 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2901 | ASSERT_TRUE(response); |
| 2902 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2903 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2904 | } |
| 2905 | |
| 2906 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2907 | // connection, but the server gets impatient and closes the connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2908 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) { |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2909 | HttpRequestInfo request; |
| 2910 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2911 | request.url = GURL("http://www.example.org/"); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2912 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2913 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2914 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2915 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2916 | MockWrite( |
| 2917 | "GET / HTTP/1.1\r\n" |
| 2918 | "Host: www.example.org\r\n" |
| 2919 | "Connection: keep-alive\r\n\r\n"), |
| 2920 | // This simulates the seemingly successful write to a closed connection |
| 2921 | // if the bug is not fixed. |
| 2922 | MockWrite( |
| 2923 | "GET / HTTP/1.1\r\n" |
| 2924 | "Host: www.example.org\r\n" |
| 2925 | "Connection: keep-alive\r\n" |
| 2926 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2927 | }; |
| 2928 | |
| 2929 | MockRead data_reads1[] = { |
| 2930 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2931 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2932 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2933 | MockRead("Content-Length: 14\r\n\r\n"), |
| 2934 | // Tell MockTCPClientSocket to simulate the server closing the connection. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2935 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2936 | MockRead("Unauthorized\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2937 | MockRead(SYNCHRONOUS, OK), // The server closes the connection. |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2938 | }; |
| 2939 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2940 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2941 | // be issuing -- the final header line contains the credentials. |
| 2942 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2943 | MockWrite( |
| 2944 | "GET / HTTP/1.1\r\n" |
| 2945 | "Host: www.example.org\r\n" |
| 2946 | "Connection: keep-alive\r\n" |
| 2947 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2948 | }; |
| 2949 | |
| 2950 | // Lastly, the server responds with the actual content. |
| 2951 | MockRead data_reads2[] = { |
| 2952 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2953 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2954 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2955 | MockRead("hello"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2956 | }; |
| 2957 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2958 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2959 | data_writes1, arraysize(data_writes1)); |
| 2960 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2961 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2962 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2963 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2964 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2965 | TestCompletionCallback callback1; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2966 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2967 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2968 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2969 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2970 | |
| 2971 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2972 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2973 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2974 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2975 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2976 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2977 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2978 | TestCompletionCallback callback2; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2979 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2980 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2981 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2982 | |
| 2983 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2984 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2985 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2986 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2987 | ASSERT_TRUE(response); |
| 2988 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2989 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2990 | } |
| 2991 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2992 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 2993 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2994 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp10) { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2995 | HttpRequestInfo request; |
| 2996 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2997 | request.url = GURL("https://www.example.org/"); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2998 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2999 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3000 | |
| 3001 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3002 | session_deps_.proxy_service = |
| 3003 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3004 | BoundTestNetLog log; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3005 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3006 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3007 | |
| 3008 | // Since we have proxy, should try to establish tunnel. |
| 3009 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3010 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3011 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3012 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3013 | }; |
| 3014 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3015 | // The proxy responds to the connect with a 407, using a non-persistent |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3016 | // connection. |
| 3017 | MockRead data_reads1[] = { |
| 3018 | // No credentials. |
| 3019 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 3020 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3021 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3022 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3023 | // Since the first connection couldn't be reused, need to establish another |
| 3024 | // once given credentials. |
| 3025 | MockWrite data_writes2[] = { |
| 3026 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3027 | // be issuing -- the final header line contains the credentials. |
| 3028 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3029 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3030 | "Proxy-Connection: keep-alive\r\n" |
| 3031 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3032 | |
| 3033 | MockWrite("GET / HTTP/1.1\r\n" |
| 3034 | "Host: www.example.org\r\n" |
| 3035 | "Connection: keep-alive\r\n\r\n"), |
| 3036 | }; |
| 3037 | |
| 3038 | MockRead data_reads2[] = { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3039 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3040 | |
| 3041 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3042 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3043 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3044 | MockRead(SYNCHRONOUS, "hello"), |
| 3045 | }; |
| 3046 | |
| 3047 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3048 | data_writes1, arraysize(data_writes1)); |
| 3049 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3050 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3051 | data_writes2, arraysize(data_writes2)); |
| 3052 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3053 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3054 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3055 | |
| 3056 | TestCompletionCallback callback1; |
| 3057 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3058 | auto trans = |
| 3059 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3060 | |
| 3061 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3062 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3063 | |
| 3064 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3065 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3066 | TestNetLogEntry::List entries; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3067 | log.GetEntries(&entries); |
| 3068 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3069 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3070 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3071 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3072 | entries, pos, |
| 3073 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3074 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3075 | |
| 3076 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3077 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3078 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3079 | ASSERT_TRUE(response->headers); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3080 | EXPECT_EQ(407, response->headers->response_code()); |
| 3081 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3082 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3083 | |
| 3084 | LoadTimingInfo load_timing_info; |
| 3085 | // CONNECT requests and responses are handled at the connect job level, so |
| 3086 | // the transaction does not yet have a connection. |
| 3087 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3088 | |
| 3089 | TestCompletionCallback callback2; |
| 3090 | |
| 3091 | rv = |
| 3092 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3093 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3094 | |
| 3095 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3096 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3097 | |
| 3098 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3099 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3100 | |
| 3101 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3102 | EXPECT_EQ(200, response->headers->response_code()); |
| 3103 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 3104 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3105 | |
| 3106 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3107 | EXPECT_FALSE(response->auth_challenge); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3108 | |
| 3109 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3110 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3111 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3112 | |
| 3113 | trans.reset(); |
| 3114 | session->CloseAllConnections(); |
| 3115 | } |
| 3116 | |
| 3117 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 3118 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3119 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp11) { |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3120 | HttpRequestInfo request; |
| 3121 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3122 | request.url = GURL("https://www.example.org/"); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3123 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3124 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3125 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3126 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3127 | session_deps_.proxy_service = |
| 3128 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3129 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3130 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3131 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3132 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3133 | // Since we have proxy, should try to establish tunnel. |
| 3134 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3135 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3136 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3137 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3138 | }; |
| 3139 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3140 | // The proxy responds to the connect with a 407, using a non-persistent |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3141 | // connection. |
| 3142 | MockRead data_reads1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3143 | // No credentials. |
| 3144 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3145 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3146 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3147 | }; |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3148 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3149 | MockWrite data_writes2[] = { |
| 3150 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3151 | // be issuing -- the final header line contains the credentials. |
| 3152 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3153 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3154 | "Proxy-Connection: keep-alive\r\n" |
| 3155 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3156 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3157 | MockWrite("GET / HTTP/1.1\r\n" |
| 3158 | "Host: www.example.org\r\n" |
| 3159 | "Connection: keep-alive\r\n\r\n"), |
| 3160 | }; |
| 3161 | |
| 3162 | MockRead data_reads2[] = { |
| 3163 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3164 | |
| 3165 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3166 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3167 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3168 | MockRead(SYNCHRONOUS, "hello"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3169 | }; |
| 3170 | |
| 3171 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3172 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3173 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3174 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3175 | data_writes2, arraysize(data_writes2)); |
| 3176 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3177 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3178 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3179 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3180 | TestCompletionCallback callback1; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3181 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3182 | auto trans = |
| 3183 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3184 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3185 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3186 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3187 | |
| 3188 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3189 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3190 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3191 | log.GetEntries(&entries); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3192 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3193 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3194 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3195 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3196 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3197 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3198 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3199 | |
| 3200 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3201 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3202 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3203 | ASSERT_TRUE(response->headers); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3204 | EXPECT_EQ(407, response->headers->response_code()); |
| 3205 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3206 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3207 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3208 | LoadTimingInfo load_timing_info; |
| 3209 | // CONNECT requests and responses are handled at the connect job level, so |
| 3210 | // the transaction does not yet have a connection. |
| 3211 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3212 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3213 | TestCompletionCallback callback2; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3214 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3215 | rv = trans->RestartWithAuth( |
| 3216 | AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3217 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3218 | |
| 3219 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3220 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3221 | |
| 3222 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3223 | ASSERT_TRUE(response); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3224 | |
| 3225 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3226 | EXPECT_EQ(200, response->headers->response_code()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3227 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3228 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3229 | |
| 3230 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3231 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3232 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3233 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3234 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3235 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3236 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3237 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3238 | session->CloseAllConnections(); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3239 | } |
| 3240 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3241 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3242 | // proxy connection with HTTP/1.0 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3243 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp10) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3244 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3245 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3246 | // reused. See http://crbug.com/544255. |
| 3247 | for (int i = 0; i < 2; ++i) { |
| 3248 | HttpRequestInfo request; |
| 3249 | request.method = "GET"; |
| 3250 | request.url = GURL("https://www.example.org/"); |
| 3251 | // Ensure that proxy authentication is attempted even |
| 3252 | // when the no authentication data flag is set. |
| 3253 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3254 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3255 | // Configure against proxy server "myproxy:70". |
| 3256 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
| 3257 | BoundTestNetLog log; |
| 3258 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3259 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3260 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3261 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3262 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3263 | // Since we have proxy, should try to establish tunnel. |
| 3264 | MockWrite data_writes1[] = { |
| 3265 | MockWrite(ASYNC, 0, |
| 3266 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3267 | "Host: www.example.org:443\r\n" |
| 3268 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3269 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3270 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3271 | // be issuing -- the final header line contains the credentials. |
| 3272 | MockWrite(ASYNC, 3, |
| 3273 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3274 | "Host: www.example.org:443\r\n" |
| 3275 | "Proxy-Connection: keep-alive\r\n" |
| 3276 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3277 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3278 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3279 | // The proxy responds to the connect with a 407, using a persistent |
| 3280 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3281 | MockRead data_reads1[] = { |
| 3282 | // No credentials. |
| 3283 | MockRead(ASYNC, 1, |
| 3284 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3285 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3286 | "Proxy-Connection: keep-alive\r\n" |
| 3287 | "Content-Length: 10\r\n\r\n"), |
| 3288 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3289 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3290 | // Wrong credentials (wrong password). |
| 3291 | MockRead(ASYNC, 4, |
| 3292 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3293 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3294 | "Proxy-Connection: keep-alive\r\n" |
| 3295 | "Content-Length: 10\r\n\r\n"), |
| 3296 | // No response body because the test stops reading here. |
| 3297 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3298 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3299 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3300 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3301 | arraysize(data_writes1)); |
| 3302 | data1.set_busy_before_sync_reads(true); |
| 3303 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3304 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3305 | TestCompletionCallback callback1; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3306 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3307 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3308 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3309 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3310 | TestNetLogEntry::List entries; |
| 3311 | log.GetEntries(&entries); |
| 3312 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3313 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3314 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3315 | ExpectLogContainsSomewhere( |
| 3316 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3317 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3318 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3319 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3320 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3321 | ASSERT_TRUE(response); |
| 3322 | ASSERT_TRUE(response->headers); |
| 3323 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3324 | EXPECT_EQ(407, response->headers->response_code()); |
| 3325 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3326 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3327 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3328 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3329 | TestCompletionCallback callback2; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3330 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3331 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3332 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3333 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3334 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3335 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3336 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3337 | ASSERT_TRUE(response); |
| 3338 | ASSERT_TRUE(response->headers); |
| 3339 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3340 | EXPECT_EQ(407, response->headers->response_code()); |
| 3341 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3342 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3343 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3344 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3345 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3346 | // out of scope. |
| 3347 | session->CloseAllConnections(); |
| 3348 | } |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3349 | } |
| 3350 | |
| 3351 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3352 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3353 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp11) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3354 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3355 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3356 | // reused. See http://crbug.com/544255. |
| 3357 | for (int i = 0; i < 2; ++i) { |
| 3358 | HttpRequestInfo request; |
| 3359 | request.method = "GET"; |
| 3360 | request.url = GURL("https://www.example.org/"); |
| 3361 | // Ensure that proxy authentication is attempted even |
| 3362 | // when the no authentication data flag is set. |
| 3363 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
| 3364 | |
| 3365 | // Configure against proxy server "myproxy:70". |
| 3366 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
| 3367 | BoundTestNetLog log; |
| 3368 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3369 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3370 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3371 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3372 | |
| 3373 | // Since we have proxy, should try to establish tunnel. |
| 3374 | MockWrite data_writes1[] = { |
| 3375 | MockWrite(ASYNC, 0, |
| 3376 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3377 | "Host: www.example.org:443\r\n" |
| 3378 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3379 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3380 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3381 | // be issuing -- the final header line contains the credentials. |
| 3382 | MockWrite(ASYNC, 3, |
| 3383 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3384 | "Host: www.example.org:443\r\n" |
| 3385 | "Proxy-Connection: keep-alive\r\n" |
| 3386 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3387 | }; |
| 3388 | |
| 3389 | // The proxy responds to the connect with a 407, using a persistent |
| 3390 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3391 | MockRead data_reads1[] = { |
| 3392 | // No credentials. |
| 3393 | MockRead(ASYNC, 1, |
| 3394 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3395 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3396 | "Content-Length: 10\r\n\r\n"), |
| 3397 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
| 3398 | |
| 3399 | // Wrong credentials (wrong password). |
| 3400 | MockRead(ASYNC, 4, |
| 3401 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3402 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3403 | "Content-Length: 10\r\n\r\n"), |
| 3404 | // No response body because the test stops reading here. |
| 3405 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3406 | }; |
| 3407 | |
| 3408 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3409 | arraysize(data_writes1)); |
| 3410 | data1.set_busy_before_sync_reads(true); |
| 3411 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3412 | |
| 3413 | TestCompletionCallback callback1; |
| 3414 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3415 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3416 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3417 | |
| 3418 | TestNetLogEntry::List entries; |
| 3419 | log.GetEntries(&entries); |
| 3420 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3421 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3422 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3423 | ExpectLogContainsSomewhere( |
| 3424 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3425 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3426 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3427 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3428 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3429 | ASSERT_TRUE(response); |
| 3430 | ASSERT_TRUE(response->headers); |
| 3431 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3432 | EXPECT_EQ(407, response->headers->response_code()); |
| 3433 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3434 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3435 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3436 | |
| 3437 | TestCompletionCallback callback2; |
| 3438 | |
| 3439 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3440 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3441 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3442 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3443 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3444 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3445 | ASSERT_TRUE(response); |
| 3446 | ASSERT_TRUE(response->headers); |
| 3447 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3448 | EXPECT_EQ(407, response->headers->response_code()); |
| 3449 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3450 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3451 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3452 | |
| 3453 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3454 | // out of scope. |
| 3455 | session->CloseAllConnections(); |
| 3456 | } |
| 3457 | } |
| 3458 | |
| 3459 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3460 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel, in |
| 3461 | // the case the server sends extra data on the original socket, so it can't be |
| 3462 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3463 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveExtraData) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3464 | HttpRequestInfo request; |
| 3465 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3466 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3467 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3468 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3469 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3470 | // Configure against proxy server "myproxy:70". |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3471 | session_deps_.proxy_service = |
| 3472 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3473 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3474 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3475 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3476 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3477 | // Since we have proxy, should try to establish tunnel. |
| 3478 | MockWrite data_writes1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3479 | MockWrite(ASYNC, 0, |
| 3480 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3481 | "Host: www.example.org:443\r\n" |
| 3482 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3483 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3484 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3485 | // The proxy responds to the connect with a 407, using a persistent, but sends |
| 3486 | // extra data, so the socket cannot be reused. |
| 3487 | MockRead data_reads1[] = { |
| 3488 | // No credentials. |
| 3489 | MockRead(ASYNC, 1, |
| 3490 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3491 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3492 | "Content-Length: 10\r\n\r\n"), |
| 3493 | MockRead(SYNCHRONOUS, 2, "0123456789"), |
| 3494 | MockRead(SYNCHRONOUS, 3, "I'm broken!"), |
| 3495 | }; |
| 3496 | |
| 3497 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3498 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3499 | // be issuing -- the final header line contains the credentials. |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3500 | MockWrite(ASYNC, 0, |
| 3501 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3502 | "Host: www.example.org:443\r\n" |
| 3503 | "Proxy-Connection: keep-alive\r\n" |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3504 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3505 | |
| 3506 | MockWrite(ASYNC, 2, |
| 3507 | "GET / HTTP/1.1\r\n" |
| 3508 | "Host: www.example.org\r\n" |
| 3509 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3510 | }; |
| 3511 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3512 | MockRead data_reads2[] = { |
| 3513 | MockRead(ASYNC, 1, "HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3514 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3515 | MockRead(ASYNC, 3, |
| 3516 | "HTTP/1.1 200 OK\r\n" |
| 3517 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 3518 | "Content-Length: 5\r\n\r\n"), |
| 3519 | // No response body because the test stops reading here. |
| 3520 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 4), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3521 | }; |
| 3522 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3523 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3524 | arraysize(data_writes1)); |
| 3525 | data1.set_busy_before_sync_reads(true); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3526 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3527 | SequencedSocketData data2(data_reads2, arraysize(data_reads2), data_writes2, |
| 3528 | arraysize(data_writes2)); |
| 3529 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3530 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3531 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3532 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3533 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3534 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3535 | auto trans = |
| 3536 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3537 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3538 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3539 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3540 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3541 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3542 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3543 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3544 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3545 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3546 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3547 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3548 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3549 | NetLogEventPhase::NONE); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3550 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3551 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3552 | ASSERT_TRUE(response); |
| 3553 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3554 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3555 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3556 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3557 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3558 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3559 | LoadTimingInfo load_timing_info; |
| 3560 | // CONNECT requests and responses are handled at the connect job level, so |
| 3561 | // the transaction does not yet have a connection. |
| 3562 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3563 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3564 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3565 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3566 | rv = |
| 3567 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3568 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3569 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3570 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3571 | EXPECT_EQ(200, response->headers->response_code()); |
| 3572 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3573 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 3574 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3575 | // The password prompt info should not be set. |
| 3576 | EXPECT_FALSE(response->auth_challenge); |
| 3577 | |
| 3578 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3579 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3580 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3581 | |
| 3582 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3583 | session->CloseAllConnections(); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3584 | } |
| 3585 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3586 | // Test the case a proxy closes a socket while the challenge body is being |
| 3587 | // drained. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3588 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHangupDuringBody) { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3589 | HttpRequestInfo request; |
| 3590 | request.method = "GET"; |
| 3591 | request.url = GURL("https://www.example.org/"); |
| 3592 | // Ensure that proxy authentication is attempted even |
| 3593 | // when the no authentication data flag is set. |
| 3594 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
| 3595 | |
| 3596 | // Configure against proxy server "myproxy:70". |
| 3597 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3598 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3599 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3600 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3601 | |
| 3602 | // Since we have proxy, should try to establish tunnel. |
| 3603 | MockWrite data_writes1[] = { |
| 3604 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3605 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3606 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3607 | }; |
| 3608 | |
| 3609 | // The proxy responds to the connect with a 407, using a persistent |
| 3610 | // connection. |
| 3611 | MockRead data_reads1[] = { |
| 3612 | // No credentials. |
| 3613 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3614 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3615 | MockRead("Content-Length: 10\r\n\r\n"), MockRead("spam!"), |
| 3616 | // Server hands up in the middle of the body. |
| 3617 | MockRead(ASYNC, ERR_CONNECTION_CLOSED), |
| 3618 | }; |
| 3619 | |
| 3620 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3621 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3622 | // be issuing -- the final header line contains the credentials. |
| 3623 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3624 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3625 | "Proxy-Connection: keep-alive\r\n" |
| 3626 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3627 | |
| 3628 | MockWrite("GET / HTTP/1.1\r\n" |
| 3629 | "Host: www.example.org\r\n" |
| 3630 | "Connection: keep-alive\r\n\r\n"), |
| 3631 | }; |
| 3632 | |
| 3633 | MockRead data_reads2[] = { |
| 3634 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3635 | |
| 3636 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3637 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3638 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3639 | MockRead(SYNCHRONOUS, "hello"), |
| 3640 | }; |
| 3641 | |
| 3642 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3643 | data_writes1, arraysize(data_writes1)); |
| 3644 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3645 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3646 | data_writes2, arraysize(data_writes2)); |
| 3647 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3648 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3649 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3650 | |
| 3651 | TestCompletionCallback callback; |
| 3652 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3653 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3654 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3655 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3656 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3657 | ASSERT_TRUE(response); |
| 3658 | ASSERT_TRUE(response->headers); |
| 3659 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3660 | EXPECT_EQ(407, response->headers->response_code()); |
| 3661 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3662 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3663 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3664 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3665 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3666 | response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3667 | ASSERT_TRUE(response); |
| 3668 | ASSERT_TRUE(response->headers); |
| 3669 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3670 | EXPECT_EQ(200, response->headers->response_code()); |
| 3671 | std::string body; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3672 | EXPECT_THAT(ReadTransaction(&trans, &body), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3673 | EXPECT_EQ("hello", body); |
| 3674 | } |
| 3675 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3676 | // Test that we don't read the response body when we fail to establish a tunnel, |
| 3677 | // even if the user cancels the proxy's auth attempt. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3678 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3679 | HttpRequestInfo request; |
| 3680 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3681 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3682 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3683 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3684 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3685 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3686 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3687 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3688 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3689 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3690 | // Since we have proxy, should try to establish tunnel. |
| 3691 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3692 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3693 | "Host: www.example.org:443\r\n" |
| 3694 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3695 | }; |
| 3696 | |
| 3697 | // The proxy responds to the connect with a 407. |
| 3698 | MockRead data_reads[] = { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3699 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3700 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3701 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3702 | MockRead("0123456789"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3703 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3704 | }; |
| 3705 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 3706 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 3707 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3708 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3709 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3710 | TestCompletionCallback callback; |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3711 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3712 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3713 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3714 | |
| 3715 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3716 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3717 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3718 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3719 | ASSERT_TRUE(response); |
| 3720 | ASSERT_TRUE(response->headers); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3721 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3722 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3723 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3724 | |
| 3725 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3726 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3727 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 3728 | |
| 3729 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3730 | session->CloseAllConnections(); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3731 | } |
| 3732 | |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3733 | // Test that we don't pass extraneous headers from the proxy's response to the |
| 3734 | // caller when the proxy responds to CONNECT with 407. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3735 | TEST_F(HttpNetworkTransactionTest, SanitizeProxyAuthHeaders) { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3736 | HttpRequestInfo request; |
| 3737 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3738 | request.url = GURL("https://www.example.org/"); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3739 | |
| 3740 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3741 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3742 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3743 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3744 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3745 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3746 | |
| 3747 | // Since we have proxy, should try to establish tunnel. |
| 3748 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3749 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3750 | "Host: www.example.org:443\r\n" |
| 3751 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3752 | }; |
| 3753 | |
| 3754 | // The proxy responds to the connect with a 407. |
| 3755 | MockRead data_reads[] = { |
| 3756 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3757 | MockRead("X-Foo: bar\r\n"), |
| 3758 | MockRead("Set-Cookie: foo=bar\r\n"), |
| 3759 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3760 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3761 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3762 | }; |
| 3763 | |
| 3764 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 3765 | arraysize(data_writes)); |
| 3766 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 3767 | |
| 3768 | TestCompletionCallback callback; |
| 3769 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3770 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3771 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3772 | |
| 3773 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3774 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3775 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3776 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3777 | ASSERT_TRUE(response); |
| 3778 | ASSERT_TRUE(response->headers); |
| 3779 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3780 | EXPECT_EQ(407, response->headers->response_code()); |
| 3781 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3782 | EXPECT_FALSE(response->headers->HasHeader("X-Foo")); |
| 3783 | EXPECT_FALSE(response->headers->HasHeader("Set-Cookie")); |
| 3784 | |
| 3785 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3786 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3787 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3788 | |
| 3789 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
| 3790 | session->CloseAllConnections(); |
| 3791 | } |
| 3792 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3793 | // Test when a server (non-proxy) returns a 407 (proxy-authenticate). |
| 3794 | // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3795 | TEST_F(HttpNetworkTransactionTest, UnexpectedProxyAuth) { |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3796 | HttpRequestInfo request; |
| 3797 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3798 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3799 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3800 | // We are using a DIRECT connection (i.e. no proxy) for this session. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3801 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3802 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3803 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3804 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3805 | MockWrite( |
| 3806 | "GET / HTTP/1.1\r\n" |
| 3807 | "Host: www.example.org\r\n" |
| 3808 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3809 | }; |
| 3810 | |
| 3811 | MockRead data_reads1[] = { |
| 3812 | MockRead("HTTP/1.0 407 Proxy Auth required\r\n"), |
| 3813 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3814 | // Large content-length -- won't matter, as connection will be reset. |
| 3815 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3816 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3817 | }; |
| 3818 | |
| 3819 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3820 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3821 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3822 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3823 | TestCompletionCallback callback; |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3824 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3825 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3826 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3827 | |
| 3828 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3829 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3830 | } |
| 3831 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3832 | // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) |
| 3833 | // through a non-authenticating proxy. The request should fail with |
| 3834 | // ERR_UNEXPECTED_PROXY_AUTH. |
| 3835 | // Note that it is impossible to detect if an HTTP server returns a 407 through |
| 3836 | // a non-authenticating proxy - there is nothing to indicate whether the |
| 3837 | // response came from the proxy or the server, so it is treated as if the proxy |
| 3838 | // issued the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3839 | TEST_F(HttpNetworkTransactionTest, HttpsServerRequestsProxyAuthThroughProxy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3840 | HttpRequestInfo request; |
| 3841 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3842 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3843 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3844 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3845 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3846 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3847 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3848 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3849 | // Since we have proxy, should try to establish tunnel. |
| 3850 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3851 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3852 | "Host: www.example.org:443\r\n" |
| 3853 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3854 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3855 | MockWrite("GET / HTTP/1.1\r\n" |
| 3856 | "Host: www.example.org\r\n" |
| 3857 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3858 | }; |
| 3859 | |
| 3860 | MockRead data_reads1[] = { |
| 3861 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3862 | |
| 3863 | MockRead("HTTP/1.1 407 Unauthorized\r\n"), |
| 3864 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3865 | MockRead("\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3866 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3867 | }; |
| 3868 | |
| 3869 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3870 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3871 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3872 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3873 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3874 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3875 | TestCompletionCallback callback1; |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3876 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3877 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3878 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3879 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3880 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3881 | |
| 3882 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3883 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3884 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3885 | log.GetEntries(&entries); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3886 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3887 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3888 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3889 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3890 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3891 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3892 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3893 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3894 | |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3895 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 3896 | // that uses non-persistent connections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3897 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3898 | AuthAllowsDefaultCredentialsTunnelConnectionClose) { |
| 3899 | HttpRequestInfo request; |
| 3900 | request.method = "GET"; |
| 3901 | request.url = GURL("https://www.example.org/"); |
| 3902 | |
| 3903 | // Configure against proxy server "myproxy:70". |
| 3904 | session_deps_.proxy_service = |
| 3905 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 3906 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3907 | auto auth_handler_factory = base::MakeUnique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3908 | auth_handler_factory->set_do_init_from_challenge(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3909 | auto mock_handler = base::MakeUnique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3910 | mock_handler->set_allows_default_credentials(true); |
| 3911 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3912 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 3913 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3914 | |
| 3915 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 3916 | NetLog net_log; |
| 3917 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3918 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3919 | |
| 3920 | // Since we have proxy, should try to establish tunnel. |
| 3921 | MockWrite data_writes1[] = { |
| 3922 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3923 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3924 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3925 | }; |
| 3926 | |
| 3927 | // The proxy responds to the connect with a 407, using a non-persistent |
| 3928 | // connection. |
| 3929 | MockRead data_reads1[] = { |
| 3930 | // No credentials. |
| 3931 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3932 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 3933 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3934 | }; |
| 3935 | |
| 3936 | // Since the first connection couldn't be reused, need to establish another |
| 3937 | // once given credentials. |
| 3938 | MockWrite data_writes2[] = { |
| 3939 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3940 | // be issuing -- the final header line contains the credentials. |
| 3941 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3942 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3943 | "Proxy-Connection: keep-alive\r\n" |
| 3944 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3945 | |
| 3946 | MockWrite("GET / HTTP/1.1\r\n" |
| 3947 | "Host: www.example.org\r\n" |
| 3948 | "Connection: keep-alive\r\n\r\n"), |
| 3949 | }; |
| 3950 | |
| 3951 | MockRead data_reads2[] = { |
| 3952 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3953 | |
| 3954 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3955 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3956 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3957 | MockRead(SYNCHRONOUS, "hello"), |
| 3958 | }; |
| 3959 | |
| 3960 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3961 | data_writes1, arraysize(data_writes1)); |
| 3962 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3963 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3964 | data_writes2, arraysize(data_writes2)); |
| 3965 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3966 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3967 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3968 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3969 | auto trans = |
| 3970 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3971 | |
| 3972 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3973 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3974 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3975 | |
| 3976 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3977 | ASSERT_TRUE(response); |
| 3978 | ASSERT_TRUE(response->headers); |
| 3979 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
| 3980 | EXPECT_EQ(407, response->headers->response_code()); |
| 3981 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3982 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3983 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3984 | |
| 3985 | LoadTimingInfo load_timing_info; |
| 3986 | // CONNECT requests and responses are handled at the connect job level, so |
| 3987 | // the transaction does not yet have a connection. |
| 3988 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3989 | |
| 3990 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3991 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3992 | response = trans->GetResponseInfo(); |
| 3993 | ASSERT_TRUE(response); |
| 3994 | ASSERT_TRUE(response->headers); |
| 3995 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3996 | EXPECT_EQ(200, response->headers->response_code()); |
| 3997 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 3998 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3999 | |
| 4000 | // The password prompt info should not be set. |
| 4001 | EXPECT_FALSE(response->auth_challenge); |
| 4002 | |
| 4003 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4004 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4005 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4006 | |
| 4007 | trans.reset(); |
| 4008 | session->CloseAllConnections(); |
| 4009 | } |
| 4010 | |
| 4011 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4012 | // that hangs up when credentials are initially sent. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4013 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4014 | AuthAllowsDefaultCredentialsTunnelServerClosesConnection) { |
| 4015 | HttpRequestInfo request; |
| 4016 | request.method = "GET"; |
| 4017 | request.url = GURL("https://www.example.org/"); |
| 4018 | |
| 4019 | // Configure against proxy server "myproxy:70". |
| 4020 | session_deps_.proxy_service = |
| 4021 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 4022 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4023 | auto auth_handler_factory = base::MakeUnique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4024 | auth_handler_factory->set_do_init_from_challenge(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4025 | auto mock_handler = base::MakeUnique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4026 | mock_handler->set_allows_default_credentials(true); |
| 4027 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4028 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4029 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4030 | |
| 4031 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4032 | NetLog net_log; |
| 4033 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4034 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4035 | |
| 4036 | // Should try to establish tunnel. |
| 4037 | MockWrite data_writes1[] = { |
| 4038 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4039 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4040 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4041 | |
| 4042 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4043 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4044 | "Proxy-Connection: keep-alive\r\n" |
| 4045 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4046 | }; |
| 4047 | |
| 4048 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4049 | // connection. |
| 4050 | MockRead data_reads1[] = { |
| 4051 | // No credentials. |
| 4052 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4053 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4054 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4055 | }; |
| 4056 | |
| 4057 | // Since the first connection was closed, need to establish another once given |
| 4058 | // credentials. |
| 4059 | MockWrite data_writes2[] = { |
| 4060 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4061 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4062 | "Proxy-Connection: keep-alive\r\n" |
| 4063 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4064 | |
| 4065 | MockWrite("GET / HTTP/1.1\r\n" |
| 4066 | "Host: www.example.org\r\n" |
| 4067 | "Connection: keep-alive\r\n\r\n"), |
| 4068 | }; |
| 4069 | |
| 4070 | MockRead data_reads2[] = { |
| 4071 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 4072 | |
| 4073 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4074 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4075 | MockRead("Content-Length: 5\r\n\r\n"), |
| 4076 | MockRead(SYNCHRONOUS, "hello"), |
| 4077 | }; |
| 4078 | |
| 4079 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4080 | data_writes1, arraysize(data_writes1)); |
| 4081 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4082 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4083 | data_writes2, arraysize(data_writes2)); |
| 4084 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4085 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4086 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4087 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4088 | auto trans = |
| 4089 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4090 | |
| 4091 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4092 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4093 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4094 | |
| 4095 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4096 | ASSERT_TRUE(response); |
| 4097 | ASSERT_TRUE(response->headers); |
| 4098 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4099 | EXPECT_EQ(407, response->headers->response_code()); |
| 4100 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4101 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4102 | EXPECT_FALSE(response->auth_challenge); |
| 4103 | |
| 4104 | LoadTimingInfo load_timing_info; |
| 4105 | // CONNECT requests and responses are handled at the connect job level, so |
| 4106 | // the transaction does not yet have a connection. |
| 4107 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4108 | |
| 4109 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4110 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4111 | |
| 4112 | response = trans->GetResponseInfo(); |
| 4113 | ASSERT_TRUE(response); |
| 4114 | ASSERT_TRUE(response->headers); |
| 4115 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4116 | EXPECT_EQ(200, response->headers->response_code()); |
| 4117 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 4118 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4119 | |
| 4120 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4121 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4122 | |
| 4123 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4124 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4125 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4126 | |
| 4127 | trans.reset(); |
| 4128 | session->CloseAllConnections(); |
| 4129 | } |
| 4130 | |
| 4131 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4132 | // that hangs up when credentials are initially sent, and hangs up again when |
| 4133 | // they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4134 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4135 | AuthAllowsDefaultCredentialsTunnelServerClosesConnectionTwice) { |
| 4136 | HttpRequestInfo request; |
| 4137 | request.method = "GET"; |
| 4138 | request.url = GURL("https://www.example.org/"); |
| 4139 | |
| 4140 | // Configure against proxy server "myproxy:70". |
| 4141 | session_deps_.proxy_service = |
| 4142 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 4143 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4144 | auto auth_handler_factory = base::MakeUnique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4145 | auth_handler_factory->set_do_init_from_challenge(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4146 | auto mock_handler = base::MakeUnique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4147 | mock_handler->set_allows_default_credentials(true); |
| 4148 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4149 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4150 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4151 | |
| 4152 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4153 | NetLog net_log; |
| 4154 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4155 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4156 | |
| 4157 | // Should try to establish tunnel. |
| 4158 | MockWrite data_writes1[] = { |
| 4159 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4160 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4161 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4162 | |
| 4163 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4164 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4165 | "Proxy-Connection: keep-alive\r\n" |
| 4166 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4167 | }; |
| 4168 | |
| 4169 | // The proxy responds to the connect with a 407, and then hangs up after the |
| 4170 | // second request is sent. |
| 4171 | MockRead data_reads1[] = { |
| 4172 | // No credentials. |
| 4173 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4174 | MockRead("Content-Length: 0\r\n"), |
| 4175 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4176 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4177 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4178 | }; |
| 4179 | |
| 4180 | // HttpNetworkTransaction sees a reused connection that was closed with |
| 4181 | // ERR_CONNECTION_CLOSED, realized it might have been a race, so retries the |
| 4182 | // request. |
| 4183 | MockWrite data_writes2[] = { |
| 4184 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4185 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4186 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4187 | }; |
| 4188 | |
| 4189 | // The proxy, having had more than enough of us, just hangs up. |
| 4190 | MockRead data_reads2[] = { |
| 4191 | // No credentials. |
| 4192 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4193 | }; |
| 4194 | |
| 4195 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4196 | data_writes1, arraysize(data_writes1)); |
| 4197 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4198 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4199 | data_writes2, arraysize(data_writes2)); |
| 4200 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4201 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4202 | auto trans = |
| 4203 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4204 | |
| 4205 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4206 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4207 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4208 | |
| 4209 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4210 | ASSERT_TRUE(response); |
| 4211 | ASSERT_TRUE(response->headers); |
| 4212 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4213 | EXPECT_EQ(407, response->headers->response_code()); |
| 4214 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4215 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4216 | EXPECT_FALSE(response->auth_challenge); |
| 4217 | |
| 4218 | LoadTimingInfo load_timing_info; |
| 4219 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4220 | |
| 4221 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4222 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4223 | |
| 4224 | trans.reset(); |
| 4225 | session->CloseAllConnections(); |
| 4226 | } |
| 4227 | |
| 4228 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4229 | // that hangs up when credentials are initially sent, and sends a challenge |
| 4230 | // again they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4231 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4232 | AuthAllowsDefaultCredentialsTunnelServerChallengesTwice) { |
| 4233 | HttpRequestInfo request; |
| 4234 | request.method = "GET"; |
| 4235 | request.url = GURL("https://www.example.org/"); |
| 4236 | |
| 4237 | // Configure against proxy server "myproxy:70". |
| 4238 | session_deps_.proxy_service = |
| 4239 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 4240 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4241 | auto auth_handler_factory = base::MakeUnique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4242 | auth_handler_factory->set_do_init_from_challenge(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4243 | auto mock_handler = base::MakeUnique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4244 | mock_handler->set_allows_default_credentials(true); |
| 4245 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4246 | HttpAuth::AUTH_PROXY); |
| 4247 | // Add another handler for the second challenge. It supports default |
| 4248 | // credentials, but they shouldn't be used, since they were already tried. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4249 | mock_handler = base::MakeUnique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4250 | mock_handler->set_allows_default_credentials(true); |
| 4251 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4252 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4253 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4254 | |
| 4255 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4256 | NetLog net_log; |
| 4257 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4258 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4259 | |
| 4260 | // Should try to establish tunnel. |
| 4261 | MockWrite data_writes1[] = { |
| 4262 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4263 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4264 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4265 | }; |
| 4266 | |
| 4267 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4268 | // connection. |
| 4269 | MockRead data_reads1[] = { |
| 4270 | // No credentials. |
| 4271 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4272 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4273 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4274 | }; |
| 4275 | |
| 4276 | // Since the first connection was closed, need to establish another once given |
| 4277 | // credentials. |
| 4278 | MockWrite data_writes2[] = { |
| 4279 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4280 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4281 | "Proxy-Connection: keep-alive\r\n" |
| 4282 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4283 | }; |
| 4284 | |
| 4285 | MockRead data_reads2[] = { |
| 4286 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4287 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4288 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4289 | }; |
| 4290 | |
| 4291 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4292 | data_writes1, arraysize(data_writes1)); |
| 4293 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4294 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4295 | data_writes2, arraysize(data_writes2)); |
| 4296 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4297 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4298 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4299 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4300 | auto trans = |
| 4301 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4302 | |
| 4303 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4304 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4305 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4306 | |
| 4307 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4308 | ASSERT_TRUE(response); |
| 4309 | ASSERT_TRUE(response->headers); |
| 4310 | EXPECT_EQ(407, response->headers->response_code()); |
| 4311 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4312 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4313 | EXPECT_FALSE(response->auth_challenge); |
| 4314 | |
| 4315 | LoadTimingInfo load_timing_info; |
| 4316 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4317 | |
| 4318 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4319 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4320 | response = trans->GetResponseInfo(); |
| 4321 | ASSERT_TRUE(response); |
| 4322 | ASSERT_TRUE(response->headers); |
| 4323 | EXPECT_EQ(407, response->headers->response_code()); |
| 4324 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4325 | EXPECT_TRUE(response->auth_challenge); |
| 4326 | |
| 4327 | trans.reset(); |
| 4328 | session->CloseAllConnections(); |
| 4329 | } |
| 4330 | |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4331 | // A more nuanced test than GenerateAuthToken test which asserts that |
| 4332 | // ERR_INVALID_AUTH_CREDENTIALS does not cause the auth scheme to be |
| 4333 | // unnecessarily invalidated, and that if the server co-operates, the |
| 4334 | // authentication handshake can continue with the same scheme but with a |
| 4335 | // different identity. |
| 4336 | TEST_F(HttpNetworkTransactionTest, NonPermanentGenerateAuthTokenError) { |
| 4337 | HttpRequestInfo request; |
| 4338 | request.method = "GET"; |
| 4339 | request.url = GURL("http://www.example.org/"); |
| 4340 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4341 | auto auth_handler_factory = base::MakeUnique<HttpAuthHandlerMock::Factory>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4342 | auth_handler_factory->set_do_init_from_challenge(true); |
| 4343 | |
| 4344 | // First handler. Uses default credentials, but barfs at generate auth token. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4345 | auto mock_handler = base::MakeUnique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4346 | mock_handler->set_allows_default_credentials(true); |
| 4347 | mock_handler->set_allows_explicit_credentials(true); |
| 4348 | mock_handler->set_connection_based(true); |
| 4349 | mock_handler->SetGenerateExpectation(true, ERR_INVALID_AUTH_CREDENTIALS); |
| 4350 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4351 | HttpAuth::AUTH_SERVER); |
| 4352 | |
| 4353 | // Add another handler for the second challenge. It supports default |
| 4354 | // credentials, but they shouldn't be used, since they were already tried. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4355 | mock_handler = base::MakeUnique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4356 | mock_handler->set_allows_default_credentials(true); |
| 4357 | mock_handler->set_allows_explicit_credentials(true); |
| 4358 | mock_handler->set_connection_based(true); |
| 4359 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4360 | HttpAuth::AUTH_SERVER); |
| 4361 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
| 4362 | |
| 4363 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4364 | |
| 4365 | MockWrite data_writes1[] = { |
| 4366 | MockWrite("GET / HTTP/1.1\r\n" |
| 4367 | "Host: www.example.org\r\n" |
| 4368 | "Connection: keep-alive\r\n\r\n"), |
| 4369 | }; |
| 4370 | |
| 4371 | MockRead data_reads1[] = { |
| 4372 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4373 | "WWW-Authenticate: Mock\r\n" |
| 4374 | "Connection: keep-alive\r\n\r\n"), |
| 4375 | }; |
| 4376 | |
| 4377 | // Identical to data_writes1[]. The AuthHandler encounters a |
| 4378 | // ERR_INVALID_AUTH_CREDENTIALS during the GenerateAuthToken stage, so the |
| 4379 | // transaction procceds without an authorization header. |
| 4380 | MockWrite data_writes2[] = { |
| 4381 | MockWrite("GET / HTTP/1.1\r\n" |
| 4382 | "Host: www.example.org\r\n" |
| 4383 | "Connection: keep-alive\r\n\r\n"), |
| 4384 | }; |
| 4385 | |
| 4386 | MockRead data_reads2[] = { |
| 4387 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4388 | "WWW-Authenticate: Mock\r\n" |
| 4389 | "Connection: keep-alive\r\n\r\n"), |
| 4390 | }; |
| 4391 | |
| 4392 | MockWrite data_writes3[] = { |
| 4393 | MockWrite("GET / HTTP/1.1\r\n" |
| 4394 | "Host: www.example.org\r\n" |
| 4395 | "Connection: keep-alive\r\n" |
| 4396 | "Authorization: auth_token\r\n\r\n"), |
| 4397 | }; |
| 4398 | |
| 4399 | MockRead data_reads3[] = { |
| 4400 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4401 | "Content-Length: 5\r\n" |
| 4402 | "Content-Type: text/plain\r\n" |
| 4403 | "Connection: keep-alive\r\n\r\n" |
| 4404 | "Hello"), |
| 4405 | }; |
| 4406 | |
| 4407 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4408 | data_writes1, arraysize(data_writes1)); |
| 4409 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4410 | |
| 4411 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4412 | data_writes2, arraysize(data_writes2)); |
| 4413 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4414 | |
| 4415 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 4416 | data_writes3, arraysize(data_writes3)); |
| 4417 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 4418 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4419 | auto trans = |
| 4420 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4421 | |
| 4422 | TestCompletionCallback callback; |
| 4423 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 4424 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4425 | |
| 4426 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4427 | ASSERT_TRUE(response); |
| 4428 | ASSERT_TRUE(response->headers); |
| 4429 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4430 | |
| 4431 | // The following three tests assert that an authentication challenge was |
| 4432 | // received and that the stack is ready to respond to the challenge using |
| 4433 | // ambient credentials. |
| 4434 | EXPECT_EQ(401, response->headers->response_code()); |
| 4435 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4436 | EXPECT_FALSE(response->auth_challenge); |
| 4437 | |
| 4438 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4439 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4440 | response = trans->GetResponseInfo(); |
| 4441 | ASSERT_TRUE(response); |
| 4442 | ASSERT_TRUE(response->headers); |
| 4443 | |
| 4444 | // The following three tests assert that an authentication challenge was |
| 4445 | // received and that the stack needs explicit credentials before it is ready |
| 4446 | // to respond to the challenge. |
| 4447 | EXPECT_EQ(401, response->headers->response_code()); |
| 4448 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4449 | EXPECT_TRUE(response->auth_challenge); |
| 4450 | |
| 4451 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4452 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4453 | response = trans->GetResponseInfo(); |
| 4454 | ASSERT_TRUE(response); |
| 4455 | ASSERT_TRUE(response->headers); |
| 4456 | EXPECT_EQ(200, response->headers->response_code()); |
| 4457 | |
| 4458 | trans.reset(); |
| 4459 | session->CloseAllConnections(); |
| 4460 | } |
| 4461 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4462 | // Test the load timing for HTTPS requests with an HTTP proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4463 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingNoPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4464 | HttpRequestInfo request1; |
| 4465 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4466 | request1.url = GURL("https://www.example.org/1"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4467 | |
| 4468 | HttpRequestInfo request2; |
| 4469 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4470 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4471 | |
| 4472 | // Configure against proxy server "myproxy:70". |
brettw | c1213d9 | 2016-11-12 03:41:13 | [diff] [blame] | 4473 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4474 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4475 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4476 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4477 | |
| 4478 | // Since we have proxy, should try to establish tunnel. |
| 4479 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4480 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4481 | "Host: www.example.org:443\r\n" |
| 4482 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4483 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4484 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 4485 | "Host: www.example.org\r\n" |
| 4486 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4487 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4488 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 4489 | "Host: www.example.org\r\n" |
| 4490 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4491 | }; |
| 4492 | |
| 4493 | // The proxy responds to the connect with a 407, using a persistent |
| 4494 | // connection. |
| 4495 | MockRead data_reads1[] = { |
| 4496 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4497 | |
| 4498 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4499 | MockRead("Content-Length: 1\r\n\r\n"), |
| 4500 | MockRead(SYNCHRONOUS, "1"), |
| 4501 | |
| 4502 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4503 | MockRead("Content-Length: 2\r\n\r\n"), |
| 4504 | MockRead(SYNCHRONOUS, "22"), |
| 4505 | }; |
| 4506 | |
| 4507 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4508 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4509 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4510 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4511 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4512 | |
| 4513 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4514 | auto trans1 = |
| 4515 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4516 | |
| 4517 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4518 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4519 | |
| 4520 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4521 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4522 | |
| 4523 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4524 | ASSERT_TRUE(response1); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4525 | EXPECT_TRUE(response1->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4526 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4527 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 4528 | |
| 4529 | LoadTimingInfo load_timing_info1; |
| 4530 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 4531 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4532 | |
| 4533 | trans1.reset(); |
| 4534 | |
| 4535 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4536 | auto trans2 = |
| 4537 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4538 | |
| 4539 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4540 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4541 | |
| 4542 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4543 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4544 | |
| 4545 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4546 | ASSERT_TRUE(response2); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4547 | EXPECT_TRUE(response2->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4548 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4549 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 4550 | |
| 4551 | LoadTimingInfo load_timing_info2; |
| 4552 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4553 | TestLoadTimingReused(load_timing_info2); |
| 4554 | |
| 4555 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 4556 | |
| 4557 | trans2.reset(); |
| 4558 | session->CloseAllConnections(); |
| 4559 | } |
| 4560 | |
| 4561 | // 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] | 4562 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingWithPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4563 | HttpRequestInfo request1; |
| 4564 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4565 | request1.url = GURL("https://www.example.org/1"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4566 | |
| 4567 | HttpRequestInfo request2; |
| 4568 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4569 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4570 | |
| 4571 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4572 | session_deps_.proxy_service = |
| 4573 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4574 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4575 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4576 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4577 | |
| 4578 | // Since we have proxy, should try to establish tunnel. |
| 4579 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4580 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4581 | "Host: www.example.org:443\r\n" |
| 4582 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4583 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4584 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 4585 | "Host: www.example.org\r\n" |
| 4586 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4587 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4588 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 4589 | "Host: www.example.org\r\n" |
| 4590 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4591 | }; |
| 4592 | |
| 4593 | // The proxy responds to the connect with a 407, using a persistent |
| 4594 | // connection. |
| 4595 | MockRead data_reads1[] = { |
| 4596 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4597 | |
| 4598 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4599 | MockRead("Content-Length: 1\r\n\r\n"), |
| 4600 | MockRead(SYNCHRONOUS, "1"), |
| 4601 | |
| 4602 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4603 | MockRead("Content-Length: 2\r\n\r\n"), |
| 4604 | MockRead(SYNCHRONOUS, "22"), |
| 4605 | }; |
| 4606 | |
| 4607 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4608 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4609 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4610 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4611 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4612 | |
| 4613 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4614 | auto trans1 = |
| 4615 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4616 | |
| 4617 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4618 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4619 | |
| 4620 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4621 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4622 | |
| 4623 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4624 | ASSERT_TRUE(response1); |
| 4625 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4626 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 4627 | |
| 4628 | LoadTimingInfo load_timing_info1; |
| 4629 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 4630 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 4631 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4632 | |
| 4633 | trans1.reset(); |
| 4634 | |
| 4635 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4636 | auto trans2 = |
| 4637 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4638 | |
| 4639 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4640 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4641 | |
| 4642 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4643 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4644 | |
| 4645 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4646 | ASSERT_TRUE(response2); |
| 4647 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4648 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 4649 | |
| 4650 | LoadTimingInfo load_timing_info2; |
| 4651 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4652 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 4653 | |
| 4654 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 4655 | |
| 4656 | trans2.reset(); |
| 4657 | session->CloseAllConnections(); |
| 4658 | } |
| 4659 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4660 | // Test a simple get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4661 | TEST_F(HttpNetworkTransactionTest, HttpsProxyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4662 | HttpRequestInfo request; |
| 4663 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4664 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4665 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4666 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4667 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4668 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4669 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4670 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4671 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4672 | // Since we have proxy, should use full url |
| 4673 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4674 | MockWrite( |
| 4675 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 4676 | "Host: www.example.org\r\n" |
| 4677 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4678 | }; |
| 4679 | |
| 4680 | MockRead data_reads1[] = { |
| 4681 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4682 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4683 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4684 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4685 | }; |
| 4686 | |
| 4687 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4688 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4689 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4690 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4691 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4692 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4693 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4694 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4695 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4696 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4697 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4698 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4699 | |
| 4700 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4701 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4702 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4703 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4704 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4705 | TestLoadTimingNotReused(load_timing_info, |
| 4706 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4707 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4708 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4709 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4710 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4711 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4712 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4713 | EXPECT_EQ(200, response->headers->response_code()); |
| 4714 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 4715 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4716 | |
| 4717 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4718 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4719 | } |
| 4720 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4721 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4722 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4723 | HttpRequestInfo request; |
| 4724 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4725 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4726 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4727 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4728 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4729 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4730 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4731 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4732 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4733 | // fetch http://www.example.org/ via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4734 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 4735 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4736 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4737 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4738 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4739 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4740 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4741 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4742 | }; |
| 4743 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4744 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4745 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4746 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4747 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4748 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4749 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4750 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4751 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4752 | TestCompletionCallback callback1; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4753 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4754 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4755 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4756 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4757 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4758 | |
| 4759 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4760 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4761 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4762 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4763 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4764 | TestLoadTimingNotReused(load_timing_info, |
| 4765 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4766 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4767 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4768 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4769 | EXPECT_TRUE(response->proxy_server.is_https()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4770 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4771 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4772 | |
| 4773 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4774 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 4775 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4776 | } |
| 4777 | |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4778 | // Verifies that a session which races and wins against the owning transaction |
| 4779 | // (completing prior to host resolution), doesn't fail the transaction. |
| 4780 | // Regression test for crbug.com/334413. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4781 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithSessionRace) { |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4782 | HttpRequestInfo request; |
| 4783 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4784 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4785 | |
| 4786 | // Configure SPDY proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4787 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4788 | BoundTestNetLog log; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4789 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4790 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4791 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4792 | // Fetch http://www.example.org/ through the SPDY proxy. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4793 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 4794 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4795 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4796 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4797 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4798 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4799 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4800 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4801 | }; |
| 4802 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4803 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4804 | arraysize(spdy_writes)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4805 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 4806 | |
| 4807 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4808 | ssl.next_proto = kProtoHTTP2; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4809 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4810 | |
| 4811 | TestCompletionCallback callback1; |
| 4812 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4813 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4814 | |
| 4815 | // Stall the hostname resolution begun by the transaction. |
| 4816 | session_deps_.host_resolver->set_synchronous_mode(false); |
| 4817 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 4818 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4819 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4820 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4821 | |
| 4822 | // Race a session to the proxy, which completes first. |
| 4823 | session_deps_.host_resolver->set_ondemand_mode(false); |
| 4824 | SpdySessionKey key( |
| 4825 | HostPortPair("proxy", 70), ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
| 4826 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 4827 | CreateSpdySession(session.get(), key, log.bound()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4828 | |
| 4829 | // Unstall the resolution begun by the transaction. |
| 4830 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 4831 | session_deps_.host_resolver->ResolveAllPending(); |
| 4832 | |
| 4833 | EXPECT_FALSE(callback1.have_result()); |
| 4834 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4835 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4836 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4837 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4838 | ASSERT_TRUE(response); |
| 4839 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4840 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4841 | |
| 4842 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4843 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4844 | EXPECT_EQ(kUploadData, response_data); |
| 4845 | } |
| 4846 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4847 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4848 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4849 | HttpRequestInfo request; |
| 4850 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4851 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4852 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4853 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4854 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4855 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4856 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4857 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4858 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4859 | // The first request will be a bare GET, the second request will be a |
| 4860 | // GET with a Proxy-Authorization header. |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 4861 | spdy_util_.set_default_url(request.url); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4862 | SpdySerializedFrame req_get( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4863 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, false)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4864 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4865 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4866 | "proxy-authorization", "Basic Zm9vOmJhcg==" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4867 | }; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4868 | SpdySerializedFrame req_get_authorization(spdy_util_.ConstructSpdyGet( |
| 4869 | kExtraAuthorizationHeaders, arraysize(kExtraAuthorizationHeaders) / 2, 3, |
| 4870 | LOWEST, false)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4871 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4872 | CreateMockWrite(req_get, 0), CreateMockWrite(req_get_authorization, 3), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4873 | }; |
| 4874 | |
| 4875 | // The first response is a 407 proxy authentication challenge, and the second |
| 4876 | // response will be a 200 response since the second request includes a valid |
| 4877 | // Authorization header. |
| 4878 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4879 | "proxy-authenticate", "Basic realm=\"MyRealm1\"" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4880 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4881 | SpdySerializedFrame resp_authentication(spdy_util_.ConstructSpdyReplyError( |
bnc | c9f762a | 2016-12-06 20:38:23 | [diff] [blame] | 4882 | "407", kExtraAuthenticationHeaders, |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4883 | arraysize(kExtraAuthenticationHeaders) / 2, 1)); |
| 4884 | SpdySerializedFrame body_authentication( |
| 4885 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4886 | SpdySerializedFrame resp_data(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4887 | SpdySerializedFrame body_data(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4888 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4889 | CreateMockRead(resp_authentication, 1), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 4890 | CreateMockRead(body_authentication, 2, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4891 | CreateMockRead(resp_data, 4), |
| 4892 | CreateMockRead(body_data, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4893 | MockRead(ASYNC, 0, 6), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4894 | }; |
| 4895 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4896 | SequencedSocketData data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4897 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4898 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4899 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4900 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4901 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4902 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4903 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4904 | TestCompletionCallback callback1; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4905 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4906 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4907 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4908 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4909 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4910 | |
| 4911 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4912 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4913 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4914 | const HttpResponseInfo* const response = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4915 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4916 | ASSERT_TRUE(response); |
| 4917 | ASSERT_TRUE(response->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4918 | EXPECT_EQ(407, response->headers->response_code()); |
| 4919 | EXPECT_TRUE(response->was_fetched_via_spdy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 4920 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4921 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4922 | TestCompletionCallback callback2; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4923 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4924 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4925 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4926 | |
| 4927 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4928 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4929 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4930 | const HttpResponseInfo* const response_restart = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4931 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4932 | ASSERT_TRUE(response_restart); |
| 4933 | ASSERT_TRUE(response_restart->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4934 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 4935 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4936 | EXPECT_FALSE(response_restart->auth_challenge); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4937 | } |
| 4938 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4939 | // Test a SPDY CONNECT through an HTTPS Proxy to an HTTPS (non-SPDY) Server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4940 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4941 | HttpRequestInfo request; |
| 4942 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4943 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4944 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4945 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4946 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4947 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4948 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4949 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4950 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4951 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4952 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4953 | // CONNECT to www.example.org:443 via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4954 | SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4955 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 4956 | // fetch https://www.example.org/ via HTTP |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4957 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4958 | const char get[] = |
| 4959 | "GET / HTTP/1.1\r\n" |
| 4960 | "Host: www.example.org\r\n" |
| 4961 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4962 | SpdySerializedFrame wrapped_get( |
| 4963 | spdy_util_.ConstructSpdyDataFrame(1, get, strlen(get), false)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4964 | SpdySerializedFrame conn_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4965 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 4966 | "Content-Length: 10\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4967 | SpdySerializedFrame wrapped_get_resp( |
| 4968 | spdy_util_.ConstructSpdyDataFrame(1, resp, strlen(resp), false)); |
| 4969 | SpdySerializedFrame wrapped_body( |
| 4970 | spdy_util_.ConstructSpdyDataFrame(1, "1234567890", 10, false)); |
| 4971 | SpdySerializedFrame window_update( |
| 4972 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4973 | |
| 4974 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4975 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 4976 | CreateMockWrite(window_update, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4977 | }; |
| 4978 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4979 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4980 | CreateMockRead(conn_resp, 1, ASYNC), |
| 4981 | CreateMockRead(wrapped_get_resp, 3, ASYNC), |
| 4982 | CreateMockRead(wrapped_body, 4, ASYNC), |
| 4983 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4984 | MockRead(ASYNC, 0, 7), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4985 | }; |
| 4986 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4987 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4988 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4989 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4990 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4991 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4992 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4993 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4994 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4995 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4996 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4997 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4998 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4999 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5000 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5001 | |
| 5002 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5003 | ASSERT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5004 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5005 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5006 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5007 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5008 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5009 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5010 | ASSERT_TRUE(response); |
| 5011 | ASSERT_TRUE(response->headers); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5012 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5013 | |
| 5014 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5015 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5016 | EXPECT_EQ("1234567890", response_data); |
| 5017 | } |
| 5018 | |
| 5019 | // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5020 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) { |
| 5021 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5022 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5023 | HttpRequestInfo request; |
| 5024 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5025 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5026 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5027 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5028 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5029 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5030 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5031 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5032 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5033 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5034 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5035 | // CONNECT to www.example.org:443 via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5036 | SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5037 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 5038 | // fetch https://www.example.org/ via SPDY |
| 5039 | const char kMyUrl[] = "https://www.example.org/"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5040 | SpdySerializedFrame get( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 5041 | spdy_util_wrapped.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5042 | SpdySerializedFrame wrapped_get(spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5043 | SpdySerializedFrame conn_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5044 | SpdySerializedFrame get_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5045 | spdy_util_wrapped.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5046 | SpdySerializedFrame wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5047 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5048 | SpdySerializedFrame body(spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 5049 | SpdySerializedFrame wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5050 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5051 | SpdySerializedFrame window_update_get_resp( |
| 5052 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
| 5053 | SpdySerializedFrame window_update_body( |
| 5054 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5055 | |
| 5056 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5057 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 5058 | CreateMockWrite(window_update_get_resp, 6), |
| 5059 | CreateMockWrite(window_update_body, 7), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5060 | }; |
| 5061 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5062 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5063 | CreateMockRead(conn_resp, 1, ASYNC), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5064 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5065 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 5066 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5067 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5068 | }; |
| 5069 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5070 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5071 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5072 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5073 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5074 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5075 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5076 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5077 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5078 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5079 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5080 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5081 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5082 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5083 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5084 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5085 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5086 | // Allow the SpdyProxyClientSocket's write callback to complete. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 5087 | base::RunLoop().RunUntilIdle(); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5088 | // Now allow the read of the response to complete. |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 5089 | spdy_data.Resume(); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5090 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5091 | EXPECT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5092 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5093 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5094 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5095 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5096 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5097 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5098 | ASSERT_TRUE(response); |
| 5099 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5100 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5101 | |
| 5102 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5103 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5104 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5105 | } |
| 5106 | |
| 5107 | // Test a SPDY CONNECT failure through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5108 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5109 | HttpRequestInfo request; |
| 5110 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5111 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5112 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5113 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5114 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5115 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5116 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5117 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5118 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5119 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5120 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5121 | // CONNECT to www.example.org:443 via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5122 | SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5123 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5124 | SpdySerializedFrame get( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 5125 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5126 | |
| 5127 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5128 | CreateMockWrite(connect, 0), CreateMockWrite(get, 2), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5129 | }; |
| 5130 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5131 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError(1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5132 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5133 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5134 | CreateMockRead(resp, 1, ASYNC), MockRead(ASYNC, 0, 3), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5135 | }; |
| 5136 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5137 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5138 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5139 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5140 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5141 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5142 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5143 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5144 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5145 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5146 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5147 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5148 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5149 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5150 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5151 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5152 | |
| 5153 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5154 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5155 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 5156 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5157 | } |
| 5158 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5159 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 5160 | // HTTPS Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5161 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5162 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) { |
| 5163 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5164 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5165 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5166 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5167 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5168 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5169 | |
| 5170 | HttpRequestInfo request1; |
| 5171 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5172 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5173 | request1.load_flags = 0; |
| 5174 | |
| 5175 | HttpRequestInfo request2; |
| 5176 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5177 | request2.url = GURL("https://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5178 | request2.load_flags = 0; |
| 5179 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5180 | // CONNECT to www.example.org:443 via SPDY. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5181 | SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5182 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5183 | SpdySerializedFrame conn_resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5184 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5185 | // Fetch https://www.example.org/ via HTTP. |
| 5186 | const char get1[] = |
| 5187 | "GET / HTTP/1.1\r\n" |
| 5188 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5189 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5190 | SpdySerializedFrame wrapped_get1( |
| 5191 | spdy_util_.ConstructSpdyDataFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5192 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 5193 | "Content-Length: 1\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5194 | SpdySerializedFrame wrapped_get_resp1( |
| 5195 | spdy_util_.ConstructSpdyDataFrame(1, resp1, strlen(resp1), false)); |
| 5196 | SpdySerializedFrame wrapped_body1( |
| 5197 | spdy_util_.ConstructSpdyDataFrame(1, "1", 1, false)); |
| 5198 | SpdySerializedFrame window_update( |
| 5199 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5200 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5201 | // CONNECT to mail.example.org:443 via SPDY. |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 5202 | SpdyHeaderBlock connect2_block; |
| 5203 | connect2_block[spdy_util_.GetMethodKey()] = "CONNECT"; |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 5204 | connect2_block[spdy_util_.GetHostKey()] = "mail.example.org:443"; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5205 | SpdySerializedFrame connect2(spdy_util_.ConstructSpdyHeaders( |
| 5206 | 3, std::move(connect2_block), LOWEST, false)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 5207 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5208 | SpdySerializedFrame conn_resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5209 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5210 | // Fetch https://mail.example.org/ via HTTP. |
| 5211 | const char get2[] = |
| 5212 | "GET / HTTP/1.1\r\n" |
| 5213 | "Host: mail.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5214 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5215 | SpdySerializedFrame wrapped_get2( |
| 5216 | spdy_util_.ConstructSpdyDataFrame(3, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5217 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 5218 | "Content-Length: 2\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5219 | SpdySerializedFrame wrapped_get_resp2( |
| 5220 | spdy_util_.ConstructSpdyDataFrame(3, resp2, strlen(resp2), false)); |
| 5221 | SpdySerializedFrame wrapped_body2( |
| 5222 | spdy_util_.ConstructSpdyDataFrame(3, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5223 | |
| 5224 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5225 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 5226 | CreateMockWrite(connect2, 5), CreateMockWrite(wrapped_get2, 7), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5227 | }; |
| 5228 | |
| 5229 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5230 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 5231 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
| 5232 | CreateMockRead(wrapped_body1, 4, ASYNC), |
| 5233 | CreateMockRead(conn_resp2, 6, ASYNC), |
| 5234 | CreateMockRead(wrapped_get_resp2, 8, ASYNC), |
| 5235 | CreateMockRead(wrapped_body2, 9, ASYNC), |
| 5236 | MockRead(ASYNC, 0, 10), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5237 | }; |
| 5238 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5239 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5240 | arraysize(spdy_writes)); |
| 5241 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5242 | |
| 5243 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5244 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5245 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5246 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5247 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5248 | SSLSocketDataProvider ssl3(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5249 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5250 | |
| 5251 | TestCompletionCallback callback; |
| 5252 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5253 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5254 | int rv = trans.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5255 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5256 | |
| 5257 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5258 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5259 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5260 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5261 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5262 | ASSERT_TRUE(response); |
| 5263 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5264 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5265 | |
| 5266 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5267 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5268 | rv = trans.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5269 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5270 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5271 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5272 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5273 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5274 | |
| 5275 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5276 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5277 | // Even though the SPDY connection is reused, a new tunnelled connection has |
| 5278 | // to be created, so the socket's load timing looks like a fresh connection. |
| 5279 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5280 | |
| 5281 | // The requests should have different IDs, since they each are using their own |
| 5282 | // separate stream. |
| 5283 | EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5284 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5285 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5286 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5287 | } |
| 5288 | |
| 5289 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 5290 | // HTTPS Proxy to the same server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5291 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5292 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) { |
| 5293 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5294 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5295 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5296 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5297 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5298 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5299 | |
| 5300 | HttpRequestInfo request1; |
| 5301 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5302 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5303 | request1.load_flags = 0; |
| 5304 | |
| 5305 | HttpRequestInfo request2; |
| 5306 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5307 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5308 | request2.load_flags = 0; |
| 5309 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5310 | // CONNECT to www.example.org:443 via SPDY. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5311 | SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5312 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5313 | SpdySerializedFrame conn_resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5314 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5315 | // Fetch https://www.example.org/ via HTTP. |
| 5316 | const char get1[] = |
| 5317 | "GET / HTTP/1.1\r\n" |
| 5318 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5319 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5320 | SpdySerializedFrame wrapped_get1( |
| 5321 | spdy_util_.ConstructSpdyDataFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5322 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 5323 | "Content-Length: 1\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5324 | SpdySerializedFrame wrapped_get_resp1( |
| 5325 | spdy_util_.ConstructSpdyDataFrame(1, resp1, strlen(resp1), false)); |
| 5326 | SpdySerializedFrame wrapped_body1( |
| 5327 | spdy_util_.ConstructSpdyDataFrame(1, "1", 1, false)); |
| 5328 | SpdySerializedFrame window_update( |
| 5329 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5330 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5331 | // Fetch https://www.example.org/2 via HTTP. |
| 5332 | const char get2[] = |
| 5333 | "GET /2 HTTP/1.1\r\n" |
| 5334 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5335 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5336 | SpdySerializedFrame wrapped_get2( |
| 5337 | spdy_util_.ConstructSpdyDataFrame(1, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5338 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 5339 | "Content-Length: 2\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5340 | SpdySerializedFrame wrapped_get_resp2( |
| 5341 | spdy_util_.ConstructSpdyDataFrame(1, resp2, strlen(resp2), false)); |
| 5342 | SpdySerializedFrame wrapped_body2( |
| 5343 | spdy_util_.ConstructSpdyDataFrame(1, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5344 | |
| 5345 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5346 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 5347 | CreateMockWrite(wrapped_get2, 5), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5348 | }; |
| 5349 | |
| 5350 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5351 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 5352 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5353 | CreateMockRead(wrapped_body1, 4, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5354 | CreateMockRead(wrapped_get_resp2, 6, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5355 | CreateMockRead(wrapped_body2, 7, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5356 | MockRead(ASYNC, 0, 8), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5357 | }; |
| 5358 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5359 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5360 | arraysize(spdy_writes)); |
| 5361 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5362 | |
| 5363 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5364 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5365 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5366 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5367 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5368 | |
| 5369 | TestCompletionCallback callback; |
| 5370 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5371 | auto trans = |
| 5372 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5373 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5374 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5375 | |
| 5376 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5377 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5378 | |
| 5379 | LoadTimingInfo load_timing_info; |
| 5380 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5381 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5382 | |
| 5383 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5384 | ASSERT_TRUE(response); |
| 5385 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5386 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5387 | |
| 5388 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5389 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5390 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5391 | trans.reset(); |
| 5392 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5393 | auto trans2 = |
| 5394 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5395 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5396 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5397 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5398 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5399 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5400 | |
| 5401 | LoadTimingInfo load_timing_info2; |
| 5402 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 5403 | TestLoadTimingReused(load_timing_info2); |
| 5404 | |
| 5405 | // The requests should have the same ID. |
| 5406 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5407 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5408 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5409 | } |
| 5410 | |
| 5411 | // Test load timing in the case of of two HTTP requests through a SPDY HTTPS |
| 5412 | // Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5413 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyLoadTimingTwoHttpRequests) { |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5414 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5415 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5416 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5417 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5418 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5419 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5420 | |
| 5421 | HttpRequestInfo request1; |
| 5422 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5423 | request1.url = GURL("http://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5424 | request1.load_flags = 0; |
| 5425 | |
| 5426 | HttpRequestInfo request2; |
| 5427 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5428 | request2.url = GURL("http://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5429 | request2.load_flags = 0; |
| 5430 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5431 | // http://www.example.org/ |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 5432 | SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5433 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5434 | SpdySerializedFrame get1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5435 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
| 5436 | SpdySerializedFrame get_resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5437 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, "1", 1, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5438 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5439 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5440 | // http://mail.example.org/ |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 5441 | SpdyHeaderBlock headers2( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5442 | spdy_util_.ConstructGetHeaderBlockForProxy("http://mail.example.org/")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5443 | SpdySerializedFrame get2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5444 | spdy_util_.ConstructSpdyHeaders(3, std::move(headers2), LOWEST, true)); |
| 5445 | SpdySerializedFrame get_resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5446 | SpdySerializedFrame body2( |
| 5447 | spdy_util_.ConstructSpdyDataFrame(3, "22", 2, true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5448 | |
| 5449 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5450 | CreateMockWrite(get1, 0), CreateMockWrite(get2, 3), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5451 | }; |
| 5452 | |
| 5453 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5454 | CreateMockRead(get_resp1, 1, ASYNC), |
| 5455 | CreateMockRead(body1, 2, ASYNC), |
| 5456 | CreateMockRead(get_resp2, 4, ASYNC), |
| 5457 | CreateMockRead(body2, 5, ASYNC), |
| 5458 | MockRead(ASYNC, 0, 6), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5459 | }; |
| 5460 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5461 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5462 | arraysize(spdy_writes)); |
| 5463 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5464 | |
| 5465 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5466 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5467 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5468 | |
| 5469 | TestCompletionCallback callback; |
| 5470 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5471 | auto trans = |
| 5472 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5473 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5474 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5475 | |
| 5476 | LoadTimingInfo load_timing_info; |
| 5477 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5478 | TestLoadTimingNotReused(load_timing_info, |
| 5479 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5480 | |
| 5481 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5482 | ASSERT_TRUE(response); |
| 5483 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5484 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5485 | |
| 5486 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5487 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5488 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 5489 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5490 | // Delete the first request, so the second one can reuse the socket. |
| 5491 | trans.reset(); |
| 5492 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5493 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5494 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5495 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5496 | |
| 5497 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5498 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5499 | TestLoadTimingReused(load_timing_info2); |
| 5500 | |
| 5501 | // The requests should have the same ID. |
| 5502 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5503 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5504 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5505 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5506 | } |
| 5507 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5508 | // Test the challenge-response-retry sequence through an HTTPS Proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5509 | TEST_F(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5510 | HttpRequestInfo request; |
| 5511 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5512 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5513 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5514 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5515 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5516 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5517 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5518 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5519 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5520 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5521 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5522 | // Since we have proxy, should use full url |
| 5523 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5524 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 5525 | "Host: www.example.org\r\n" |
| 5526 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5527 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5528 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5529 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5530 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 5531 | "Host: www.example.org\r\n" |
| 5532 | "Proxy-Connection: keep-alive\r\n" |
| 5533 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5534 | }; |
| 5535 | |
| 5536 | // The proxy responds to the GET with a 407, using a persistent |
| 5537 | // connection. |
| 5538 | MockRead data_reads1[] = { |
| 5539 | // No credentials. |
| 5540 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 5541 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5542 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 5543 | MockRead("Content-Length: 0\r\n\r\n"), |
| 5544 | |
| 5545 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5546 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5547 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5548 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5549 | }; |
| 5550 | |
| 5551 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5552 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5553 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5554 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5555 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5556 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5557 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5558 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5559 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5560 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5561 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5562 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5563 | |
| 5564 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5565 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5566 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5567 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5568 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5569 | TestLoadTimingNotReused(load_timing_info, |
| 5570 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5571 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5572 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5573 | ASSERT_TRUE(response); |
| 5574 | ASSERT_TRUE(response->headers); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5575 | EXPECT_EQ(407, response->headers->response_code()); |
| 5576 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 5577 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5578 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5579 | TestCompletionCallback callback2; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5580 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5581 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5582 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5583 | |
| 5584 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5585 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5586 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5587 | load_timing_info = LoadTimingInfo(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5588 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5589 | // Retrying with HTTP AUTH is considered to be reusing a socket. |
| 5590 | TestLoadTimingReused(load_timing_info); |
| 5591 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5592 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5593 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5594 | |
| 5595 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 5596 | EXPECT_EQ(200, response->headers->response_code()); |
| 5597 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5598 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5599 | |
| 5600 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5601 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5602 | } |
| 5603 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5604 | void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5605 | const MockRead& status, int expected_status) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5606 | HttpRequestInfo request; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5607 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5608 | request.url = GURL("https://www.example.org/"); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5609 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5610 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5611 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5612 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5613 | |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5614 | // Since we have proxy, should try to establish tunnel. |
| 5615 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5616 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5617 | "Host: www.example.org:443\r\n" |
| 5618 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5619 | }; |
| 5620 | |
| 5621 | MockRead data_reads[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 5622 | status, MockRead("Content-Length: 10\r\n\r\n"), |
| 5623 | // No response body because the test stops reading here. |
| 5624 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5625 | }; |
| 5626 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5627 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 5628 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5629 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5630 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5631 | TestCompletionCallback callback; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5632 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5633 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5634 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5635 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5636 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5637 | |
| 5638 | rv = callback.WaitForResult(); |
| 5639 | EXPECT_EQ(expected_status, rv); |
| 5640 | } |
| 5641 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5642 | void HttpNetworkTransactionTest::ConnectStatusHelper( |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5643 | const MockRead& status) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5644 | ConnectStatusHelperWithExpectedStatus( |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5645 | status, ERR_TUNNEL_CONNECTION_FAILED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5646 | } |
| 5647 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5648 | TEST_F(HttpNetworkTransactionTest, ConnectStatus100) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5649 | ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n")); |
| 5650 | } |
| 5651 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5652 | TEST_F(HttpNetworkTransactionTest, ConnectStatus101) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5653 | ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n")); |
| 5654 | } |
| 5655 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5656 | TEST_F(HttpNetworkTransactionTest, ConnectStatus201) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5657 | ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n")); |
| 5658 | } |
| 5659 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5660 | TEST_F(HttpNetworkTransactionTest, ConnectStatus202) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5661 | ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n")); |
| 5662 | } |
| 5663 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5664 | TEST_F(HttpNetworkTransactionTest, ConnectStatus203) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5665 | ConnectStatusHelper( |
| 5666 | MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n")); |
| 5667 | } |
| 5668 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5669 | TEST_F(HttpNetworkTransactionTest, ConnectStatus204) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5670 | ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n")); |
| 5671 | } |
| 5672 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5673 | TEST_F(HttpNetworkTransactionTest, ConnectStatus205) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5674 | ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n")); |
| 5675 | } |
| 5676 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5677 | TEST_F(HttpNetworkTransactionTest, ConnectStatus206) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5678 | ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n")); |
| 5679 | } |
| 5680 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5681 | TEST_F(HttpNetworkTransactionTest, ConnectStatus300) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5682 | ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n")); |
| 5683 | } |
| 5684 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5685 | TEST_F(HttpNetworkTransactionTest, ConnectStatus301) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5686 | ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n")); |
| 5687 | } |
| 5688 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5689 | TEST_F(HttpNetworkTransactionTest, ConnectStatus302) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5690 | ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n")); |
| 5691 | } |
| 5692 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5693 | TEST_F(HttpNetworkTransactionTest, ConnectStatus303) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5694 | ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n")); |
| 5695 | } |
| 5696 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5697 | TEST_F(HttpNetworkTransactionTest, ConnectStatus304) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5698 | ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n")); |
| 5699 | } |
| 5700 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5701 | TEST_F(HttpNetworkTransactionTest, ConnectStatus305) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5702 | ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n")); |
| 5703 | } |
| 5704 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5705 | TEST_F(HttpNetworkTransactionTest, ConnectStatus306) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5706 | ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n")); |
| 5707 | } |
| 5708 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5709 | TEST_F(HttpNetworkTransactionTest, ConnectStatus307) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5710 | ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n")); |
| 5711 | } |
| 5712 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5713 | TEST_F(HttpNetworkTransactionTest, ConnectStatus308) { |
[email protected] | 0a17aab3 | 2014-04-24 03:32:37 | [diff] [blame] | 5714 | ConnectStatusHelper(MockRead("HTTP/1.1 308 Permanent Redirect\r\n")); |
| 5715 | } |
| 5716 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5717 | TEST_F(HttpNetworkTransactionTest, ConnectStatus400) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5718 | ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n")); |
| 5719 | } |
| 5720 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5721 | TEST_F(HttpNetworkTransactionTest, ConnectStatus401) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5722 | ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n")); |
| 5723 | } |
| 5724 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5725 | TEST_F(HttpNetworkTransactionTest, ConnectStatus402) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5726 | ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n")); |
| 5727 | } |
| 5728 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5729 | TEST_F(HttpNetworkTransactionTest, ConnectStatus403) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5730 | ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n")); |
| 5731 | } |
| 5732 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5733 | TEST_F(HttpNetworkTransactionTest, ConnectStatus404) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5734 | ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n")); |
| 5735 | } |
| 5736 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5737 | TEST_F(HttpNetworkTransactionTest, ConnectStatus405) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5738 | ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n")); |
| 5739 | } |
| 5740 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5741 | TEST_F(HttpNetworkTransactionTest, ConnectStatus406) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5742 | ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n")); |
| 5743 | } |
| 5744 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5745 | TEST_F(HttpNetworkTransactionTest, ConnectStatus407) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5746 | ConnectStatusHelperWithExpectedStatus( |
| 5747 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
[email protected] | a7ea883 | 2010-07-12 17:54:54 | [diff] [blame] | 5748 | ERR_PROXY_AUTH_UNSUPPORTED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5749 | } |
| 5750 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5751 | TEST_F(HttpNetworkTransactionTest, ConnectStatus408) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5752 | ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n")); |
| 5753 | } |
| 5754 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5755 | TEST_F(HttpNetworkTransactionTest, ConnectStatus409) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5756 | ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n")); |
| 5757 | } |
| 5758 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5759 | TEST_F(HttpNetworkTransactionTest, ConnectStatus410) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5760 | ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n")); |
| 5761 | } |
| 5762 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5763 | TEST_F(HttpNetworkTransactionTest, ConnectStatus411) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5764 | ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n")); |
| 5765 | } |
| 5766 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5767 | TEST_F(HttpNetworkTransactionTest, ConnectStatus412) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5768 | ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n")); |
| 5769 | } |
| 5770 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5771 | TEST_F(HttpNetworkTransactionTest, ConnectStatus413) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5772 | ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n")); |
| 5773 | } |
| 5774 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5775 | TEST_F(HttpNetworkTransactionTest, ConnectStatus414) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5776 | ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n")); |
| 5777 | } |
| 5778 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5779 | TEST_F(HttpNetworkTransactionTest, ConnectStatus415) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5780 | ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n")); |
| 5781 | } |
| 5782 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5783 | TEST_F(HttpNetworkTransactionTest, ConnectStatus416) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5784 | ConnectStatusHelper( |
| 5785 | MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n")); |
| 5786 | } |
| 5787 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5788 | TEST_F(HttpNetworkTransactionTest, ConnectStatus417) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5789 | ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n")); |
| 5790 | } |
| 5791 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5792 | TEST_F(HttpNetworkTransactionTest, ConnectStatus500) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5793 | ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n")); |
| 5794 | } |
| 5795 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5796 | TEST_F(HttpNetworkTransactionTest, ConnectStatus501) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5797 | ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n")); |
| 5798 | } |
| 5799 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5800 | TEST_F(HttpNetworkTransactionTest, ConnectStatus502) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5801 | ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n")); |
| 5802 | } |
| 5803 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5804 | TEST_F(HttpNetworkTransactionTest, ConnectStatus503) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5805 | ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n")); |
| 5806 | } |
| 5807 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5808 | TEST_F(HttpNetworkTransactionTest, ConnectStatus504) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5809 | ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n")); |
| 5810 | } |
| 5811 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5812 | TEST_F(HttpNetworkTransactionTest, ConnectStatus505) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5813 | ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); |
| 5814 | } |
| 5815 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5816 | // Test the flow when both the proxy server AND origin server require |
| 5817 | // authentication. Again, this uses basic auth for both since that is |
| 5818 | // the simplest to mock. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5819 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5820 | HttpRequestInfo request; |
| 5821 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5822 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5823 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5824 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5825 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5826 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 5827 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5828 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5829 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5830 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5831 | MockWrite( |
| 5832 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5833 | "Host: www.example.org\r\n" |
| 5834 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5835 | }; |
| 5836 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5837 | MockRead data_reads1[] = { |
| 5838 | MockRead("HTTP/1.0 407 Unauthorized\r\n"), |
| 5839 | // Give a couple authenticate options (only the middle one is actually |
| 5840 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 5841 | MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5842 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5843 | MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 5844 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5845 | // Large content-length -- won't matter, as connection will be reset. |
| 5846 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5847 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5848 | }; |
| 5849 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5850 | // After calling trans.RestartWithAuth() the first time, this is the |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5851 | // request we should be issuing -- the final header line contains the |
| 5852 | // proxy's credentials. |
| 5853 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5854 | MockWrite( |
| 5855 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5856 | "Host: www.example.org\r\n" |
| 5857 | "Proxy-Connection: keep-alive\r\n" |
| 5858 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5859 | }; |
| 5860 | |
| 5861 | // Now the proxy server lets the request pass through to origin server. |
| 5862 | // The origin server responds with a 401. |
| 5863 | MockRead data_reads2[] = { |
| 5864 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5865 | // Note: We are using the same realm-name as the proxy server. This is |
| 5866 | // completely valid, as realms are unique across hosts. |
| 5867 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5868 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5869 | MockRead("Content-Length: 2000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5870 | MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5871 | }; |
| 5872 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5873 | // After calling trans.RestartWithAuth() the second time, we should send |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5874 | // the credentials for both the proxy and origin server. |
| 5875 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5876 | MockWrite( |
| 5877 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5878 | "Host: www.example.org\r\n" |
| 5879 | "Proxy-Connection: keep-alive\r\n" |
| 5880 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 5881 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5882 | }; |
| 5883 | |
| 5884 | // Lastly we get the desired content. |
| 5885 | MockRead data_reads3[] = { |
| 5886 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5887 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5888 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5889 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5890 | }; |
| 5891 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5892 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5893 | data_writes1, arraysize(data_writes1)); |
| 5894 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5895 | data_writes2, arraysize(data_writes2)); |
| 5896 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 5897 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5898 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5899 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 5900 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5901 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5902 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5903 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5904 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5905 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5906 | |
| 5907 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5908 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5909 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5910 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5911 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5912 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5913 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5914 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5915 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5916 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5917 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5918 | |
| 5919 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5920 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5921 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5922 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5923 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5924 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5925 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5926 | TestCompletionCallback callback3; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5927 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5928 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 5929 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5930 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5931 | |
| 5932 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5933 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5934 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5935 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5936 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5937 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5938 | } |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5939 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 5940 | // For the NTLM implementation using SSPI, we skip the NTLM tests since we |
| 5941 | // can't hook into its internals to cause it to generate predictable NTLM |
| 5942 | // authorization headers. |
| 5943 | #if defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5944 | // The NTLM authentication unit tests were generated by capturing the HTTP |
| 5945 | // requests and responses using Fiddler 2 and inspecting the generated random |
| 5946 | // bytes in the debugger. |
| 5947 | |
| 5948 | // Enter the correct password and authenticate successfully. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5949 | TEST_F(HttpNetworkTransactionTest, NTLMAuth1) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5950 | HttpRequestInfo request; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5951 | request.method = "GET"; |
| 5952 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5953 | |
| 5954 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 5955 | // to other auth schemes. |
| 5956 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5957 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5958 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom1, |
| 5959 | MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5960 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5961 | |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5962 | MockWrite data_writes1[] = { |
| 5963 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5964 | "Host: 172.22.68.17\r\n" |
| 5965 | "Connection: keep-alive\r\n\r\n"), |
| 5966 | }; |
| 5967 | |
| 5968 | MockRead data_reads1[] = { |
| 5969 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 5970 | // Negotiate and NTLM are often requested together. However, we only want |
| 5971 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 5972 | // the header that requests Negotiate for this test. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5973 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 5974 | MockRead("Connection: close\r\n"), |
| 5975 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5976 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5977 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5978 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5979 | }; |
| 5980 | |
| 5981 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5982 | // After restarting with a null identity, this is the |
| 5983 | // request we should be issuing -- the final header line contains a Type |
| 5984 | // 1 message. |
| 5985 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5986 | "Host: 172.22.68.17\r\n" |
| 5987 | "Connection: keep-alive\r\n" |
| 5988 | "Authorization: NTLM " |
| 5989 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5990 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5991 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 5992 | // (the credentials for the origin server). The second request continues |
| 5993 | // on the same connection. |
| 5994 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5995 | "Host: 172.22.68.17\r\n" |
| 5996 | "Connection: keep-alive\r\n" |
| 5997 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 5998 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 5999 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBVKW" |
| 6000 | "Yma5xzVAAAAAAAAAAAAAAAAAAAAACH+gWcm+YsP9Tqb9zCR3WAeZZX" |
| 6001 | "ahlhx5I=\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6002 | }; |
| 6003 | |
| 6004 | MockRead data_reads2[] = { |
| 6005 | // The origin server responds with a Type 2 message. |
| 6006 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 6007 | MockRead("WWW-Authenticate: NTLM " |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6008 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCjGpMpPGlYKkAAAAAAAAAALo" |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6009 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 6010 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 6011 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 6012 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 6013 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 6014 | "BtAAAAAAA=\r\n"), |
| 6015 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6016 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6017 | MockRead("You are not authorized to view this page\r\n"), |
| 6018 | |
| 6019 | // Lastly we get the desired content. |
| 6020 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6021 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 6022 | MockRead("Content-Length: 13\r\n\r\n"), |
| 6023 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6024 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6025 | }; |
| 6026 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6027 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6028 | data_writes1, arraysize(data_writes1)); |
| 6029 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6030 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6031 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6032 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6033 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6034 | TestCompletionCallback callback1; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6035 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6036 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6037 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6038 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6039 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6040 | |
| 6041 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6042 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6043 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6044 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6045 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6046 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6047 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6048 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6049 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6050 | TestCompletionCallback callback2; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6051 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6052 | rv = trans.RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
| 6053 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6054 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6055 | |
| 6056 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6057 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6058 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6059 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6060 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6061 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6062 | ASSERT_TRUE(response); |
| 6063 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6064 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6065 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6066 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6067 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6068 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6069 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6070 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6071 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6072 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6073 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6074 | ASSERT_TRUE(response); |
| 6075 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6076 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 6077 | } |
| 6078 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6079 | // Enter a wrong password, and then the correct one. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6080 | TEST_F(HttpNetworkTransactionTest, NTLMAuth2) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6081 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6082 | request.method = "GET"; |
| 6083 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6084 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6085 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom2, |
| 6086 | MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6087 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6088 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6089 | MockWrite data_writes1[] = { |
| 6090 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6091 | "Host: 172.22.68.17\r\n" |
| 6092 | "Connection: keep-alive\r\n\r\n"), |
| 6093 | }; |
| 6094 | |
| 6095 | MockRead data_reads1[] = { |
| 6096 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 6097 | // Negotiate and NTLM are often requested together. However, we only want |
| 6098 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 6099 | // the header that requests Negotiate for this test. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6100 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 6101 | MockRead("Connection: close\r\n"), |
| 6102 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6103 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6104 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6105 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6106 | }; |
| 6107 | |
| 6108 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6109 | // After restarting with a null identity, this is the |
| 6110 | // request we should be issuing -- the final header line contains a Type |
| 6111 | // 1 message. |
| 6112 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6113 | "Host: 172.22.68.17\r\n" |
| 6114 | "Connection: keep-alive\r\n" |
| 6115 | "Authorization: NTLM " |
| 6116 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6117 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6118 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 6119 | // (the credentials for the origin server). The second request continues |
| 6120 | // on the same connection. |
| 6121 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6122 | "Host: 172.22.68.17\r\n" |
| 6123 | "Connection: keep-alive\r\n" |
| 6124 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 6125 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 6126 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwCWeY" |
| 6127 | "XnSZNwoQAAAAAAAAAAAAAAAAAAAADLa34/phTTKzNTWdub+uyFleOj" |
| 6128 | "4Ww7b7E=\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6129 | }; |
| 6130 | |
| 6131 | MockRead data_reads2[] = { |
| 6132 | // The origin server responds with a Type 2 message. |
| 6133 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 6134 | MockRead("WWW-Authenticate: NTLM " |
| 6135 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCbVWUZezVGpAAAAAAAAAAALo" |
| 6136 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 6137 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 6138 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 6139 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 6140 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 6141 | "BtAAAAAAA=\r\n"), |
| 6142 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6143 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6144 | MockRead("You are not authorized to view this page\r\n"), |
| 6145 | |
| 6146 | // Wrong password. |
| 6147 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6148 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 6149 | MockRead("Connection: close\r\n"), |
| 6150 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6151 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6152 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6153 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6154 | }; |
| 6155 | |
| 6156 | MockWrite data_writes3[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6157 | // After restarting with a null identity, this is the |
| 6158 | // request we should be issuing -- the final header line contains a Type |
| 6159 | // 1 message. |
| 6160 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6161 | "Host: 172.22.68.17\r\n" |
| 6162 | "Connection: keep-alive\r\n" |
| 6163 | "Authorization: NTLM " |
| 6164 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6165 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6166 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 6167 | // (the credentials for the origin server). The second request continues |
| 6168 | // on the same connection. |
| 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" |
| 6172 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 6173 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 6174 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBO54" |
| 6175 | "dFMVvTHwAAAAAAAAAAAAAAAAAAAACS7sT6Uzw7L0L//WUqlIaVWpbI" |
| 6176 | "+4MUm7c=\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6177 | }; |
| 6178 | |
| 6179 | MockRead data_reads3[] = { |
| 6180 | // The origin server responds with a Type 2 message. |
| 6181 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 6182 | MockRead("WWW-Authenticate: NTLM " |
| 6183 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCL24VN8dgOR8AAAAAAAAAALo" |
| 6184 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 6185 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 6186 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 6187 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 6188 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 6189 | "BtAAAAAAA=\r\n"), |
| 6190 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6191 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6192 | MockRead("You are not authorized to view this page\r\n"), |
| 6193 | |
| 6194 | // Lastly we get the desired content. |
| 6195 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6196 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 6197 | MockRead("Content-Length: 13\r\n\r\n"), |
| 6198 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6199 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6200 | }; |
| 6201 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6202 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6203 | data_writes1, arraysize(data_writes1)); |
| 6204 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6205 | data_writes2, arraysize(data_writes2)); |
| 6206 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6207 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6208 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6209 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6210 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6211 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6212 | TestCompletionCallback callback1; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6213 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6214 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6215 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6216 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6217 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6218 | |
| 6219 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6220 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6221 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6222 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6223 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6224 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6225 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6226 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6227 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6228 | TestCompletionCallback callback2; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6229 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6230 | // Enter the wrong password. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6231 | rv = trans.RestartWithAuth(AuthCredentials(kTestingNTLM, kWrongPassword), |
| 6232 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6233 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6234 | |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6235 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6236 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6237 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6238 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6239 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6240 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6241 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6242 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6243 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6244 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6245 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6246 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6247 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6248 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6249 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6250 | TestCompletionCallback callback4; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6251 | |
| 6252 | // Now enter the right password. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6253 | rv = trans.RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
| 6254 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6255 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6256 | |
| 6257 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6258 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6259 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6260 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6261 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6262 | TestCompletionCallback callback5; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6263 | |
| 6264 | // One more roundtrip |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6265 | rv = trans.RestartWithAuth(AuthCredentials(), callback5.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6266 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6267 | |
| 6268 | rv = callback5.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6269 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6270 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6271 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6272 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6273 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 6274 | } |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6275 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6276 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6277 | // Test reading a server response which has only headers, and no body. |
| 6278 | // After some maximum number of bytes is consumed, the transaction should |
| 6279 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6280 | TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6281 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6282 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6283 | request.url = GURL("http://www.example.org/"); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6284 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6285 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6286 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6287 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 6288 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 6289 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 6290 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6291 | |
| 6292 | MockRead data_reads[] = { |
| 6293 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6294 | MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6295 | MockRead("\r\nBODY"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6296 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6297 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6298 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6299 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6300 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6301 | TestCompletionCallback callback; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6302 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6303 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6304 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6305 | |
| 6306 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6307 | EXPECT_THAT(rv, IsError(ERR_RESPONSE_HEADERS_TOO_BIG)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6308 | } |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6309 | |
| 6310 | // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 6311 | // establish tunnel. |
| 6312 | // http://code.google.com/p/chromium/issues/detail?id=3772 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6313 | TEST_F(HttpNetworkTransactionTest, DontRecycleTransportSocketForSSLTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6314 | HttpRequestInfo request; |
| 6315 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6316 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6317 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6318 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 6319 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 6320 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6321 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6322 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6323 | auto trans = |
| 6324 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6325 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6326 | // Since we have proxy, should try to establish tunnel. |
| 6327 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 6328 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6329 | "Host: www.example.org:443\r\n" |
| 6330 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6331 | }; |
| 6332 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 6333 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6334 | // connection. Usually a proxy would return 501 (not implemented), |
| 6335 | // or 200 (tunnel established). |
| 6336 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 6337 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 6338 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6339 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6340 | }; |
| 6341 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6342 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6343 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6344 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6345 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6346 | TestCompletionCallback callback1; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6347 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6348 | int rv = trans->Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6349 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6350 | |
| 6351 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6352 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6353 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6354 | // Empty the current queue. This is necessary because idle sockets are |
| 6355 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6356 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6357 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6358 | // We now check to make sure the TCPClientSocket was not added back to |
| 6359 | // the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6360 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6361 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6362 | base::RunLoop().RunUntilIdle(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6363 | // Make sure that the socket didn't get recycled after calling the destructor. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6364 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6365 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6366 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6367 | // Make sure that we recycle a socket after reading all of the response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6368 | TEST_F(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6369 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6370 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6371 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6372 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6373 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6374 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6375 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6376 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6377 | MockRead data_reads[] = { |
| 6378 | // A part of the response body is received with the response headers. |
| 6379 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 6380 | // The rest of the response body is received in two parts. |
| 6381 | MockRead("lo"), |
| 6382 | MockRead(" world"), |
| 6383 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6384 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6385 | }; |
| 6386 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6387 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6388 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6389 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6390 | TestCompletionCallback callback; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6391 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6392 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6393 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6394 | |
| 6395 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6396 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6397 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6398 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6399 | ASSERT_TRUE(response); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6400 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6401 | EXPECT_TRUE(response->headers); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6402 | std::string status_line = response->headers->GetStatusLine(); |
| 6403 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 6404 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6405 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6406 | |
| 6407 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6408 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6409 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6410 | EXPECT_EQ("hello world", response_data); |
| 6411 | |
| 6412 | // Empty the current queue. This is necessary because idle sockets are |
| 6413 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6414 | base::RunLoop().RunUntilIdle(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6415 | |
| 6416 | // 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] | 6417 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6418 | } |
| 6419 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6420 | // Make sure that we recycle a SSL socket after reading all of the response |
| 6421 | // body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6422 | TEST_F(HttpNetworkTransactionTest, RecycleSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6423 | HttpRequestInfo request; |
| 6424 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6425 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6426 | |
| 6427 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6428 | MockWrite( |
| 6429 | "GET / HTTP/1.1\r\n" |
| 6430 | "Host: www.example.org\r\n" |
| 6431 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6432 | }; |
| 6433 | |
| 6434 | MockRead data_reads[] = { |
| 6435 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6436 | MockRead("Content-Length: 11\r\n\r\n"), |
| 6437 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6438 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6439 | }; |
| 6440 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6441 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6442 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6443 | |
| 6444 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6445 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6446 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6447 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6448 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6449 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6450 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6451 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6452 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6453 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6454 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6455 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6456 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6457 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6458 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6459 | ASSERT_TRUE(response); |
| 6460 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6461 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6462 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6463 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6464 | |
| 6465 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6466 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6467 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6468 | EXPECT_EQ("hello world", response_data); |
| 6469 | |
| 6470 | // Empty the current queue. This is necessary because idle sockets are |
| 6471 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6472 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6473 | |
| 6474 | // 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] | 6475 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6476 | } |
| 6477 | |
| 6478 | // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it |
| 6479 | // from the pool and make sure that we recover okay. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6480 | TEST_F(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6481 | HttpRequestInfo request; |
| 6482 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6483 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6484 | |
| 6485 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6486 | MockWrite( |
| 6487 | "GET / HTTP/1.1\r\n" |
| 6488 | "Host: www.example.org\r\n" |
| 6489 | "Connection: keep-alive\r\n\r\n"), |
| 6490 | MockWrite( |
| 6491 | "GET / HTTP/1.1\r\n" |
| 6492 | "Host: www.example.org\r\n" |
| 6493 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6494 | }; |
| 6495 | |
| 6496 | MockRead data_reads[] = { |
mmenke | 911ee022 | 2015-12-04 03:58:42 | [diff] [blame] | 6497 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 6498 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6499 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6500 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6501 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6502 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6503 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6504 | |
| 6505 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6506 | data_writes, arraysize(data_writes)); |
| 6507 | StaticSocketDataProvider data2(data_reads, arraysize(data_reads), |
| 6508 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6509 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6510 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6511 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6512 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6513 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6514 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6515 | auto trans = |
| 6516 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6517 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6518 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6519 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6520 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6521 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6522 | |
| 6523 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6524 | ASSERT_TRUE(response); |
| 6525 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6526 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6527 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6528 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6529 | |
| 6530 | std::string response_data; |
| 6531 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6532 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6533 | EXPECT_EQ("hello world", response_data); |
| 6534 | |
| 6535 | // Empty the current queue. This is necessary because idle sockets are |
| 6536 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6537 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6538 | |
| 6539 | // 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] | 6540 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6541 | |
| 6542 | // Now start the second transaction, which should reuse the previous socket. |
| 6543 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6544 | trans = |
| 6545 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6546 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6547 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6548 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6549 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6550 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6551 | |
| 6552 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6553 | ASSERT_TRUE(response); |
| 6554 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6555 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6556 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6557 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6558 | |
| 6559 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6560 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6561 | EXPECT_EQ("hello world", response_data); |
| 6562 | |
| 6563 | // Empty the current queue. This is necessary because idle sockets are |
| 6564 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6565 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6566 | |
| 6567 | // 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] | 6568 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6569 | } |
| 6570 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6571 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 6572 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6573 | TEST_F(HttpNetworkTransactionTest, FlushSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6574 | HttpRequestInfo request; |
| 6575 | request.method = "GET"; |
| 6576 | request.url = GURL("http://www.example.org/"); |
| 6577 | request.load_flags = 0; |
| 6578 | |
| 6579 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6580 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6581 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6582 | |
| 6583 | MockRead data_reads[] = { |
| 6584 | // A part of the response body is received with the response headers. |
| 6585 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 6586 | // The rest of the response body is received in two parts. |
| 6587 | MockRead("lo"), MockRead(" world"), |
| 6588 | MockRead("junk"), // Should not be read!! |
| 6589 | MockRead(SYNCHRONOUS, OK), |
| 6590 | }; |
| 6591 | |
| 6592 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 6593 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6594 | |
| 6595 | TestCompletionCallback callback; |
| 6596 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6597 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6598 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6599 | |
| 6600 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6601 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6602 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6603 | ASSERT_TRUE(response); |
| 6604 | EXPECT_TRUE(response->headers); |
| 6605 | std::string status_line = response->headers->GetStatusLine(); |
| 6606 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 6607 | |
| 6608 | // Make memory critical notification and ensure the transaction still has been |
| 6609 | // operating right. |
| 6610 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 6611 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 6612 | base::RunLoop().RunUntilIdle(); |
| 6613 | |
| 6614 | // Socket should not be flushed as long as it is not idle. |
| 6615 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 6616 | |
| 6617 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6618 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6619 | EXPECT_THAT(rv, IsOk()); |
| 6620 | EXPECT_EQ("hello world", response_data); |
| 6621 | |
| 6622 | // Empty the current queue. This is necessary because idle sockets are |
| 6623 | // added to the connection pool asynchronously with a PostTask. |
| 6624 | base::RunLoop().RunUntilIdle(); |
| 6625 | |
| 6626 | // We now check to make sure the socket was added back to the pool. |
| 6627 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 6628 | |
| 6629 | // Idle sockets should be flushed now. |
| 6630 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 6631 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 6632 | base::RunLoop().RunUntilIdle(); |
| 6633 | |
| 6634 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 6635 | } |
| 6636 | |
| 6637 | // Grab an SSL socket, use it, and put it back into the pool. Then, make |
| 6638 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6639 | TEST_F(HttpNetworkTransactionTest, FlushSSLSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6640 | HttpRequestInfo request; |
| 6641 | request.method = "GET"; |
| 6642 | request.url = GURL("https://www.example.org/"); |
| 6643 | request.load_flags = 0; |
| 6644 | |
| 6645 | MockWrite data_writes[] = { |
| 6646 | MockWrite("GET / HTTP/1.1\r\n" |
| 6647 | "Host: www.example.org\r\n" |
| 6648 | "Connection: keep-alive\r\n\r\n"), |
| 6649 | }; |
| 6650 | |
| 6651 | MockRead data_reads[] = { |
| 6652 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 6653 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
| 6654 | |
| 6655 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6656 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6657 | |
| 6658 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 6659 | arraysize(data_writes)); |
| 6660 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6661 | |
| 6662 | TestCompletionCallback callback; |
| 6663 | |
| 6664 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6665 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6666 | |
| 6667 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6668 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6669 | |
| 6670 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6671 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6672 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6673 | ASSERT_TRUE(response); |
| 6674 | ASSERT_TRUE(response->headers); |
| 6675 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6676 | |
| 6677 | // Make memory critical notification and ensure the transaction still has been |
| 6678 | // operating right. |
| 6679 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 6680 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 6681 | base::RunLoop().RunUntilIdle(); |
| 6682 | |
| 6683 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 6684 | |
| 6685 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6686 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6687 | EXPECT_THAT(rv, IsOk()); |
| 6688 | EXPECT_EQ("hello world", response_data); |
| 6689 | |
| 6690 | // Empty the current queue. This is necessary because idle sockets are |
| 6691 | // added to the connection pool asynchronously with a PostTask. |
| 6692 | base::RunLoop().RunUntilIdle(); |
| 6693 | |
| 6694 | // We now check to make sure the socket was added back to the pool. |
| 6695 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 6696 | |
| 6697 | // Make memory notification once again and ensure idle socket is closed. |
| 6698 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 6699 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 6700 | base::RunLoop().RunUntilIdle(); |
| 6701 | |
| 6702 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 6703 | } |
| 6704 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6705 | // Make sure that we recycle a socket after a zero-length response. |
| 6706 | // http://crbug.com/9880 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6707 | TEST_F(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6708 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6709 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6710 | request.url = GURL( |
| 6711 | "http://www.example.org/csi?v=3&s=web&action=&" |
| 6712 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 6713 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 6714 | "rt=prt.2642,ol.2649,xjs.2951"); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6715 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6716 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6717 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6718 | MockRead data_reads[] = { |
| 6719 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 6720 | "Content-Length: 0\r\n" |
| 6721 | "Content-Type: text/html\r\n\r\n"), |
| 6722 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6723 | MockRead(SYNCHRONOUS, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6724 | }; |
| 6725 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6726 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6727 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6728 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 6729 | // Transaction must be created after the MockReads, so it's destroyed before |
| 6730 | // them. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6731 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 6732 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6733 | TestCompletionCallback callback; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6734 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6735 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6736 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6737 | |
| 6738 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6739 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6740 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6741 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6742 | ASSERT_TRUE(response); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6743 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6744 | EXPECT_TRUE(response->headers); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6745 | std::string status_line = response->headers->GetStatusLine(); |
| 6746 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 6747 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6748 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6749 | |
| 6750 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6751 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6752 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6753 | EXPECT_EQ("", response_data); |
| 6754 | |
| 6755 | // Empty the current queue. This is necessary because idle sockets are |
| 6756 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6757 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6758 | |
| 6759 | // 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] | 6760 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6761 | } |
| 6762 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6763 | TEST_F(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6764 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 6765 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 6766 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 6767 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 6768 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6769 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6770 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 6771 | // after use. |
| 6772 | request[0].method = "GET"; |
| 6773 | request[0].url = GURL("http://www.google.com/"); |
| 6774 | request[0].load_flags = 0; |
| 6775 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 6776 | // transaction 1. The first attempts fails when writing the POST data. |
| 6777 | // This causes the transaction to retry with a new socket. The second |
| 6778 | // attempt succeeds. |
| 6779 | request[1].method = "POST"; |
| 6780 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 6781 | request[1].upload_data_stream = &upload_data_stream; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6782 | request[1].load_flags = 0; |
| 6783 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6784 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6785 | |
| 6786 | // The first socket is used for transaction 1 and the first attempt of |
| 6787 | // transaction 2. |
| 6788 | |
| 6789 | // The response of transaction 1. |
| 6790 | MockRead data_reads1[] = { |
| 6791 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 6792 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6793 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6794 | }; |
| 6795 | // The mock write results of transaction 1 and the first attempt of |
| 6796 | // transaction 2. |
| 6797 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6798 | MockWrite(SYNCHRONOUS, 64), // GET |
| 6799 | MockWrite(SYNCHRONOUS, 93), // POST |
| 6800 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6801 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6802 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6803 | data_writes1, arraysize(data_writes1)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6804 | |
| 6805 | // The second socket is used for the second attempt of transaction 2. |
| 6806 | |
| 6807 | // The response of transaction 2. |
| 6808 | MockRead data_reads2[] = { |
| 6809 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 6810 | MockRead("welcome"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6811 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6812 | }; |
| 6813 | // The mock write results of the second attempt of transaction 2. |
| 6814 | MockWrite data_writes2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6815 | MockWrite(SYNCHRONOUS, 93), // POST |
| 6816 | MockWrite(SYNCHRONOUS, 3), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6817 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6818 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6819 | data_writes2, arraysize(data_writes2)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6820 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6821 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6822 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6823 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 6824 | const char* const kExpectedResponseData[] = { |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6825 | "hello world", "welcome" |
| 6826 | }; |
| 6827 | |
| 6828 | for (int i = 0; i < 2; ++i) { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6829 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6830 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6831 | TestCompletionCallback callback; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6832 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6833 | int rv = trans.Start(&request[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6834 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6835 | |
| 6836 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6837 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6838 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6839 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6840 | ASSERT_TRUE(response); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6841 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6842 | EXPECT_TRUE(response->headers); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6843 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6844 | |
| 6845 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6846 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6847 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6848 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 6849 | } |
| 6850 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6851 | |
| 6852 | // Test the request-challenge-retry sequence for basic auth when there is |
| 6853 | // 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] | 6854 | // it fails the identity from the URL is used to answer the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6855 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6856 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6857 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6858 | request.url = GURL("http://foo:b@[email protected]/"); |
[email protected] | 7b08ba6 | 2012-02-10 20:19:41 | [diff] [blame] | 6859 | request.load_flags = LOAD_NORMAL; |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 6860 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6861 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6862 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6863 | |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 6864 | // The password contains an escaped character -- for this test to pass it |
| 6865 | // will need to be unescaped by HttpNetworkTransaction. |
| 6866 | EXPECT_EQ("b%40r", request.url.password()); |
| 6867 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6868 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6869 | MockWrite( |
| 6870 | "GET / HTTP/1.1\r\n" |
| 6871 | "Host: www.example.org\r\n" |
| 6872 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6873 | }; |
| 6874 | |
| 6875 | MockRead data_reads1[] = { |
| 6876 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6877 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6878 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6879 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6880 | }; |
| 6881 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6882 | // After the challenge above, the transaction will be restarted using the |
| 6883 | // identity from the url (foo, b@r) to answer the challenge. |
| 6884 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6885 | MockWrite( |
| 6886 | "GET / HTTP/1.1\r\n" |
| 6887 | "Host: www.example.org\r\n" |
| 6888 | "Connection: keep-alive\r\n" |
| 6889 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6890 | }; |
| 6891 | |
| 6892 | MockRead data_reads2[] = { |
| 6893 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6894 | MockRead("Content-Length: 100\r\n\r\n"), |
| 6895 | MockRead(SYNCHRONOUS, OK), |
| 6896 | }; |
| 6897 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6898 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6899 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6900 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6901 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6902 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6903 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6904 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6905 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6906 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6907 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6908 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6909 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6910 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6911 | |
| 6912 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6913 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6914 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6915 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6916 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6917 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6918 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6919 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6920 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6921 | |
| 6922 | // There is no challenge info, since the identity in URL worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6923 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6924 | |
| 6925 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6926 | |
| 6927 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6928 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6929 | } |
| 6930 | |
| 6931 | // Test the request-challenge-retry sequence for basic auth when there is an |
| 6932 | // incorrect identity in the URL. The identity from the URL should be used only |
| 6933 | // once. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6934 | TEST_F(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6935 | HttpRequestInfo request; |
| 6936 | request.method = "GET"; |
| 6937 | // Note: the URL has a username:password in it. The password "baz" is |
| 6938 | // wrong (should be "bar"). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6939 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6940 | |
| 6941 | request.load_flags = LOAD_NORMAL; |
| 6942 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6943 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6944 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6945 | |
| 6946 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6947 | MockWrite( |
| 6948 | "GET / HTTP/1.1\r\n" |
| 6949 | "Host: www.example.org\r\n" |
| 6950 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6951 | }; |
| 6952 | |
| 6953 | MockRead data_reads1[] = { |
| 6954 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6955 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6956 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6957 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 6958 | }; |
| 6959 | |
| 6960 | // After the challenge above, the transaction will be restarted using the |
| 6961 | // identity from the url (foo, baz) to answer the challenge. |
| 6962 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6963 | MockWrite( |
| 6964 | "GET / HTTP/1.1\r\n" |
| 6965 | "Host: www.example.org\r\n" |
| 6966 | "Connection: keep-alive\r\n" |
| 6967 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6968 | }; |
| 6969 | |
| 6970 | MockRead data_reads2[] = { |
| 6971 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6972 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6973 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6974 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 6975 | }; |
| 6976 | |
| 6977 | // After the challenge above, the transaction will be restarted using the |
| 6978 | // identity supplied by the user (foo, bar) to answer the challenge. |
| 6979 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6980 | MockWrite( |
| 6981 | "GET / HTTP/1.1\r\n" |
| 6982 | "Host: www.example.org\r\n" |
| 6983 | "Connection: keep-alive\r\n" |
| 6984 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6985 | }; |
| 6986 | |
| 6987 | MockRead data_reads3[] = { |
| 6988 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6989 | MockRead("Content-Length: 100\r\n\r\n"), |
| 6990 | MockRead(SYNCHRONOUS, OK), |
| 6991 | }; |
| 6992 | |
| 6993 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6994 | data_writes1, arraysize(data_writes1)); |
| 6995 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6996 | data_writes2, arraysize(data_writes2)); |
| 6997 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6998 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6999 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7000 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7001 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7002 | |
| 7003 | TestCompletionCallback callback1; |
| 7004 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7005 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7006 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7007 | |
| 7008 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7009 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7010 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7011 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7012 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7013 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7014 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7015 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7016 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7017 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7018 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7019 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7020 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7021 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 7022 | |
| 7023 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7024 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7025 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7026 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7027 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7028 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7029 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7030 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7031 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7032 | |
| 7033 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7034 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7035 | |
| 7036 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7037 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 7038 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7039 | base::RunLoop().RunUntilIdle(); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 7040 | } |
| 7041 | |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7042 | |
| 7043 | // Test the request-challenge-retry sequence for basic auth when there is a |
| 7044 | // correct identity in the URL, but its use is being suppressed. The identity |
| 7045 | // from the URL should never be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7046 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURLSuppressed) { |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7047 | HttpRequestInfo request; |
| 7048 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7049 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7050 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
| 7051 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7052 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7053 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7054 | |
| 7055 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7056 | MockWrite( |
| 7057 | "GET / HTTP/1.1\r\n" |
| 7058 | "Host: www.example.org\r\n" |
| 7059 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7060 | }; |
| 7061 | |
| 7062 | MockRead data_reads1[] = { |
| 7063 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7064 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7065 | MockRead("Content-Length: 10\r\n\r\n"), |
| 7066 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 7067 | }; |
| 7068 | |
| 7069 | // After the challenge above, the transaction will be restarted using the |
| 7070 | // identity supplied by the user, not the one in the URL, to answer the |
| 7071 | // challenge. |
| 7072 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7073 | MockWrite( |
| 7074 | "GET / HTTP/1.1\r\n" |
| 7075 | "Host: www.example.org\r\n" |
| 7076 | "Connection: keep-alive\r\n" |
| 7077 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7078 | }; |
| 7079 | |
| 7080 | MockRead data_reads3[] = { |
| 7081 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7082 | MockRead("Content-Length: 100\r\n\r\n"), |
| 7083 | MockRead(SYNCHRONOUS, OK), |
| 7084 | }; |
| 7085 | |
| 7086 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7087 | data_writes1, arraysize(data_writes1)); |
| 7088 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 7089 | data_writes3, arraysize(data_writes3)); |
| 7090 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7091 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 7092 | |
| 7093 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7094 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7095 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7096 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7097 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7098 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7099 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7100 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7101 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7102 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 7103 | |
| 7104 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7105 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7106 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7107 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7108 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7109 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7110 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7111 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7112 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7113 | |
| 7114 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7115 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7116 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7117 | |
| 7118 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7119 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7120 | } |
| 7121 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7122 | // Test that previously tried username/passwords for a realm get re-used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7123 | TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7124 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7125 | |
| 7126 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 7127 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7128 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7129 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7130 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7131 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7132 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7133 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7134 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7135 | MockWrite( |
| 7136 | "GET /x/y/z HTTP/1.1\r\n" |
| 7137 | "Host: www.example.org\r\n" |
| 7138 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7139 | }; |
| 7140 | |
| 7141 | MockRead data_reads1[] = { |
| 7142 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7143 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7144 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7145 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7146 | }; |
| 7147 | |
| 7148 | // Resend with authorization (username=foo, password=bar) |
| 7149 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7150 | MockWrite( |
| 7151 | "GET /x/y/z HTTP/1.1\r\n" |
| 7152 | "Host: www.example.org\r\n" |
| 7153 | "Connection: keep-alive\r\n" |
| 7154 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7155 | }; |
| 7156 | |
| 7157 | // Sever accepts the authorization. |
| 7158 | MockRead data_reads2[] = { |
| 7159 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7160 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7161 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7162 | }; |
| 7163 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7164 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7165 | data_writes1, arraysize(data_writes1)); |
| 7166 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7167 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7168 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7169 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7170 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7171 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7172 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7173 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7174 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7175 | |
| 7176 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7177 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7178 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7179 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7180 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7181 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7182 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7183 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7184 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7185 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 7186 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7187 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7188 | |
| 7189 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7190 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7191 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7192 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7193 | ASSERT_TRUE(response); |
| 7194 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7195 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7196 | } |
| 7197 | |
| 7198 | // ------------------------------------------------------------------------ |
| 7199 | |
| 7200 | // Transaction 2: authenticate (foo2, bar2) on MyRealm2 |
| 7201 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7202 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7203 | request.method = "GET"; |
| 7204 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 7205 | // protection space as MyRealm1. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7206 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7207 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7208 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7209 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7210 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7211 | MockWrite( |
| 7212 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 7213 | "Host: www.example.org\r\n" |
| 7214 | "Connection: keep-alive\r\n" |
| 7215 | // Send preemptive authorization for MyRealm1 |
| 7216 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7217 | }; |
| 7218 | |
| 7219 | // The server didn't like the preemptive authorization, and |
| 7220 | // challenges us for a different realm (MyRealm2). |
| 7221 | MockRead data_reads1[] = { |
| 7222 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7223 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 7224 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7225 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7226 | }; |
| 7227 | |
| 7228 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 7229 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7230 | MockWrite( |
| 7231 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 7232 | "Host: www.example.org\r\n" |
| 7233 | "Connection: keep-alive\r\n" |
| 7234 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7235 | }; |
| 7236 | |
| 7237 | // Sever accepts the authorization. |
| 7238 | MockRead data_reads2[] = { |
| 7239 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7240 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7241 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7242 | }; |
| 7243 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7244 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7245 | data_writes1, arraysize(data_writes1)); |
| 7246 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7247 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7248 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7249 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7250 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7251 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7252 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7253 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7254 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7255 | |
| 7256 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7257 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7258 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7259 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7260 | ASSERT_TRUE(response); |
| 7261 | ASSERT_TRUE(response->auth_challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7262 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 7263 | EXPECT_EQ("http://www.example.org", |
| 7264 | response->auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7265 | EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 7266 | EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7267 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7268 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7269 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7270 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 7271 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7272 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7273 | |
| 7274 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7275 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7276 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7277 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7278 | ASSERT_TRUE(response); |
| 7279 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7280 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7281 | } |
| 7282 | |
| 7283 | // ------------------------------------------------------------------------ |
| 7284 | |
| 7285 | // Transaction 3: Resend a request in MyRealm's protection space -- |
| 7286 | // succeed with preemptive authorization. |
| 7287 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7288 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7289 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7290 | request.url = GURL("http://www.example.org/x/y/z2"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7291 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7292 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7293 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7294 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7295 | MockWrite( |
| 7296 | "GET /x/y/z2 HTTP/1.1\r\n" |
| 7297 | "Host: www.example.org\r\n" |
| 7298 | "Connection: keep-alive\r\n" |
| 7299 | // The authorization for MyRealm1 gets sent preemptively |
| 7300 | // (since the url is in the same protection space) |
| 7301 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7302 | }; |
| 7303 | |
| 7304 | // Sever accepts the preemptive authorization |
| 7305 | MockRead data_reads1[] = { |
| 7306 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7307 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7308 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7309 | }; |
| 7310 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7311 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7312 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7313 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7314 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7315 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7316 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7317 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7318 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7319 | |
| 7320 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7321 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7322 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7323 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7324 | ASSERT_TRUE(response); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7325 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7326 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7327 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7328 | } |
| 7329 | |
| 7330 | // ------------------------------------------------------------------------ |
| 7331 | |
| 7332 | // Transaction 4: request another URL in MyRealm (however the |
| 7333 | // url is not known to belong to the protection space, so no pre-auth). |
| 7334 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7335 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7336 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7337 | request.url = GURL("http://www.example.org/x/1"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7338 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7339 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7340 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7341 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7342 | MockWrite( |
| 7343 | "GET /x/1 HTTP/1.1\r\n" |
| 7344 | "Host: www.example.org\r\n" |
| 7345 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7346 | }; |
| 7347 | |
| 7348 | MockRead data_reads1[] = { |
| 7349 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7350 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7351 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7352 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7353 | }; |
| 7354 | |
| 7355 | // Resend with authorization from MyRealm's cache. |
| 7356 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7357 | MockWrite( |
| 7358 | "GET /x/1 HTTP/1.1\r\n" |
| 7359 | "Host: www.example.org\r\n" |
| 7360 | "Connection: keep-alive\r\n" |
| 7361 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7362 | }; |
| 7363 | |
| 7364 | // Sever accepts the authorization. |
| 7365 | MockRead data_reads2[] = { |
| 7366 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7367 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7368 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7369 | }; |
| 7370 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7371 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7372 | data_writes1, arraysize(data_writes1)); |
| 7373 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7374 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7375 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7376 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7377 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7378 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7379 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7380 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7381 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7382 | |
| 7383 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7384 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7385 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7386 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7387 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7388 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7389 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7390 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7391 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7392 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [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); |
| 7396 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7397 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7398 | } |
| 7399 | |
| 7400 | // ------------------------------------------------------------------------ |
| 7401 | |
| 7402 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 7403 | // cached identity. Should invalidate and re-prompt. |
| 7404 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7405 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7406 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7407 | request.url = GURL("http://www.example.org/p/q/t"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7408 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7409 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7410 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7411 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7412 | MockWrite( |
| 7413 | "GET /p/q/t HTTP/1.1\r\n" |
| 7414 | "Host: www.example.org\r\n" |
| 7415 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7416 | }; |
| 7417 | |
| 7418 | MockRead data_reads1[] = { |
| 7419 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7420 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7421 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7422 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7423 | }; |
| 7424 | |
| 7425 | // Resend with authorization from cache for MyRealm. |
| 7426 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7427 | MockWrite( |
| 7428 | "GET /p/q/t HTTP/1.1\r\n" |
| 7429 | "Host: www.example.org\r\n" |
| 7430 | "Connection: keep-alive\r\n" |
| 7431 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7432 | }; |
| 7433 | |
| 7434 | // Sever rejects the authorization. |
| 7435 | MockRead data_reads2[] = { |
| 7436 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7437 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7438 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7439 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7440 | }; |
| 7441 | |
| 7442 | // At this point we should prompt for new credentials for MyRealm. |
| 7443 | // Restart with username=foo3, password=foo4. |
| 7444 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7445 | MockWrite( |
| 7446 | "GET /p/q/t HTTP/1.1\r\n" |
| 7447 | "Host: www.example.org\r\n" |
| 7448 | "Connection: keep-alive\r\n" |
| 7449 | "Authorization: Basic Zm9vMzpiYXIz\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_reads3[] = { |
| 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)); |
| 7463 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 7464 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7465 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7466 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7467 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7468 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7469 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7470 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7471 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7472 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7473 | |
| 7474 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7475 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7476 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7477 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7478 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7479 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7480 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7481 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7482 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7483 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7484 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7485 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7486 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7487 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7488 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7489 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7490 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7491 | rv = trans.RestartWithAuth(AuthCredentials(kFoo3, kBar3), |
| 7492 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7493 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7494 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7495 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7496 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7497 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7498 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7499 | ASSERT_TRUE(response); |
| 7500 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7501 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7502 | } |
| 7503 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7504 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7505 | // Tests that nonce count increments when multiple auth attempts |
| 7506 | // are started with the same nonce. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7507 | TEST_F(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { |
[email protected] | 54fea256 | 2010-11-17 14:40:44 | [diff] [blame] | 7508 | HttpAuthHandlerDigest::Factory* digest_factory = |
| 7509 | new HttpAuthHandlerDigest::Factory(); |
| 7510 | HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = |
| 7511 | new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); |
| 7512 | digest_factory->set_nonce_generator(nonce_generator); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7513 | session_deps_.http_auth_handler_factory.reset(digest_factory); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7514 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7515 | |
| 7516 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 7517 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7518 | HttpRequestInfo request; |
| 7519 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7520 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7521 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7522 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7523 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7524 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7525 | MockWrite( |
| 7526 | "GET /x/y/z HTTP/1.1\r\n" |
| 7527 | "Host: www.example.org\r\n" |
| 7528 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7529 | }; |
| 7530 | |
| 7531 | MockRead data_reads1[] = { |
| 7532 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7533 | MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " |
| 7534 | "algorithm=MD5, qop=\"auth\"\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7535 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7536 | }; |
| 7537 | |
| 7538 | // Resend with authorization (username=foo, password=bar) |
| 7539 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7540 | MockWrite( |
| 7541 | "GET /x/y/z HTTP/1.1\r\n" |
| 7542 | "Host: www.example.org\r\n" |
| 7543 | "Connection: keep-alive\r\n" |
| 7544 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 7545 | "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " |
| 7546 | "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " |
| 7547 | "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7548 | }; |
| 7549 | |
| 7550 | // Sever accepts the authorization. |
| 7551 | MockRead data_reads2[] = { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 7552 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7553 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7554 | }; |
| 7555 | |
| 7556 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7557 | data_writes1, arraysize(data_writes1)); |
| 7558 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7559 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7560 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7561 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7562 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7563 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7564 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7565 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7566 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7567 | |
| 7568 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7569 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7570 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7571 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7572 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7573 | EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge.get())); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7574 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7575 | TestCompletionCallback callback2; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7576 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7577 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 7578 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7579 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7580 | |
| 7581 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7582 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7583 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7584 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7585 | ASSERT_TRUE(response); |
| 7586 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7587 | } |
| 7588 | |
| 7589 | // ------------------------------------------------------------------------ |
| 7590 | |
| 7591 | // Transaction 2: Request another resource in digestive's protection space. |
| 7592 | // This will preemptively add an Authorization header which should have an |
| 7593 | // "nc" value of 2 (as compared to 1 in the first use. |
| 7594 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7595 | HttpRequestInfo request; |
| 7596 | request.method = "GET"; |
| 7597 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 7598 | // protection space as digest. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7599 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7600 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7601 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7602 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7603 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7604 | MockWrite( |
| 7605 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 7606 | "Host: www.example.org\r\n" |
| 7607 | "Connection: keep-alive\r\n" |
| 7608 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 7609 | "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " |
| 7610 | "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " |
| 7611 | "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7612 | }; |
| 7613 | |
| 7614 | // Sever accepts the authorization. |
| 7615 | MockRead data_reads1[] = { |
| 7616 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7617 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7618 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7619 | }; |
| 7620 | |
| 7621 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7622 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7623 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7624 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7625 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7626 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7627 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7628 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7629 | |
| 7630 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7631 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7632 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7633 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7634 | ASSERT_TRUE(response); |
| 7635 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7636 | } |
| 7637 | } |
| 7638 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7639 | // Test the ResetStateForRestart() private method. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7640 | TEST_F(HttpNetworkTransactionTest, ResetStateForRestart) { |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7641 | // Create a transaction (the dependencies aren't important). |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7642 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7643 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7644 | |
| 7645 | // Setup some state (which we expect ResetStateForRestart() will clear). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7646 | trans.read_buf_ = new IOBuffer(15); |
| 7647 | trans.read_buf_len_ = 15; |
| 7648 | trans.request_headers_.SetHeader("Authorization", "NTLM"); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7649 | |
| 7650 | // Setup state in response_ |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7651 | HttpResponseInfo* response = &trans.response_; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7652 | response->auth_challenge = new AuthChallengeInfo(); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 7653 | response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7654 | response->response_time = base::Time::Now(); |
| 7655 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7656 | |
| 7657 | { // Setup state for response_.vary_data |
| 7658 | HttpRequestInfo request; |
| 7659 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 7660 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 7661 | scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 7662 | request.extra_headers.SetHeader("Foo", "1"); |
| 7663 | request.extra_headers.SetHeader("bar", "23"); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7664 | EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7665 | } |
| 7666 | |
| 7667 | // Cause the above state to be reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7668 | trans.ResetStateForRestart(); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7669 | |
| 7670 | // Verify that the state that needed to be reset, has been reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7671 | EXPECT_FALSE(trans.read_buf_); |
| 7672 | EXPECT_EQ(0, trans.read_buf_len_); |
| 7673 | EXPECT_TRUE(trans.request_headers_.IsEmpty()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7674 | EXPECT_FALSE(response->auth_challenge); |
| 7675 | EXPECT_FALSE(response->headers); |
[email protected] | 34f4094 | 2010-10-04 00:34:04 | [diff] [blame] | 7676 | EXPECT_FALSE(response->was_cached); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 7677 | EXPECT_EQ(0U, response->ssl_info.cert_status); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7678 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7679 | } |
| 7680 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7681 | // Test HTTPS connections to a site with a bad certificate |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7682 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7683 | HttpRequestInfo request; |
| 7684 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7685 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7686 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7687 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7688 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7689 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7690 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7691 | MockWrite( |
| 7692 | "GET / HTTP/1.1\r\n" |
| 7693 | "Host: www.example.org\r\n" |
| 7694 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7695 | }; |
| 7696 | |
| 7697 | MockRead data_reads[] = { |
| 7698 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7699 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7700 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7701 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7702 | }; |
| 7703 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 7704 | StaticSocketDataProvider ssl_bad_certificate; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7705 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7706 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7707 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 7708 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7709 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7710 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 7711 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7712 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 7713 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7714 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7715 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7716 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7717 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7718 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7719 | |
| 7720 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7721 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7722 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7723 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7724 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7725 | |
| 7726 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7727 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7728 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7729 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7730 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7731 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7732 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7733 | } |
| 7734 | |
| 7735 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 7736 | // proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7737 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7738 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7739 | |
| 7740 | HttpRequestInfo request; |
| 7741 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7742 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7743 | |
| 7744 | MockWrite proxy_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7745 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7746 | "Host: www.example.org:443\r\n" |
| 7747 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7748 | }; |
| 7749 | |
| 7750 | MockRead proxy_reads[] = { |
| 7751 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7752 | MockRead(SYNCHRONOUS, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7753 | }; |
| 7754 | |
| 7755 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7756 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7757 | "Host: www.example.org:443\r\n" |
| 7758 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7759 | MockWrite("GET / HTTP/1.1\r\n" |
| 7760 | "Host: www.example.org\r\n" |
| 7761 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7762 | }; |
| 7763 | |
| 7764 | MockRead data_reads[] = { |
| 7765 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 7766 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7767 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7768 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7769 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7770 | }; |
| 7771 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7772 | StaticSocketDataProvider ssl_bad_certificate( |
| 7773 | proxy_reads, arraysize(proxy_reads), |
| 7774 | proxy_writes, arraysize(proxy_writes)); |
| 7775 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7776 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7777 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 7778 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7779 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7780 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 7781 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7782 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 7783 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7784 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7785 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7786 | |
| 7787 | for (int i = 0; i < 2; i++) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7788 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7789 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7790 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7791 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7792 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7793 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7794 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7795 | |
| 7796 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7797 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7798 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7799 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7800 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7801 | |
| 7802 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7803 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7804 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7805 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7806 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7807 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7808 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7809 | } |
| 7810 | } |
| 7811 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7812 | |
| 7813 | // Test HTTPS connections to a site, going through an HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7814 | TEST_F(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7815 | session_deps_.proxy_service = |
| 7816 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7817 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7818 | session_deps_.net_log = &net_log; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7819 | |
| 7820 | HttpRequestInfo request; |
| 7821 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7822 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7823 | |
| 7824 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7825 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7826 | "Host: www.example.org:443\r\n" |
| 7827 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7828 | MockWrite("GET / HTTP/1.1\r\n" |
| 7829 | "Host: www.example.org\r\n" |
| 7830 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7831 | }; |
| 7832 | |
| 7833 | MockRead data_reads[] = { |
| 7834 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 7835 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7836 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7837 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7838 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7839 | }; |
| 7840 | |
| 7841 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7842 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7843 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 7844 | SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7845 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7846 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7847 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 7848 | session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7849 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7850 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7851 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7852 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7853 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7854 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7855 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7856 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7857 | |
| 7858 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7859 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7860 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7861 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7862 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7863 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 7864 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7865 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 7866 | EXPECT_EQ(200, response->headers->response_code()); |
| 7867 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7868 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7869 | |
| 7870 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7871 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7872 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7873 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7874 | } |
| 7875 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7876 | // Test an HTTPS Proxy's ability to redirect a CONNECT request |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7877 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7878 | session_deps_.proxy_service = |
| 7879 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7880 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7881 | session_deps_.net_log = &net_log; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7882 | |
| 7883 | HttpRequestInfo request; |
| 7884 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7885 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7886 | |
| 7887 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7888 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7889 | "Host: www.example.org:443\r\n" |
| 7890 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7891 | }; |
| 7892 | |
| 7893 | MockRead data_reads[] = { |
| 7894 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 7895 | MockRead("Location: http://login.example.com/\r\n"), |
| 7896 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7897 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7898 | }; |
| 7899 | |
| 7900 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7901 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7902 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7903 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7904 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7905 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7906 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7907 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7908 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7909 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7910 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7911 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7912 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7913 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7914 | |
| 7915 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7916 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7917 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7918 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7919 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7920 | |
| 7921 | EXPECT_EQ(302, response->headers->response_code()); |
| 7922 | std::string url; |
| 7923 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 7924 | EXPECT_EQ("http://login.example.com/", url); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7925 | |
| 7926 | // In the case of redirects from proxies, HttpNetworkTransaction returns |
| 7927 | // timing for the proxy connection instead of the connection to the host, |
| 7928 | // and no send / receive times. |
| 7929 | // See HttpNetworkTransaction::OnHttpsProxyTunnelResponse. |
| 7930 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7931 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7932 | |
| 7933 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 7934 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7935 | |
| 7936 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 7937 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 7938 | load_timing_info.proxy_resolve_end); |
| 7939 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 7940 | load_timing_info.connect_timing.connect_start); |
| 7941 | ExpectConnectTimingHasTimes( |
| 7942 | load_timing_info.connect_timing, |
| 7943 | CONNECT_TIMING_HAS_DNS_TIMES | CONNECT_TIMING_HAS_SSL_TIMES); |
| 7944 | |
| 7945 | EXPECT_TRUE(load_timing_info.send_start.is_null()); |
| 7946 | EXPECT_TRUE(load_timing_info.send_end.is_null()); |
| 7947 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7948 | } |
| 7949 | |
| 7950 | // Test an HTTPS (SPDY) Proxy's ability to redirect a CONNECT request |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7951 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7952 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7953 | |
| 7954 | HttpRequestInfo request; |
| 7955 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7956 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7957 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7958 | SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7959 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7960 | SpdySerializedFrame goaway( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 7961 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7962 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7963 | CreateMockWrite(conn, 0, SYNCHRONOUS), |
| 7964 | CreateMockWrite(goaway, 2, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7965 | }; |
| 7966 | |
| 7967 | static const char* const kExtraHeaders[] = { |
| 7968 | "location", |
| 7969 | "http://login.example.com/", |
| 7970 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 7971 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
bnc | c9f762a | 2016-12-06 20:38:23 | [diff] [blame] | 7972 | "302", kExtraHeaders, arraysize(kExtraHeaders) / 2, 1)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7973 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7974 | CreateMockRead(resp, 1), MockRead(ASYNC, 0, 3), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7975 | }; |
| 7976 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7977 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 7978 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7979 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 7980 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7981 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7982 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7983 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7984 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7985 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7986 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7987 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7988 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7989 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7990 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7991 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7992 | |
| 7993 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7994 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7995 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7996 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7997 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7998 | |
| 7999 | EXPECT_EQ(302, response->headers->response_code()); |
| 8000 | std::string url; |
| 8001 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 8002 | EXPECT_EQ("http://login.example.com/", url); |
| 8003 | } |
| 8004 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 8005 | // Test that an HTTPS proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8006 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8007 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8008 | |
| 8009 | HttpRequestInfo request; |
| 8010 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8011 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8012 | |
| 8013 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8014 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8015 | "Host: www.example.org:443\r\n" |
| 8016 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8017 | }; |
| 8018 | |
| 8019 | MockRead data_reads[] = { |
| 8020 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 8021 | MockRead("Content-Length: 23\r\n\r\n"), |
| 8022 | MockRead("The host does not exist"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8023 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8024 | }; |
| 8025 | |
| 8026 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8027 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8028 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8029 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8030 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8031 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8032 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8033 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8034 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8035 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8036 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8037 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8038 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8039 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8040 | |
| 8041 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8042 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8043 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 8044 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8045 | } |
| 8046 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 8047 | // Test that a SPDY proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8048 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaSpdyProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8049 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8050 | |
| 8051 | HttpRequestInfo request; |
| 8052 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8053 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8054 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8055 | SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8056 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8057 | SpdySerializedFrame rst( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 8058 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8059 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8060 | CreateMockWrite(conn, 0), CreateMockWrite(rst, 3), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8061 | }; |
| 8062 | |
| 8063 | static const char* const kExtraHeaders[] = { |
| 8064 | "location", |
| 8065 | "http://login.example.com/", |
| 8066 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8067 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
bnc | c9f762a | 2016-12-06 20:38:23 | [diff] [blame] | 8068 | "404", kExtraHeaders, arraysize(kExtraHeaders) / 2, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8069 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 8070 | 1, "The host does not exist", 23, true)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8071 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8072 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8073 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8074 | }; |
| 8075 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8076 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 8077 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8078 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8079 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8080 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8081 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8082 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8083 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8084 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8085 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8086 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8087 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8088 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8089 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8090 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8091 | |
| 8092 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8093 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8094 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 8095 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8096 | } |
| 8097 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8098 | // Test the request-challenge-retry sequence for basic auth, through |
| 8099 | // a SPDY proxy over a single SPDY session. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8100 | TEST_F(HttpNetworkTransactionTest, BasicAuthSpdyProxy) { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8101 | HttpRequestInfo request; |
| 8102 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8103 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8104 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 8105 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8106 | |
| 8107 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8108 | session_deps_.proxy_service = |
| 8109 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8110 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8111 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8112 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8113 | |
| 8114 | // Since we have proxy, should try to establish tunnel. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8115 | SpdySerializedFrame req(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8116 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8117 | SpdySerializedFrame rst( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 8118 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 8119 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8120 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8121 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8122 | // be issuing -- the final header line contains the credentials. |
| 8123 | const char* const kAuthCredentials[] = { |
| 8124 | "proxy-authorization", "Basic Zm9vOmJhcg==", |
| 8125 | }; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8126 | SpdySerializedFrame connect2(spdy_util_.ConstructSpdyConnect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 8127 | kAuthCredentials, arraysize(kAuthCredentials) / 2, 3, LOWEST, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8128 | HostPortPair("www.example.org", 443))); |
| 8129 | // fetch https://www.example.org/ via HTTP |
| 8130 | const char get[] = |
| 8131 | "GET / HTTP/1.1\r\n" |
| 8132 | "Host: www.example.org\r\n" |
| 8133 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8134 | SpdySerializedFrame wrapped_get( |
| 8135 | spdy_util_.ConstructSpdyDataFrame(3, get, strlen(get), false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8136 | |
| 8137 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8138 | CreateMockWrite(req, 0, ASYNC), CreateMockWrite(rst, 2, ASYNC), |
| 8139 | CreateMockWrite(connect2, 3), CreateMockWrite(wrapped_get, 5), |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8140 | }; |
| 8141 | |
| 8142 | // The proxy responds to the connect with a 407, using a persistent |
| 8143 | // connection. |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 8144 | const char kAuthStatus[] = "407"; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8145 | const char* const kAuthChallenge[] = { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8146 | "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 8147 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8148 | SpdySerializedFrame conn_auth_resp(spdy_util_.ConstructSpdyReplyError( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8149 | kAuthStatus, kAuthChallenge, arraysize(kAuthChallenge) / 2, 1)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8150 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8151 | SpdySerializedFrame conn_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8152 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 8153 | "Content-Length: 5\r\n\r\n"; |
| 8154 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8155 | SpdySerializedFrame wrapped_get_resp( |
| 8156 | spdy_util_.ConstructSpdyDataFrame(3, resp, strlen(resp), false)); |
| 8157 | SpdySerializedFrame wrapped_body( |
| 8158 | spdy_util_.ConstructSpdyDataFrame(3, "hello", 5, false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8159 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8160 | CreateMockRead(conn_auth_resp, 1, ASYNC), |
| 8161 | CreateMockRead(conn_resp, 4, ASYNC), |
| 8162 | CreateMockRead(wrapped_get_resp, 6, ASYNC), |
| 8163 | CreateMockRead(wrapped_body, 7, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8164 | MockRead(ASYNC, OK, 8), // EOF. May or may not be read. |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8165 | }; |
| 8166 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8167 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8168 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8169 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8170 | // Negotiate SPDY to the proxy |
| 8171 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8172 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8173 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8174 | // Vanilla SSL to the server |
| 8175 | SSLSocketDataProvider server(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8176 | session_deps_.socket_factory->AddSSLSocketDataProvider(&server); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8177 | |
| 8178 | TestCompletionCallback callback1; |
| 8179 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8180 | auto trans = |
| 8181 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8182 | |
| 8183 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8184 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8185 | |
| 8186 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8187 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 8188 | TestNetLogEntry::List entries; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8189 | log.GetEntries(&entries); |
| 8190 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 8191 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 8192 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8193 | ExpectLogContainsSomewhere( |
| 8194 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 8195 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 8196 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8197 | |
| 8198 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8199 | ASSERT_TRUE(response); |
| 8200 | ASSERT_TRUE(response->headers); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8201 | EXPECT_EQ(407, response->headers->response_code()); |
| 8202 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8203 | EXPECT_TRUE(response->auth_challenge); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 8204 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8205 | |
| 8206 | TestCompletionCallback callback2; |
| 8207 | |
| 8208 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 8209 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8210 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8211 | |
| 8212 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8213 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8214 | |
| 8215 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8216 | ASSERT_TRUE(response); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8217 | |
| 8218 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8219 | EXPECT_EQ(200, response->headers->response_code()); |
| 8220 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 8221 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8222 | |
| 8223 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8224 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8225 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8226 | LoadTimingInfo load_timing_info; |
| 8227 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8228 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8229 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 8230 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8231 | trans.reset(); |
| 8232 | session->CloseAllConnections(); |
| 8233 | } |
| 8234 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8235 | // Test that an explicitly trusted SPDY proxy can push a resource from an |
| 8236 | // origin that is different from that of its associated resource. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8237 | TEST_F(HttpNetworkTransactionTest, CrossOriginSPDYProxyPush) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8238 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8239 | auto proxy_delegate = base::MakeUnique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8240 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 8241 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8242 | HttpRequestInfo request; |
| 8243 | HttpRequestInfo push_request; |
| 8244 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8245 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8246 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8247 | push_request.method = "GET"; |
| 8248 | push_request.url = GURL("http://www.another-origin.com/foo.dat"); |
| 8249 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8250 | // Configure against https proxy server "myproxy:443". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8251 | session_deps_.proxy_service = |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8252 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:443"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8253 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8254 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8255 | |
inlinechan | 894515af | 2016-12-09 02:40:10 | [diff] [blame] | 8256 | session_deps_.proxy_delegate = std::move(proxy_delegate); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8257 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8258 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8259 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8260 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 8261 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8262 | SpdySerializedFrame stream2_priority( |
| 8263 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8264 | |
| 8265 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8266 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8267 | CreateMockWrite(stream2_priority, 3, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8268 | }; |
| 8269 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8270 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8271 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8272 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8273 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8274 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8275 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 8276 | NULL, 0, 2, 1, "http://www.another-origin.com/foo.dat")); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8277 | const char kPushedData[] = "pushed"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8278 | SpdySerializedFrame stream2_body(spdy_util_.ConstructSpdyDataFrame( |
| 8279 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8280 | |
| 8281 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8282 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 8283 | CreateMockRead(stream2_syn, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8284 | CreateMockRead(stream1_body, 4, ASYNC), |
| 8285 | CreateMockRead(stream2_body, 5, ASYNC), |
| 8286 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8287 | }; |
| 8288 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8289 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8290 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8291 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8292 | // Negotiate SPDY to the proxy |
| 8293 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8294 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8295 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8296 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8297 | auto trans = |
| 8298 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8299 | TestCompletionCallback callback; |
| 8300 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8301 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8302 | |
| 8303 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8304 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8305 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8306 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8307 | auto push_trans = |
| 8308 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8309 | rv = push_trans->Start(&push_request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8310 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8311 | |
| 8312 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8313 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8314 | const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); |
| 8315 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8316 | ASSERT_TRUE(response); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8317 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8318 | |
| 8319 | EXPECT_EQ(200, response->headers->response_code()); |
| 8320 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8321 | |
| 8322 | std::string response_data; |
| 8323 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8324 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8325 | EXPECT_EQ("hello!", response_data); |
| 8326 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8327 | LoadTimingInfo load_timing_info; |
| 8328 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8329 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8330 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 8331 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8332 | // Verify the pushed stream. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8333 | EXPECT_TRUE(push_response->headers); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8334 | EXPECT_EQ(200, push_response->headers->response_code()); |
| 8335 | |
| 8336 | rv = ReadTransaction(push_trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8337 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8338 | EXPECT_EQ("pushed", response_data); |
| 8339 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8340 | LoadTimingInfo push_load_timing_info; |
| 8341 | EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); |
| 8342 | TestLoadTimingReusedWithPac(push_load_timing_info); |
| 8343 | // The transactions should share a socket ID, despite being for different |
| 8344 | // origins. |
| 8345 | EXPECT_EQ(load_timing_info.socket_log_id, |
| 8346 | push_load_timing_info.socket_log_id); |
| 8347 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8348 | trans.reset(); |
| 8349 | push_trans.reset(); |
| 8350 | session->CloseAllConnections(); |
| 8351 | } |
| 8352 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8353 | // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8354 | TEST_F(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8355 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8356 | auto proxy_delegate = base::MakeUnique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8357 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 8358 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8359 | HttpRequestInfo request; |
| 8360 | |
| 8361 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8362 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8363 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8364 | session_deps_.proxy_service = |
| 8365 | ProxyService::CreateFixed("https://myproxy:443"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8366 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8367 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8368 | |
| 8369 | // Enable cross-origin push. |
inlinechan | 894515af | 2016-12-09 02:40:10 | [diff] [blame] | 8370 | session_deps_.proxy_delegate = std::move(proxy_delegate); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8371 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8372 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8373 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8374 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 8375 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8376 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8377 | SpdySerializedFrame push_rst( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 8378 | spdy_util_.ConstructSpdyRstStream(2, ERROR_CODE_REFUSED_STREAM)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8379 | |
| 8380 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8381 | CreateMockWrite(stream1_syn, 0, ASYNC), CreateMockWrite(push_rst, 3), |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8382 | }; |
| 8383 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8384 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8385 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8386 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8387 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8388 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8389 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 8390 | NULL, 0, 2, 1, "https://www.another-origin.com/foo.dat")); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8391 | |
| 8392 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8393 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 8394 | CreateMockRead(stream2_syn, 2, ASYNC), |
| 8395 | CreateMockRead(stream1_body, 4, ASYNC), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 8396 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a hang |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8397 | }; |
| 8398 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8399 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8400 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8401 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8402 | // Negotiate SPDY to the proxy |
| 8403 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8404 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8405 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8406 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8407 | auto trans = |
| 8408 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8409 | TestCompletionCallback callback; |
| 8410 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8411 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8412 | |
| 8413 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8414 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8415 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8416 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8417 | ASSERT_TRUE(response); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8418 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8419 | |
| 8420 | EXPECT_EQ(200, response->headers->response_code()); |
| 8421 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8422 | |
| 8423 | std::string response_data; |
| 8424 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8425 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8426 | EXPECT_EQ("hello!", response_data); |
| 8427 | |
| 8428 | trans.reset(); |
| 8429 | session->CloseAllConnections(); |
| 8430 | } |
| 8431 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8432 | // Test that an explicitly trusted SPDY proxy can push same-origin HTTPS |
| 8433 | // resources. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8434 | TEST_F(HttpNetworkTransactionTest, SameOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8435 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8436 | auto proxy_delegate = base::MakeUnique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8437 | proxy_delegate->set_trusted_spdy_proxy( |
| 8438 | net::ProxyServer::FromURI("myproxy:70", net::ProxyServer::SCHEME_HTTP)); |
| 8439 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8440 | HttpRequestInfo request; |
| 8441 | |
| 8442 | request.method = "GET"; |
| 8443 | request.url = GURL("http://www.example.org/"); |
| 8444 | |
| 8445 | // Configure against https proxy server "myproxy:70". |
| 8446 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
| 8447 | BoundTestNetLog log; |
| 8448 | session_deps_.net_log = log.bound().net_log(); |
| 8449 | |
| 8450 | // Enable cross-origin push. |
inlinechan | 894515af | 2016-12-09 02:40:10 | [diff] [blame] | 8451 | session_deps_.proxy_delegate = std::move(proxy_delegate); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8452 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8453 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8454 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8455 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 8456 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8457 | SpdySerializedFrame stream2_priority( |
| 8458 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8459 | |
| 8460 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8461 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8462 | CreateMockWrite(stream2_priority, 3, ASYNC), |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8463 | }; |
| 8464 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8465 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8466 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8467 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8468 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
Bence Béky | 096cf05 | 2017-08-08 23:55:33 | [diff] [blame] | 8469 | nullptr, 0, 2, 1, "http://www.example.org/foo.dat")); |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 8470 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8471 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8472 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8473 | SpdySerializedFrame stream2_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8474 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8475 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8476 | SpdySerializedFrame stream2_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8477 | |
| 8478 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8479 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 8480 | CreateMockRead(stream2_syn, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8481 | CreateMockRead(stream1_body, 4, ASYNC), |
| 8482 | CreateMockRead(stream2_body, 5, ASYNC), |
| 8483 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8484 | }; |
| 8485 | |
| 8486 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8487 | arraysize(spdy_writes)); |
| 8488 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 8489 | // Negotiate SPDY to the proxy |
| 8490 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8491 | proxy.next_proto = kProtoHTTP2; |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8492 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
| 8493 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8494 | auto trans = |
| 8495 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8496 | TestCompletionCallback callback; |
| 8497 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8498 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8499 | |
| 8500 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8501 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8502 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8503 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8504 | ASSERT_TRUE(response); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8505 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8506 | |
| 8507 | EXPECT_EQ(200, response->headers->response_code()); |
| 8508 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8509 | |
| 8510 | std::string response_data; |
| 8511 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8512 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8513 | EXPECT_EQ("hello!", response_data); |
| 8514 | |
| 8515 | trans.reset(); |
| 8516 | session->CloseAllConnections(); |
| 8517 | } |
| 8518 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8519 | // Test HTTPS connections to a site with a bad certificate, going through an |
| 8520 | // HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8521 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8522 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8523 | |
| 8524 | HttpRequestInfo request; |
| 8525 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8526 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8527 | |
| 8528 | // Attempt to fetch the URL from a server with a bad cert |
| 8529 | MockWrite bad_cert_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8530 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8531 | "Host: www.example.org:443\r\n" |
| 8532 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8533 | }; |
| 8534 | |
| 8535 | MockRead bad_cert_reads[] = { |
| 8536 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8537 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8538 | }; |
| 8539 | |
| 8540 | // Attempt to fetch the URL with a good cert |
| 8541 | MockWrite good_data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8542 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8543 | "Host: www.example.org:443\r\n" |
| 8544 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 8545 | MockWrite("GET / HTTP/1.1\r\n" |
| 8546 | "Host: www.example.org\r\n" |
| 8547 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8548 | }; |
| 8549 | |
| 8550 | MockRead good_cert_reads[] = { |
| 8551 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 8552 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8553 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8554 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8555 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8556 | }; |
| 8557 | |
| 8558 | StaticSocketDataProvider ssl_bad_certificate( |
| 8559 | bad_cert_reads, arraysize(bad_cert_reads), |
| 8560 | bad_cert_writes, arraysize(bad_cert_writes)); |
| 8561 | StaticSocketDataProvider data(good_cert_reads, arraysize(good_cert_reads), |
| 8562 | good_data_writes, arraysize(good_data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8563 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 8564 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8565 | |
| 8566 | // SSL to the proxy, then CONNECT request, then SSL with bad certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8567 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 8568 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 8569 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8570 | |
| 8571 | // SSL to the proxy, then CONNECT request, then valid SSL certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8572 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 8573 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8574 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8575 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8576 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8577 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8578 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8579 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8580 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8581 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8582 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8583 | |
| 8584 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8585 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8586 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8587 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8588 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8589 | |
| 8590 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8591 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8592 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8593 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8594 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8595 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8596 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8597 | } |
| 8598 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8599 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8600 | HttpRequestInfo request; |
| 8601 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8602 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8603 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 8604 | "Chromium Ultra Awesome X Edition"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8605 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8606 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8607 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8608 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8609 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8610 | MockWrite( |
| 8611 | "GET / HTTP/1.1\r\n" |
| 8612 | "Host: www.example.org\r\n" |
| 8613 | "Connection: keep-alive\r\n" |
| 8614 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8615 | }; |
| 8616 | |
| 8617 | // Lastly, the server responds with the actual content. |
| 8618 | MockRead data_reads[] = { |
| 8619 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8620 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8621 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8622 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8623 | }; |
| 8624 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8625 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8626 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8627 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8628 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8629 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8630 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8631 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8632 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8633 | |
| 8634 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8635 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8636 | } |
| 8637 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8638 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8639 | HttpRequestInfo request; |
| 8640 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8641 | request.url = GURL("https://www.example.org/"); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8642 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 8643 | "Chromium Ultra Awesome X Edition"); |
| 8644 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8645 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8646 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8647 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8648 | |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8649 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8650 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8651 | "Host: www.example.org:443\r\n" |
| 8652 | "Proxy-Connection: keep-alive\r\n" |
| 8653 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8654 | }; |
| 8655 | MockRead data_reads[] = { |
| 8656 | // Return an error, so the transaction stops here (this test isn't |
| 8657 | // interested in the rest). |
| 8658 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 8659 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8660 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 8661 | }; |
| 8662 | |
| 8663 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8664 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8665 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8666 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8667 | TestCompletionCallback callback; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8668 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8669 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8670 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8671 | |
| 8672 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8673 | EXPECT_THAT(rv, IsOk()); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8674 | } |
| 8675 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8676 | TEST_F(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8677 | HttpRequestInfo request; |
| 8678 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8679 | request.url = GURL("http://www.example.org/"); |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 8680 | request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 8681 | "http://the.previous.site.com/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8682 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8683 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8684 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8685 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8686 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8687 | MockWrite( |
| 8688 | "GET / HTTP/1.1\r\n" |
| 8689 | "Host: www.example.org\r\n" |
| 8690 | "Connection: keep-alive\r\n" |
| 8691 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8692 | }; |
| 8693 | |
| 8694 | // Lastly, the server responds with the actual content. |
| 8695 | MockRead data_reads[] = { |
| 8696 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8697 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8698 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8699 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8700 | }; |
| 8701 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8702 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8703 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8704 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8705 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8706 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8707 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8708 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8709 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8710 | |
| 8711 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8712 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8713 | } |
| 8714 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8715 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8716 | HttpRequestInfo request; |
| 8717 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8718 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8719 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8720 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8721 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8722 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8723 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8724 | MockWrite( |
| 8725 | "POST / HTTP/1.1\r\n" |
| 8726 | "Host: www.example.org\r\n" |
| 8727 | "Connection: keep-alive\r\n" |
| 8728 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8729 | }; |
| 8730 | |
| 8731 | // Lastly, the server responds with the actual content. |
| 8732 | MockRead data_reads[] = { |
| 8733 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8734 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8735 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8736 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8737 | }; |
| 8738 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8739 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8740 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8741 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8742 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8743 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8744 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8745 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8746 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8747 | |
| 8748 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8749 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8750 | } |
| 8751 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8752 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8753 | HttpRequestInfo request; |
| 8754 | request.method = "PUT"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8755 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8756 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8757 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8758 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8759 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8760 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8761 | MockWrite( |
| 8762 | "PUT / HTTP/1.1\r\n" |
| 8763 | "Host: www.example.org\r\n" |
| 8764 | "Connection: keep-alive\r\n" |
| 8765 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8766 | }; |
| 8767 | |
| 8768 | // Lastly, the server responds with the actual content. |
| 8769 | MockRead data_reads[] = { |
| 8770 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8771 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8772 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8773 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8774 | }; |
| 8775 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8776 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8777 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8778 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8779 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8780 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8781 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8782 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8783 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8784 | |
| 8785 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8786 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8787 | } |
| 8788 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8789 | TEST_F(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8790 | HttpRequestInfo request; |
| 8791 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8792 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8793 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8794 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8795 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8796 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8797 | MockWrite data_writes[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 8798 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 8799 | "Host: www.example.org\r\n" |
| 8800 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8801 | }; |
| 8802 | |
| 8803 | // Lastly, the server responds with the actual content. |
| 8804 | MockRead data_reads[] = { |
| 8805 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8806 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8807 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8808 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8809 | }; |
| 8810 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8811 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8812 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8813 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8814 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8815 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8816 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8817 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8818 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8819 | |
| 8820 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8821 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8822 | } |
| 8823 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8824 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8825 | HttpRequestInfo request; |
| 8826 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8827 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8828 | request.load_flags = LOAD_BYPASS_CACHE; |
| 8829 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8830 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8831 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8832 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8833 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8834 | MockWrite( |
| 8835 | "GET / HTTP/1.1\r\n" |
| 8836 | "Host: www.example.org\r\n" |
| 8837 | "Connection: keep-alive\r\n" |
| 8838 | "Pragma: no-cache\r\n" |
| 8839 | "Cache-Control: no-cache\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8840 | }; |
| 8841 | |
| 8842 | // Lastly, the server responds with the actual content. |
| 8843 | MockRead data_reads[] = { |
| 8844 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8845 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8846 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8847 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8848 | }; |
| 8849 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8850 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8851 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8852 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8853 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8854 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8855 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8856 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8857 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8858 | |
| 8859 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8860 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8861 | } |
| 8862 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8863 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlValidateCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8864 | HttpRequestInfo request; |
| 8865 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8866 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8867 | request.load_flags = LOAD_VALIDATE_CACHE; |
| 8868 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8869 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8870 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8871 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8872 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8873 | MockWrite( |
| 8874 | "GET / HTTP/1.1\r\n" |
| 8875 | "Host: www.example.org\r\n" |
| 8876 | "Connection: keep-alive\r\n" |
| 8877 | "Cache-Control: max-age=0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8878 | }; |
| 8879 | |
| 8880 | // Lastly, the server responds with the actual content. |
| 8881 | MockRead data_reads[] = { |
| 8882 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8883 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8884 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8885 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8886 | }; |
| 8887 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8888 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8889 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8890 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8891 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8892 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8893 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8894 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8895 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8896 | |
| 8897 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8898 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8899 | } |
| 8900 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8901 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8902 | HttpRequestInfo request; |
| 8903 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8904 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8905 | request.extra_headers.SetHeader("FooHeader", "Bar"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8906 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8907 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8908 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8909 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8910 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8911 | MockWrite( |
| 8912 | "GET / HTTP/1.1\r\n" |
| 8913 | "Host: www.example.org\r\n" |
| 8914 | "Connection: keep-alive\r\n" |
| 8915 | "FooHeader: Bar\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8916 | }; |
| 8917 | |
| 8918 | // Lastly, the server responds with the actual content. |
| 8919 | MockRead data_reads[] = { |
| 8920 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8921 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8922 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8923 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8924 | }; |
| 8925 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8926 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8927 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8928 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8929 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8930 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8931 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8932 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8933 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8934 | |
| 8935 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8936 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8937 | } |
| 8938 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8939 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8940 | HttpRequestInfo request; |
| 8941 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8942 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8943 | request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 8944 | request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 8945 | request.extra_headers.SetHeader("FoO", "bar"); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8946 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8947 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8948 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8949 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8950 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8951 | MockWrite( |
| 8952 | "GET / HTTP/1.1\r\n" |
| 8953 | "Host: www.example.org\r\n" |
| 8954 | "Connection: keep-alive\r\n" |
| 8955 | "referer: www.foo.com\r\n" |
| 8956 | "hEllo: Kitty\r\n" |
| 8957 | "FoO: bar\r\n\r\n"), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8958 | }; |
| 8959 | |
| 8960 | // Lastly, the server responds with the actual content. |
| 8961 | MockRead data_reads[] = { |
| 8962 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8963 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8964 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8965 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8966 | }; |
| 8967 | |
| 8968 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8969 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8970 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8971 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8972 | TestCompletionCallback callback; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8973 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8974 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8975 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8976 | |
| 8977 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8978 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8979 | } |
| 8980 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8981 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8982 | HttpRequestInfo request; |
| 8983 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8984 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8985 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8986 | session_deps_.proxy_service = |
| 8987 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8988 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8989 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8990 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8991 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8992 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8993 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8994 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 8995 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 8996 | |
| 8997 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8998 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 8999 | MockWrite( |
| 9000 | "GET / HTTP/1.1\r\n" |
| 9001 | "Host: www.example.org\r\n" |
| 9002 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9003 | |
| 9004 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9005 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9006 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9007 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9008 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9009 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9010 | }; |
| 9011 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9012 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9013 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9014 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9015 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9016 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9017 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9018 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9019 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9020 | |
| 9021 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9022 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9023 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9024 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9025 | ASSERT_TRUE(response); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9026 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9027 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9028 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9029 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9030 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9031 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 9032 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9033 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9034 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9035 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9036 | EXPECT_EQ("Payload", response_text); |
| 9037 | } |
| 9038 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9039 | TEST_F(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9040 | HttpRequestInfo request; |
| 9041 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9042 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9043 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9044 | session_deps_.proxy_service = |
| 9045 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9046 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9047 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9048 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9049 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9050 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9051 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9052 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 9053 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 9054 | |
| 9055 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9056 | MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), |
| 9057 | arraysize(write_buffer)), |
| 9058 | MockWrite( |
| 9059 | "GET / HTTP/1.1\r\n" |
| 9060 | "Host: www.example.org\r\n" |
| 9061 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9062 | |
| 9063 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 9064 | MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), |
| 9065 | arraysize(read_buffer)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9066 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9067 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9068 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9069 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9070 | }; |
| 9071 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9072 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9073 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9074 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9075 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9076 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9077 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9078 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9079 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9080 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9081 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9082 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9083 | |
| 9084 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9085 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9086 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9087 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9088 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9089 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9090 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 9091 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9092 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9093 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9094 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9095 | |
| 9096 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9097 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9098 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9099 | EXPECT_EQ("Payload", response_text); |
| 9100 | } |
| 9101 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9102 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9103 | HttpRequestInfo request; |
| 9104 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9105 | request.url = GURL("http://www.example.org/"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9106 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9107 | session_deps_.proxy_service = |
| 9108 | ProxyService::CreateFixed("socks4://myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9109 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9110 | session_deps_.net_log = &net_log; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9111 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9112 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9113 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9114 | |
| 9115 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 9116 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 9117 | |
| 9118 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9119 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 9120 | MockWrite( |
| 9121 | "GET / HTTP/1.1\r\n" |
| 9122 | "Host: www.example.org\r\n" |
| 9123 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9124 | |
| 9125 | MockRead data_reads[] = { |
| 9126 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
| 9127 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9128 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9129 | MockRead("Payload"), |
| 9130 | MockRead(SYNCHRONOUS, OK) |
| 9131 | }; |
| 9132 | |
| 9133 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9134 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9135 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9136 | |
| 9137 | TestCompletionCallback callback; |
| 9138 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9139 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9140 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9141 | |
| 9142 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9143 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9144 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9145 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9146 | ASSERT_TRUE(response); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9147 | |
| 9148 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9149 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9150 | TestLoadTimingNotReused(load_timing_info, |
| 9151 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 9152 | |
| 9153 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9154 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9155 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9156 | EXPECT_EQ("Payload", response_text); |
| 9157 | } |
| 9158 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9159 | TEST_F(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9160 | HttpRequestInfo request; |
| 9161 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9162 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9163 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9164 | session_deps_.proxy_service = |
| 9165 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9166 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9167 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9168 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9169 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9170 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9171 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9172 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 9173 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9174 | const char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9175 | 0x05, // Version |
| 9176 | 0x01, // Command (CONNECT) |
| 9177 | 0x00, // Reserved. |
| 9178 | 0x03, // Address type (DOMAINNAME). |
| 9179 | 0x0F, // Length of domain (15) |
| 9180 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 9181 | '.', 'o', 'r', 'g', 0x00, 0x50, // 16-bit port (80) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9182 | }; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9183 | const char kSOCKS5OkResponse[] = |
| 9184 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 9185 | |
| 9186 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9187 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 9188 | MockWrite(ASYNC, kSOCKS5OkRequest, arraysize(kSOCKS5OkRequest)), |
| 9189 | MockWrite( |
| 9190 | "GET / HTTP/1.1\r\n" |
| 9191 | "Host: www.example.org\r\n" |
| 9192 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9193 | |
| 9194 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 9195 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 9196 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9197 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9198 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9199 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9200 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9201 | }; |
| 9202 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9203 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9204 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9205 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9206 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9207 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9208 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9209 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9210 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9211 | |
| 9212 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9213 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9214 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9215 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9216 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9217 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9218 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9219 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9220 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9221 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9222 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 9223 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9224 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9225 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9226 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9227 | EXPECT_EQ("Payload", response_text); |
| 9228 | } |
| 9229 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9230 | TEST_F(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9231 | HttpRequestInfo request; |
| 9232 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9233 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9234 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9235 | session_deps_.proxy_service = |
| 9236 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9237 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9238 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9239 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9240 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9241 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9242 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9243 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 9244 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9245 | const unsigned char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9246 | 0x05, // Version |
| 9247 | 0x01, // Command (CONNECT) |
| 9248 | 0x00, // Reserved. |
| 9249 | 0x03, // Address type (DOMAINNAME). |
| 9250 | 0x0F, // Length of domain (15) |
| 9251 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 9252 | '.', 'o', 'r', 'g', 0x01, 0xBB, // 16-bit port (443) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9253 | }; |
| 9254 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9255 | const char kSOCKS5OkResponse[] = |
| 9256 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 9257 | |
| 9258 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9259 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 9260 | MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
| 9261 | arraysize(kSOCKS5OkRequest)), |
| 9262 | MockWrite( |
| 9263 | "GET / HTTP/1.1\r\n" |
| 9264 | "Host: www.example.org\r\n" |
| 9265 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9266 | |
| 9267 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 9268 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 9269 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9270 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9271 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9272 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9273 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9274 | }; |
| 9275 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9276 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9277 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9278 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9279 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9280 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9281 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9282 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9283 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9284 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9285 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9286 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9287 | |
| 9288 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9289 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9290 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9291 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9292 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9293 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9294 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9295 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9296 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9297 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9298 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 9299 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9300 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9301 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9302 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9303 | EXPECT_EQ("Payload", response_text); |
| 9304 | } |
| 9305 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9306 | namespace { |
| 9307 | |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9308 | // Tests that for connection endpoints the group names are correctly set. |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9309 | |
| 9310 | struct GroupNameTest { |
| 9311 | std::string proxy_server; |
| 9312 | std::string url; |
| 9313 | std::string expected_group_name; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9314 | bool ssl; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9315 | }; |
| 9316 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9317 | std::unique_ptr<HttpNetworkSession> SetupSessionForGroupNameTests( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9318 | SpdySessionDependencies* session_deps_) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9319 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9320 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 9321 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9322 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 9323 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9324 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 9325 | http_server_properties->SetHttp2AlternativeService( |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9326 | url::SchemeHostPort("https", "host.with.alternate", 443), |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 9327 | alternative_service, expiration); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9328 | |
| 9329 | return session; |
| 9330 | } |
| 9331 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9332 | int GroupNameTransactionHelper(const std::string& url, |
| 9333 | HttpNetworkSession* session) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9334 | HttpRequestInfo request; |
| 9335 | request.method = "GET"; |
| 9336 | request.url = GURL(url); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9337 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9338 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9339 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9340 | TestCompletionCallback callback; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9341 | |
| 9342 | // We do not complete this request, the dtor will clean the transaction up. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9343 | return trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9344 | } |
| 9345 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9346 | } // namespace |
| 9347 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9348 | TEST_F(HttpNetworkTransactionTest, GroupNameForDirectConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9349 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9350 | { |
| 9351 | "", // unused |
| 9352 | "http://www.example.org/direct", |
| 9353 | "www.example.org:80", |
| 9354 | false, |
| 9355 | }, |
| 9356 | { |
| 9357 | "", // unused |
| 9358 | "http://[2001:1418:13:1::25]/direct", |
| 9359 | "[2001:1418:13:1::25]:80", |
| 9360 | false, |
| 9361 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9362 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9363 | // SSL Tests |
| 9364 | { |
| 9365 | "", // unused |
| 9366 | "https://www.example.org/direct_ssl", |
| 9367 | "ssl/www.example.org:443", |
| 9368 | true, |
| 9369 | }, |
| 9370 | { |
| 9371 | "", // unused |
| 9372 | "https://[2001:1418:13:1::25]/direct", |
| 9373 | "ssl/[2001:1418:13:1::25]:443", |
| 9374 | true, |
| 9375 | }, |
| 9376 | { |
| 9377 | "", // unused |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9378 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9379 | "ssl/host.with.alternate:443", |
| 9380 | true, |
| 9381 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9382 | }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9383 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 9384 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9385 | session_deps_.proxy_service = |
| 9386 | ProxyService::CreateFixed(tests[i].proxy_server); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9387 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 9388 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9389 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9390 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9391 | CaptureGroupNameTransportSocketPool* transport_conn_pool = |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9392 | new CaptureGroupNameTransportSocketPool(nullptr, nullptr); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9393 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9394 | new CaptureGroupNameSSLSocketPool(nullptr, nullptr); |
| 9395 | auto mock_pool_manager = base::MakeUnique<MockClientSocketPoolManager>(); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 9396 | mock_pool_manager->SetTransportSocketPool(transport_conn_pool); |
| 9397 | mock_pool_manager->SetSSLSocketPool(ssl_conn_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 9398 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9399 | |
| 9400 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9401 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9402 | if (tests[i].ssl) |
| 9403 | EXPECT_EQ(tests[i].expected_group_name, |
| 9404 | ssl_conn_pool->last_group_name_received()); |
| 9405 | else |
| 9406 | EXPECT_EQ(tests[i].expected_group_name, |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9407 | transport_conn_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9408 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9409 | } |
| 9410 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9411 | TEST_F(HttpNetworkTransactionTest, GroupNameForHTTPProxyConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9412 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9413 | { |
| 9414 | "http_proxy", |
| 9415 | "http://www.example.org/http_proxy_normal", |
| 9416 | "www.example.org:80", |
| 9417 | false, |
| 9418 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9419 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9420 | // SSL Tests |
| 9421 | { |
| 9422 | "http_proxy", |
| 9423 | "https://www.example.org/http_connect_ssl", |
| 9424 | "ssl/www.example.org:443", |
| 9425 | true, |
| 9426 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 9427 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9428 | { |
| 9429 | "http_proxy", |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9430 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9431 | "ssl/host.with.alternate:443", |
| 9432 | true, |
| 9433 | }, |
[email protected] | 4549925 | 2013-01-23 17:12:56 | [diff] [blame] | 9434 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9435 | { |
| 9436 | "http_proxy", |
| 9437 | "ftp://ftp.google.com/http_proxy_normal", |
| 9438 | "ftp/ftp.google.com:21", |
| 9439 | false, |
| 9440 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9441 | }; |
| 9442 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 9443 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9444 | session_deps_.proxy_service = |
| 9445 | ProxyService::CreateFixed(tests[i].proxy_server); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9446 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 9447 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9448 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9449 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9450 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9451 | HostPortPair proxy_host("http_proxy", 80); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9452 | CaptureGroupNameHttpProxySocketPool* http_proxy_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9453 | new CaptureGroupNameHttpProxySocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9454 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9455 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9456 | auto mock_pool_manager = base::MakeUnique<MockClientSocketPoolManager>(); |
avi | adef344 | 2016-10-03 18:50:39 | [diff] [blame] | 9457 | mock_pool_manager->SetSocketPoolForHTTPProxy( |
| 9458 | proxy_host, base::WrapUnique(http_proxy_pool)); |
| 9459 | mock_pool_manager->SetSocketPoolForSSLWithProxy( |
| 9460 | proxy_host, base::WrapUnique(ssl_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 9461 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9462 | |
| 9463 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9464 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9465 | if (tests[i].ssl) |
| 9466 | EXPECT_EQ(tests[i].expected_group_name, |
| 9467 | ssl_conn_pool->last_group_name_received()); |
| 9468 | else |
| 9469 | EXPECT_EQ(tests[i].expected_group_name, |
| 9470 | http_proxy_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9471 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9472 | } |
| 9473 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9474 | TEST_F(HttpNetworkTransactionTest, GroupNameForSOCKSConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9475 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9476 | { |
| 9477 | "socks4://socks_proxy:1080", |
| 9478 | "http://www.example.org/socks4_direct", |
| 9479 | "socks4/www.example.org:80", |
| 9480 | false, |
| 9481 | }, |
| 9482 | { |
| 9483 | "socks5://socks_proxy:1080", |
| 9484 | "http://www.example.org/socks5_direct", |
| 9485 | "socks5/www.example.org:80", |
| 9486 | false, |
| 9487 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9488 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9489 | // SSL Tests |
| 9490 | { |
| 9491 | "socks4://socks_proxy:1080", |
| 9492 | "https://www.example.org/socks4_ssl", |
| 9493 | "socks4/ssl/www.example.org:443", |
| 9494 | true, |
| 9495 | }, |
| 9496 | { |
| 9497 | "socks5://socks_proxy:1080", |
| 9498 | "https://www.example.org/socks5_ssl", |
| 9499 | "socks5/ssl/www.example.org:443", |
| 9500 | true, |
| 9501 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 9502 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9503 | { |
| 9504 | "socks4://socks_proxy:1080", |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9505 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9506 | "socks4/ssl/host.with.alternate:443", |
| 9507 | true, |
| 9508 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9509 | }; |
| 9510 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 9511 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9512 | session_deps_.proxy_service = |
| 9513 | ProxyService::CreateFixed(tests[i].proxy_server); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9514 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 9515 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 9516 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9517 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9518 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9519 | HostPortPair proxy_host("socks_proxy", 1080); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9520 | CaptureGroupNameSOCKSSocketPool* socks_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9521 | new CaptureGroupNameSOCKSSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9522 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9523 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9524 | auto mock_pool_manager = base::MakeUnique<MockClientSocketPoolManager>(); |
avi | adef344 | 2016-10-03 18:50:39 | [diff] [blame] | 9525 | mock_pool_manager->SetSocketPoolForSOCKSProxy( |
| 9526 | proxy_host, base::WrapUnique(socks_conn_pool)); |
| 9527 | mock_pool_manager->SetSocketPoolForSSLWithProxy( |
| 9528 | proxy_host, base::WrapUnique(ssl_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 9529 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9530 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9531 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9532 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9533 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9534 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9535 | if (tests[i].ssl) |
| 9536 | EXPECT_EQ(tests[i].expected_group_name, |
| 9537 | ssl_conn_pool->last_group_name_received()); |
| 9538 | else |
| 9539 | EXPECT_EQ(tests[i].expected_group_name, |
| 9540 | socks_conn_pool->last_group_name_received()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9541 | } |
| 9542 | } |
| 9543 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9544 | TEST_F(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9545 | HttpRequestInfo request; |
| 9546 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9547 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9548 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9549 | session_deps_.proxy_service = |
| 9550 | ProxyService::CreateFixed("myproxy:70;foobar:80"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 9551 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 9552 | // This simulates failure resolving all hostnames; that means we will fail |
| 9553 | // connecting to both proxies (myproxy:70 and foobar:80). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9554 | session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 9555 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9556 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9557 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9558 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9559 | TestCompletionCallback callback; |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9560 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9561 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9562 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9563 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9564 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9565 | EXPECT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9566 | } |
| 9567 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9568 | // Base test to make sure that when the load flags for a request specify to |
| 9569 | // bypass the cache, the DNS cache is not used. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9570 | void HttpNetworkTransactionTest::BypassHostCacheOnRefreshHelper( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9571 | int load_flags) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9572 | // Issue a request, asking to bypass the cache(s). |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9573 | HttpRequestInfo request_info; |
| 9574 | request_info.method = "GET"; |
| 9575 | request_info.load_flags = load_flags; |
| 9576 | request_info.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9577 | |
[email protected] | a2c2fb9 | 2009-07-18 07:31:04 | [diff] [blame] | 9578 | // Select a host resolver that does caching. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9579 | session_deps_.host_resolver = base::MakeUnique<MockCachingHostResolver>(); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 9580 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9581 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9582 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9583 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9584 | // 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] | 9585 | AddressList addrlist; |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 9586 | TestCompletionCallback callback; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9587 | std::unique_ptr<HostResolver::Request> request1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9588 | int rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9589 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9590 | DEFAULT_PRIORITY, &addrlist, callback.callback(), &request1, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9591 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9592 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 9593 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9594 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9595 | |
| 9596 | // Verify that it was added to host cache, by doing a subsequent async lookup |
| 9597 | // and confirming it completes synchronously. |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9598 | std::unique_ptr<HostResolver::Request> request2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9599 | rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9600 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9601 | DEFAULT_PRIORITY, &addrlist, callback.callback(), &request2, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9602 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9603 | ASSERT_THAT(rv, IsOk()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9604 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9605 | // 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] | 9606 | // we can tell if the next lookup hit the cache, or the "network". |
| 9607 | // (cache --> success, "network" --> failure). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9608 | session_deps_.host_resolver->rules()->AddSimulatedFailure("www.example.org"); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9609 | |
| 9610 | // Connect up a mock socket which will fail with ERR_UNEXPECTED during the |
| 9611 | // 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] | 9612 | MockRead data_reads[] = { MockRead(SYNCHRONOUS, ERR_UNEXPECTED) }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9613 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9614 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9615 | |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9616 | // Run the request. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9617 | rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9618 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9619 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9620 | |
| 9621 | // If we bypassed the cache, we would have gotten a failure while resolving |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9622 | // "www.example.org". |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9623 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9624 | } |
| 9625 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9626 | // There are multiple load flags that should trigger the host cache bypass. |
| 9627 | // Test each in isolation: |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9628 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh1) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9629 | BypassHostCacheOnRefreshHelper(LOAD_BYPASS_CACHE); |
| 9630 | } |
| 9631 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9632 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh2) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9633 | BypassHostCacheOnRefreshHelper(LOAD_VALIDATE_CACHE); |
| 9634 | } |
| 9635 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9636 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh3) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9637 | BypassHostCacheOnRefreshHelper(LOAD_DISABLE_CACHE); |
| 9638 | } |
| 9639 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9640 | // Make sure we can handle an error when writing the request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9641 | TEST_F(HttpNetworkTransactionTest, RequestWriteError) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9642 | HttpRequestInfo request; |
| 9643 | request.method = "GET"; |
| 9644 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9645 | |
| 9646 | MockWrite write_failure[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9647 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9648 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9649 | StaticSocketDataProvider data(NULL, 0, |
| 9650 | write_failure, arraysize(write_failure)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9651 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9652 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9653 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9654 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9655 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9656 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9657 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9658 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9659 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9660 | |
| 9661 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9662 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9663 | |
| 9664 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9665 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9666 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9667 | } |
| 9668 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9669 | // Check that a connection closed after the start of the headers finishes ok. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9670 | TEST_F(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9671 | HttpRequestInfo request; |
| 9672 | request.method = "GET"; |
| 9673 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9674 | |
| 9675 | MockRead data_reads[] = { |
| 9676 | MockRead("HTTP/1."), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9677 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9678 | }; |
| 9679 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9680 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9681 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9682 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9683 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9684 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9685 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9686 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9687 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9688 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9689 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9690 | |
| 9691 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9692 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9693 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9694 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9695 | ASSERT_TRUE(response); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9696 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9697 | EXPECT_TRUE(response->headers); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9698 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 9699 | |
| 9700 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9701 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9702 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9703 | EXPECT_EQ("", response_data); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9704 | |
| 9705 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9706 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9707 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9708 | } |
| 9709 | |
| 9710 | // Make sure that a dropped connection while draining the body for auth |
| 9711 | // restart does the right thing. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9712 | TEST_F(HttpNetworkTransactionTest, DrainResetOK) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9713 | HttpRequestInfo request; |
| 9714 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9715 | request.url = GURL("http://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9716 | |
| 9717 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9718 | MockWrite( |
| 9719 | "GET / HTTP/1.1\r\n" |
| 9720 | "Host: www.example.org\r\n" |
| 9721 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9722 | }; |
| 9723 | |
| 9724 | MockRead data_reads1[] = { |
| 9725 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 9726 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9727 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9728 | MockRead("Content-Length: 14\r\n\r\n"), |
| 9729 | MockRead("Unauth"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9730 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9731 | }; |
| 9732 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9733 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 9734 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9735 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9736 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9737 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9738 | // be issuing -- the final header line contains the credentials. |
| 9739 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9740 | MockWrite( |
| 9741 | "GET / HTTP/1.1\r\n" |
| 9742 | "Host: www.example.org\r\n" |
| 9743 | "Connection: keep-alive\r\n" |
| 9744 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9745 | }; |
| 9746 | |
| 9747 | // Lastly, the server responds with the actual content. |
| 9748 | MockRead data_reads2[] = { |
| 9749 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9750 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9751 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9752 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9753 | }; |
| 9754 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9755 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 9756 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9757 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9758 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9759 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9760 | TestCompletionCallback callback1; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9761 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9762 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9763 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9764 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9765 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9766 | |
| 9767 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9768 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9769 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9770 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9771 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9772 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9773 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9774 | TestCompletionCallback callback2; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9775 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9776 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9777 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9778 | |
| 9779 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9780 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9781 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9782 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9783 | ASSERT_TRUE(response); |
| 9784 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9785 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9786 | } |
| 9787 | |
| 9788 | // Test HTTPS connections going through a proxy that sends extra data. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9789 | TEST_F(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9790 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9791 | |
| 9792 | HttpRequestInfo request; |
| 9793 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9794 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9795 | |
| 9796 | MockRead proxy_reads[] = { |
| 9797 | MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9798 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9799 | }; |
| 9800 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9801 | StaticSocketDataProvider data(proxy_reads, arraysize(proxy_reads), NULL, 0); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9802 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9803 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9804 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9805 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9806 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9807 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9808 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9809 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9810 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9811 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9812 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9813 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9814 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9815 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9816 | |
| 9817 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9818 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9819 | } |
| 9820 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9821 | TEST_F(HttpNetworkTransactionTest, LargeContentLengthThenClose) { |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9822 | HttpRequestInfo request; |
| 9823 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9824 | request.url = GURL("http://www.example.org/"); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9825 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9826 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9827 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9828 | |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 9829 | MockRead data_reads[] = { |
| 9830 | 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] | 9831 | MockRead(SYNCHRONOUS, OK), |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 9832 | }; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9833 | |
| 9834 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9835 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9836 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9837 | TestCompletionCallback callback; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9838 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9839 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9840 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9841 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9842 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9843 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9844 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9845 | ASSERT_TRUE(response); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9846 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9847 | EXPECT_TRUE(response->headers); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9848 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 9849 | |
| 9850 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9851 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9852 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 9853 | } |
| 9854 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9855 | TEST_F(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 9856 | base::FilePath temp_file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 9857 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path)); |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 9858 | const uint64_t kFakeSize = 100000; // file is actually blank |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 9859 | UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 9860 | overriding_content_length(kFakeSize); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9861 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9862 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 9863 | element_readers.push_back(base::MakeUnique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 9864 | base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 9865 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9866 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9867 | |
| 9868 | HttpRequestInfo request; |
| 9869 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9870 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9871 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9872 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9873 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9874 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9875 | |
| 9876 | MockRead data_reads[] = { |
| 9877 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 9878 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9879 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9880 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9881 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9882 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9883 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9884 | TestCompletionCallback callback; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9885 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9886 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9887 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9888 | |
| 9889 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9890 | EXPECT_THAT(rv, IsError(ERR_UPLOAD_FILE_CHANGED)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9891 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9892 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9893 | ASSERT_TRUE(response); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9894 | |
maksim.sisov | e869bf5 | 2016-06-23 17:11:52 | [diff] [blame] | 9895 | EXPECT_FALSE(response->headers); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9896 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 9897 | base::DeleteFile(temp_file_path, false); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9898 | } |
| 9899 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9900 | TEST_F(HttpNetworkTransactionTest, UploadUnreadableFile) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 9901 | base::FilePath temp_file; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 9902 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9903 | std::string temp_file_content("Unreadable file."); |
lazyboy | 8df84fc | 2017-04-12 02:12:48 | [diff] [blame] | 9904 | ASSERT_EQ(static_cast<int>(temp_file_content.length()), |
| 9905 | base::WriteFile(temp_file, temp_file_content.c_str(), |
| 9906 | temp_file_content.length())); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 9907 | ASSERT_TRUE(base::MakeFileUnreadable(temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9908 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9909 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 9910 | element_readers.push_back(base::MakeUnique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 9911 | base::ThreadTaskRunnerHandle::Get().get(), temp_file, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 9912 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9913 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9914 | |
| 9915 | HttpRequestInfo request; |
| 9916 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9917 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9918 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9919 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 9920 | // If we try to upload an unreadable file, the transaction should fail. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9921 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9922 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9923 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 9924 | StaticSocketDataProvider data(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9925 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9926 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9927 | TestCompletionCallback callback; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9928 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9929 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9930 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9931 | |
| 9932 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9933 | EXPECT_THAT(rv, IsError(ERR_ACCESS_DENIED)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9934 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 9935 | base::DeleteFile(temp_file, false); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9936 | } |
| 9937 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9938 | TEST_F(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9939 | class FakeUploadElementReader : public UploadElementReader { |
| 9940 | public: |
| 9941 | FakeUploadElementReader() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9942 | ~FakeUploadElementReader() override {} |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9943 | |
| 9944 | const CompletionCallback& callback() const { return callback_; } |
| 9945 | |
| 9946 | // UploadElementReader overrides: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9947 | int Init(const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9948 | callback_ = callback; |
| 9949 | return ERR_IO_PENDING; |
| 9950 | } |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 9951 | uint64_t GetContentLength() const override { return 0; } |
| 9952 | uint64_t BytesRemaining() const override { return 0; } |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9953 | int Read(IOBuffer* buf, |
| 9954 | int buf_length, |
| 9955 | const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9956 | return ERR_FAILED; |
| 9957 | } |
| 9958 | |
| 9959 | private: |
| 9960 | CompletionCallback callback_; |
| 9961 | }; |
| 9962 | |
| 9963 | FakeUploadElementReader* fake_reader = new FakeUploadElementReader; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9964 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
| 9965 | element_readers.push_back(base::WrapUnique(fake_reader)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9966 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9967 | |
| 9968 | HttpRequestInfo request; |
| 9969 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9970 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9971 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9972 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9973 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9974 | auto trans = |
| 9975 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9976 | |
| 9977 | StaticSocketDataProvider data; |
| 9978 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9979 | |
| 9980 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9981 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9982 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 9983 | base::RunLoop().RunUntilIdle(); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9984 | |
| 9985 | // Transaction is pending on request body initialization. |
| 9986 | ASSERT_FALSE(fake_reader->callback().is_null()); |
| 9987 | |
| 9988 | // Return Init()'s result after the transaction gets destroyed. |
| 9989 | trans.reset(); |
| 9990 | fake_reader->callback().Run(OK); // Should not crash. |
| 9991 | } |
| 9992 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9993 | // Tests that changes to Auth realms are treated like auth rejections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9994 | TEST_F(HttpNetworkTransactionTest, ChangeAuthRealms) { |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9995 | HttpRequestInfo request; |
| 9996 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9997 | request.url = GURL("http://www.example.org/"); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9998 | |
| 9999 | // First transaction will request a resource and receive a Basic challenge |
| 10000 | // with realm="first_realm". |
| 10001 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10002 | MockWrite( |
| 10003 | "GET / HTTP/1.1\r\n" |
| 10004 | "Host: www.example.org\r\n" |
| 10005 | "Connection: keep-alive\r\n" |
| 10006 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10007 | }; |
| 10008 | MockRead data_reads1[] = { |
| 10009 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 10010 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 10011 | "\r\n"), |
| 10012 | }; |
| 10013 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10014 | // After calling trans.RestartWithAuth(), provide an Authentication header |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10015 | // for first_realm. The server will reject and provide a challenge with |
| 10016 | // second_realm. |
| 10017 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10018 | MockWrite( |
| 10019 | "GET / HTTP/1.1\r\n" |
| 10020 | "Host: www.example.org\r\n" |
| 10021 | "Connection: keep-alive\r\n" |
| 10022 | "Authorization: Basic Zmlyc3Q6YmF6\r\n" |
| 10023 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10024 | }; |
| 10025 | MockRead data_reads2[] = { |
| 10026 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 10027 | "WWW-Authenticate: Basic realm=\"second_realm\"\r\n" |
| 10028 | "\r\n"), |
| 10029 | }; |
| 10030 | |
| 10031 | // This again fails, and goes back to first_realm. Make sure that the |
| 10032 | // entry is removed from cache. |
| 10033 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10034 | MockWrite( |
| 10035 | "GET / HTTP/1.1\r\n" |
| 10036 | "Host: www.example.org\r\n" |
| 10037 | "Connection: keep-alive\r\n" |
| 10038 | "Authorization: Basic c2Vjb25kOmZvdQ==\r\n" |
| 10039 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10040 | }; |
| 10041 | MockRead data_reads3[] = { |
| 10042 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 10043 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 10044 | "\r\n"), |
| 10045 | }; |
| 10046 | |
| 10047 | // Try one last time (with the correct password) and get the resource. |
| 10048 | MockWrite data_writes4[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10049 | MockWrite( |
| 10050 | "GET / HTTP/1.1\r\n" |
| 10051 | "Host: www.example.org\r\n" |
| 10052 | "Connection: keep-alive\r\n" |
| 10053 | "Authorization: Basic Zmlyc3Q6YmFy\r\n" |
| 10054 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10055 | }; |
| 10056 | MockRead data_reads4[] = { |
| 10057 | MockRead("HTTP/1.1 200 OK\r\n" |
| 10058 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10059 | "Content-Length: 5\r\n" |
| 10060 | "\r\n" |
| 10061 | "hello"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10062 | }; |
| 10063 | |
| 10064 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 10065 | data_writes1, arraysize(data_writes1)); |
| 10066 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 10067 | data_writes2, arraysize(data_writes2)); |
| 10068 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 10069 | data_writes3, arraysize(data_writes3)); |
| 10070 | StaticSocketDataProvider data4(data_reads4, arraysize(data_reads4), |
| 10071 | data_writes4, arraysize(data_writes4)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10072 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 10073 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 10074 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 10075 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10076 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10077 | TestCompletionCallback callback1; |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10078 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10079 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10080 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10081 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10082 | // Issue the first request with Authorize headers. There should be a |
| 10083 | // password prompt for first_realm waiting to be filled in after the |
| 10084 | // transaction completes. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10085 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10086 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10087 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10088 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10089 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10090 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10091 | const AuthChallengeInfo* challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10092 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10093 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10094 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10095 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 10096 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10097 | |
| 10098 | // Issue the second request with an incorrect password. There should be a |
| 10099 | // password prompt for second_realm waiting to be filled in after the |
| 10100 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10101 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10102 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBaz), |
| 10103 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10104 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10105 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10106 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10107 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10108 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10109 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10110 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10111 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10112 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10113 | EXPECT_EQ("second_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 10114 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10115 | |
| 10116 | // Issue the third request with another incorrect password. There should be |
| 10117 | // a password prompt for first_realm waiting to be filled in. If the password |
| 10118 | // prompt is not present, it indicates that the HttpAuthCacheEntry for |
| 10119 | // first_realm was not correctly removed. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10120 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10121 | rv = trans.RestartWithAuth(AuthCredentials(kSecond, kFou), |
| 10122 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10123 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10124 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10125 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10126 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10127 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10128 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10129 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10130 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10131 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10132 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 10133 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10134 | |
| 10135 | // Issue the fourth request with the correct password and username. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10136 | TestCompletionCallback callback4; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10137 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBar), |
| 10138 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10139 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10140 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10141 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10142 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10143 | ASSERT_TRUE(response); |
| 10144 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10145 | } |
| 10146 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10147 | TEST_F(HttpNetworkTransactionTest, HonorAlternativeServiceHeader) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10148 | MockRead data_reads[] = { |
| 10149 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10150 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10151 | MockRead("\r\n"), |
| 10152 | MockRead("hello world"), |
| 10153 | MockRead(SYNCHRONOUS, OK), |
| 10154 | }; |
| 10155 | |
| 10156 | HttpRequestInfo request; |
| 10157 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10158 | request.url = GURL("https://www.example.org/"); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10159 | |
| 10160 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10161 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10162 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10163 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10164 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10165 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10166 | TestCompletionCallback callback; |
| 10167 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10168 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10169 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10170 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10171 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10172 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10173 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10174 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10175 | HttpServerProperties* http_server_properties = |
| 10176 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10177 | EXPECT_TRUE( |
| 10178 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10179 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10180 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10181 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10182 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10183 | ASSERT_TRUE(response); |
| 10184 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10185 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10186 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10187 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10188 | |
| 10189 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10190 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10191 | EXPECT_EQ("hello world", response_data); |
| 10192 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10193 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 10194 | http_server_properties->GetAlternativeServiceInfos(test_server); |
| 10195 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 10196 | AlternativeService alternative_service(kProtoHTTP2, "mail.example.org", 443); |
| 10197 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 10198 | alternative_service_info_vector[0].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10199 | } |
| 10200 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10201 | // Regression test for https://crbug.com/615497. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10202 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10203 | DoNotParseAlternativeServiceHeaderOnInsecureRequest) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10204 | MockRead data_reads[] = { |
| 10205 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10206 | MockRead(kAlternativeServiceHttpHeader), |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10207 | MockRead("\r\n"), |
| 10208 | MockRead("hello world"), |
| 10209 | MockRead(SYNCHRONOUS, OK), |
| 10210 | }; |
| 10211 | |
| 10212 | HttpRequestInfo request; |
| 10213 | request.method = "GET"; |
| 10214 | request.url = GURL("http://www.example.org/"); |
| 10215 | request.load_flags = 0; |
| 10216 | |
| 10217 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 10218 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10219 | |
| 10220 | TestCompletionCallback callback; |
| 10221 | |
| 10222 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10223 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10224 | |
| 10225 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10226 | HttpServerProperties* http_server_properties = |
| 10227 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10228 | EXPECT_TRUE( |
| 10229 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10230 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10231 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10232 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10233 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10234 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10235 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10236 | ASSERT_TRUE(response); |
| 10237 | ASSERT_TRUE(response->headers); |
| 10238 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10239 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10240 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10241 | |
| 10242 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10243 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10244 | EXPECT_EQ("hello world", response_data); |
| 10245 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10246 | EXPECT_TRUE( |
| 10247 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10248 | } |
| 10249 | |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 10250 | // HTTP/2 Alternative Services should be disabled by default. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10251 | // TODO(bnc): Remove when https://crbug.com/615413 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10252 | TEST_F(HttpNetworkTransactionTest, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10253 | DisableHTTP2AlternativeServicesWithDifferentHost) { |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 10254 | session_deps_.enable_http2_alternative_service = false; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10255 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10256 | HttpRequestInfo request; |
| 10257 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10258 | request.url = GURL("https://www.example.org/"); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10259 | request.load_flags = 0; |
| 10260 | |
| 10261 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10262 | StaticSocketDataProvider first_data; |
| 10263 | first_data.set_connect_data(mock_connect); |
| 10264 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10265 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10266 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10267 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10268 | |
| 10269 | MockRead data_reads[] = { |
| 10270 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 10271 | MockRead(ASYNC, OK), |
| 10272 | }; |
| 10273 | StaticSocketDataProvider second_data(data_reads, arraysize(data_reads), NULL, |
| 10274 | 0); |
| 10275 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 10276 | |
| 10277 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10278 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10279 | HttpServerProperties* http_server_properties = |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10280 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10281 | AlternativeService alternative_service(kProtoHTTP2, "different.example.org", |
| 10282 | 444); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10283 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10284 | http_server_properties->SetHttp2AlternativeService( |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10285 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 10286 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10287 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10288 | TestCompletionCallback callback; |
| 10289 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10290 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10291 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10292 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10293 | } |
| 10294 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10295 | // Regression test for https://crbug.com/615497: |
| 10296 | // Alternative Services should be disabled for http origin. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10297 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10298 | DisableAlternativeServicesForInsecureOrigin) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10299 | HttpRequestInfo request; |
| 10300 | request.method = "GET"; |
| 10301 | request.url = GURL("http://www.example.org/"); |
| 10302 | request.load_flags = 0; |
| 10303 | |
| 10304 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10305 | StaticSocketDataProvider first_data; |
| 10306 | first_data.set_connect_data(mock_connect); |
| 10307 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
| 10308 | |
| 10309 | MockRead data_reads[] = { |
| 10310 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 10311 | MockRead(ASYNC, OK), |
| 10312 | }; |
| 10313 | StaticSocketDataProvider second_data(data_reads, arraysize(data_reads), NULL, |
| 10314 | 0); |
| 10315 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 10316 | |
| 10317 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10318 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10319 | HttpServerProperties* http_server_properties = |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10320 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10321 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10322 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10323 | http_server_properties->SetHttp2AlternativeService( |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10324 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 10325 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10326 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10327 | TestCompletionCallback callback; |
| 10328 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10329 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10330 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10331 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10332 | } |
| 10333 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10334 | TEST_F(HttpNetworkTransactionTest, ClearAlternativeServices) { |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10335 | // Set an alternative service for origin. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10336 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10337 | HttpServerProperties* http_server_properties = |
| 10338 | session->http_server_properties(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10339 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10340 | AlternativeService alternative_service(kProtoQUIC, "", 80); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10341 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10342 | http_server_properties->SetQuicAlternativeService( |
| 10343 | test_server, alternative_service, expiration, |
| 10344 | session->params().quic_supported_versions); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10345 | EXPECT_EQ( |
| 10346 | 1u, |
| 10347 | http_server_properties->GetAlternativeServiceInfos(test_server).size()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10348 | |
| 10349 | // Send a clear header. |
| 10350 | MockRead data_reads[] = { |
| 10351 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10352 | MockRead("Alt-Svc: clear\r\n"), |
| 10353 | MockRead("\r\n"), |
| 10354 | MockRead("hello world"), |
| 10355 | MockRead(SYNCHRONOUS, OK), |
| 10356 | }; |
| 10357 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 10358 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10359 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10360 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10361 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10362 | |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10363 | HttpRequestInfo request; |
| 10364 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10365 | request.url = GURL("https://www.example.org/"); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10366 | |
| 10367 | TestCompletionCallback callback; |
| 10368 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10369 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10370 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10371 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10372 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10373 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10374 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10375 | ASSERT_TRUE(response); |
| 10376 | ASSERT_TRUE(response->headers); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10377 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10378 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10379 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10380 | |
| 10381 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10382 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10383 | EXPECT_EQ("hello world", response_data); |
| 10384 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10385 | EXPECT_TRUE( |
| 10386 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10387 | } |
| 10388 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10389 | TEST_F(HttpNetworkTransactionTest, HonorMultipleAlternativeServiceHeaders) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10390 | MockRead data_reads[] = { |
| 10391 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10392 | MockRead("Alt-Svc: h2=\"www.example.com:443\","), |
| 10393 | MockRead("h2=\":1234\"\r\n\r\n"), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10394 | MockRead("hello world"), |
| 10395 | MockRead(SYNCHRONOUS, OK), |
| 10396 | }; |
| 10397 | |
| 10398 | HttpRequestInfo request; |
| 10399 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10400 | request.url = GURL("https://www.example.org/"); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10401 | |
| 10402 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10403 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10404 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10405 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10406 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10407 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10408 | TestCompletionCallback callback; |
| 10409 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10410 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10411 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10412 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10413 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10414 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10415 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10416 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10417 | HttpServerProperties* http_server_properties = |
| 10418 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10419 | EXPECT_TRUE( |
| 10420 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10421 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10422 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10423 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10424 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10425 | ASSERT_TRUE(response); |
| 10426 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10427 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10428 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10429 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10430 | |
| 10431 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10432 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10433 | EXPECT_EQ("hello world", response_data); |
| 10434 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10435 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 10436 | http_server_properties->GetAlternativeServiceInfos(test_server); |
| 10437 | ASSERT_EQ(2u, alternative_service_info_vector.size()); |
| 10438 | |
| 10439 | AlternativeService alternative_service(kProtoHTTP2, "www.example.com", 443); |
| 10440 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 10441 | alternative_service_info_vector[0].alternative_service()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10442 | AlternativeService alternative_service_2(kProtoHTTP2, "www.example.org", |
| 10443 | 1234); |
| 10444 | EXPECT_EQ(alternative_service_2, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 10445 | alternative_service_info_vector[1].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10446 | } |
| 10447 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10448 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10449 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10450 | HostPortPair alternative("alternative.example.org", 443); |
| 10451 | std::string origin_url = "https://origin.example.org:443"; |
| 10452 | std::string alternative_url = "https://alternative.example.org:443"; |
| 10453 | |
| 10454 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 10455 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10456 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10457 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10458 | |
| 10459 | // HTTP/1.1 data for request. |
| 10460 | MockWrite http_writes[] = { |
| 10461 | MockWrite("GET / HTTP/1.1\r\n" |
| 10462 | "Host: alternative.example.org\r\n" |
| 10463 | "Connection: keep-alive\r\n\r\n"), |
| 10464 | }; |
| 10465 | |
| 10466 | MockRead http_reads[] = { |
| 10467 | MockRead("HTTP/1.1 200 OK\r\n" |
| 10468 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10469 | "Content-Length: 40\r\n\r\n" |
| 10470 | "first HTTP/1.1 response from alternative"), |
| 10471 | }; |
| 10472 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 10473 | http_writes, arraysize(http_writes)); |
| 10474 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 10475 | |
| 10476 | StaticSocketDataProvider data_refused; |
| 10477 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 10478 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 10479 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10480 | // Set up a QUIC alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10481 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10482 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10483 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10484 | AlternativeService alternative_service(kProtoQUIC, alternative); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10485 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10486 | http_server_properties->SetQuicAlternativeService( |
| 10487 | server, alternative_service, expiration, |
| 10488 | HttpNetworkSession::Params().quic_supported_versions); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10489 | // Mark the QUIC alternative service as broken. |
| 10490 | http_server_properties->MarkAlternativeServiceBroken(alternative_service); |
| 10491 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10492 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 10493 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10494 | request.method = "GET"; |
| 10495 | request.url = GURL(origin_url); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10496 | TestCompletionCallback callback; |
| 10497 | NetErrorDetails details; |
| 10498 | EXPECT_FALSE(details.quic_broken); |
| 10499 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10500 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10501 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10502 | EXPECT_TRUE(details.quic_broken); |
| 10503 | } |
| 10504 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10505 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicNotBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10506 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10507 | HostPortPair alternative1("alternative1.example.org", 443); |
| 10508 | HostPortPair alternative2("alternative2.example.org", 443); |
| 10509 | std::string origin_url = "https://origin.example.org:443"; |
| 10510 | std::string alternative_url1 = "https://alternative1.example.org:443"; |
| 10511 | std::string alternative_url2 = "https://alternative2.example.org:443"; |
| 10512 | |
| 10513 | // Negotiate HTTP/1.1 with alternative1.example.org. |
| 10514 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10515 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10516 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10517 | |
| 10518 | // HTTP/1.1 data for request. |
| 10519 | MockWrite http_writes[] = { |
| 10520 | MockWrite("GET / HTTP/1.1\r\n" |
| 10521 | "Host: alternative1.example.org\r\n" |
| 10522 | "Connection: keep-alive\r\n\r\n"), |
| 10523 | }; |
| 10524 | |
| 10525 | MockRead http_reads[] = { |
| 10526 | MockRead("HTTP/1.1 200 OK\r\n" |
| 10527 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10528 | "Content-Length: 40\r\n\r\n" |
| 10529 | "first HTTP/1.1 response from alternative1"), |
| 10530 | }; |
| 10531 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 10532 | http_writes, arraysize(http_writes)); |
| 10533 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 10534 | |
| 10535 | StaticSocketDataProvider data_refused; |
| 10536 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 10537 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 10538 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10539 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10540 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10541 | session->http_server_properties(); |
| 10542 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10543 | // Set up two QUIC alternative services for server. |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10544 | AlternativeServiceInfoVector alternative_service_info_vector; |
| 10545 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 10546 | |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10547 | AlternativeService alternative_service1(kProtoQUIC, alternative1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10548 | alternative_service_info_vector.push_back( |
| 10549 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 10550 | alternative_service1, expiration, |
| 10551 | session->params().quic_supported_versions)); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10552 | AlternativeService alternative_service2(kProtoQUIC, alternative2); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10553 | alternative_service_info_vector.push_back( |
| 10554 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 10555 | alternative_service2, expiration, |
| 10556 | session->params().quic_supported_versions)); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10557 | |
| 10558 | http_server_properties->SetAlternativeServices( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10559 | server, alternative_service_info_vector); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10560 | |
| 10561 | // Mark one of the QUIC alternative service as broken. |
| 10562 | http_server_properties->MarkAlternativeServiceBroken(alternative_service1); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10563 | EXPECT_EQ(2u, |
| 10564 | http_server_properties->GetAlternativeServiceInfos(server).size()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10565 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10566 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 10567 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10568 | request.method = "GET"; |
| 10569 | request.url = GURL(origin_url); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10570 | TestCompletionCallback callback; |
| 10571 | NetErrorDetails details; |
| 10572 | EXPECT_FALSE(details.quic_broken); |
| 10573 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10574 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10575 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10576 | EXPECT_FALSE(details.quic_broken); |
| 10577 | } |
| 10578 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10579 | TEST_F(HttpNetworkTransactionTest, MarkBrokenAlternateProtocolAndFallback) { |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10580 | HttpRequestInfo request; |
| 10581 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10582 | request.url = GURL("https://www.example.org/"); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10583 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10584 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10585 | StaticSocketDataProvider first_data; |
| 10586 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10587 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10588 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10589 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10590 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10591 | |
| 10592 | MockRead data_reads[] = { |
| 10593 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10594 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10595 | MockRead(ASYNC, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10596 | }; |
| 10597 | StaticSocketDataProvider second_data( |
| 10598 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10599 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10600 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10601 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10602 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10603 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10604 | session->http_server_properties(); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10605 | const url::SchemeHostPort server(request.url); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10606 | // Port must be < 1024, or the header will be ignored (since initial port was |
| 10607 | // port 80 (another restricted port). |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10608 | // Port is ignored by MockConnect anyway. |
| 10609 | const AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 10610 | 666); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10611 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10612 | http_server_properties->SetHttp2AlternativeService( |
| 10613 | server, alternative_service, expiration); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10614 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10615 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10616 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10617 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10618 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10619 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10620 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10621 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10622 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10623 | ASSERT_TRUE(response); |
| 10624 | ASSERT_TRUE(response->headers); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10625 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10626 | |
| 10627 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10628 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10629 | EXPECT_EQ("hello world", response_data); |
| 10630 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10631 | const AlternativeServiceInfoVector alternative_service_info_vector = |
| 10632 | http_server_properties->GetAlternativeServiceInfos(server); |
| 10633 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 10634 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 10635 | alternative_service_info_vector[0].alternative_service()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10636 | EXPECT_TRUE( |
| 10637 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10638 | } |
| 10639 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10640 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10641 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10642 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10643 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10644 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedBlocked) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10645 | HttpRequestInfo restricted_port_request; |
| 10646 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10647 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10648 | restricted_port_request.load_flags = 0; |
| 10649 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10650 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10651 | StaticSocketDataProvider first_data; |
| 10652 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10653 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10654 | |
| 10655 | MockRead data_reads[] = { |
| 10656 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10657 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10658 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10659 | }; |
| 10660 | StaticSocketDataProvider second_data( |
| 10661 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10662 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10663 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10664 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10665 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10666 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10667 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10668 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10669 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10670 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10671 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10672 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 10673 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10674 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10675 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10676 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10677 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10678 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10679 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10680 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10681 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10682 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 10683 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10684 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10685 | // Invalid change to unrestricted port should fail. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10686 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_REFUSED)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10687 | } |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10688 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10689 | // Ensure that we are allowed to redirect traffic via an alternate protocol to |
| 10690 | // an unrestricted (port >= 1024) when the original traffic was on a restricted |
| 10691 | // port (port < 1024) if we set |enable_user_alternate_protocol_ports|. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10692 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedPermitted) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10693 | session_deps_.enable_user_alternate_protocol_ports = true; |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10694 | |
| 10695 | HttpRequestInfo restricted_port_request; |
| 10696 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10697 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10698 | restricted_port_request.load_flags = 0; |
| 10699 | |
| 10700 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10701 | StaticSocketDataProvider first_data; |
| 10702 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10703 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10704 | |
| 10705 | MockRead data_reads[] = { |
| 10706 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10707 | MockRead("hello world"), |
| 10708 | MockRead(ASYNC, OK), |
| 10709 | }; |
| 10710 | StaticSocketDataProvider second_data( |
| 10711 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10712 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10713 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10714 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10715 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10716 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10717 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10718 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10719 | HttpServerProperties* http_server_properties = |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10720 | session->http_server_properties(); |
| 10721 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10722 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 10723 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10724 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10725 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10726 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10727 | expiration); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10728 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10729 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10730 | TestCompletionCallback callback; |
| 10731 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10732 | EXPECT_EQ(ERR_IO_PENDING, |
| 10733 | trans.Start(&restricted_port_request, callback.callback(), |
| 10734 | NetLogWithSource())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10735 | // Change to unrestricted port should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10736 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10737 | } |
| 10738 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10739 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10740 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10741 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10742 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10743 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedAllowed) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10744 | HttpRequestInfo restricted_port_request; |
| 10745 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10746 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10747 | restricted_port_request.load_flags = 0; |
| 10748 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10749 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10750 | StaticSocketDataProvider first_data; |
| 10751 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10752 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10753 | |
| 10754 | MockRead data_reads[] = { |
| 10755 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10756 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10757 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10758 | }; |
| 10759 | StaticSocketDataProvider second_data( |
| 10760 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10761 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10762 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10763 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10764 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10765 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10766 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10767 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10768 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10769 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10770 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10771 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 10772 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10773 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10774 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10775 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10776 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10777 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10778 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10779 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10780 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10781 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 10782 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10783 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10784 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10785 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10786 | } |
| 10787 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10788 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10789 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10790 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10791 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10792 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed1) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10793 | HttpRequestInfo unrestricted_port_request; |
| 10794 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10795 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10796 | unrestricted_port_request.load_flags = 0; |
| 10797 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10798 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10799 | StaticSocketDataProvider first_data; |
| 10800 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10801 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10802 | |
| 10803 | MockRead data_reads[] = { |
| 10804 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10805 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10806 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10807 | }; |
| 10808 | StaticSocketDataProvider second_data( |
| 10809 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10810 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10811 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10812 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10813 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10814 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10815 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10816 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10817 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10818 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10819 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10820 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 10821 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10822 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10823 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10824 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10825 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10826 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10827 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10828 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10829 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10830 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10831 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10832 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10833 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10834 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10835 | } |
| 10836 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10837 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10838 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10839 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10840 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10841 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed2) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10842 | HttpRequestInfo unrestricted_port_request; |
| 10843 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10844 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10845 | unrestricted_port_request.load_flags = 0; |
| 10846 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10847 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10848 | StaticSocketDataProvider first_data; |
| 10849 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10850 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10851 | |
| 10852 | MockRead data_reads[] = { |
| 10853 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10854 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10855 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10856 | }; |
| 10857 | StaticSocketDataProvider second_data( |
| 10858 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10859 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10860 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10861 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10862 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10863 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10864 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10865 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10866 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10867 | session->http_server_properties(); |
bnc | 0bbb0262 | 2015-07-23 10:06:22 | [diff] [blame] | 10868 | const int kUnrestrictedAlternatePort = 1025; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10869 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 10870 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10871 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10872 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10873 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10874 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10875 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10876 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10877 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10878 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10879 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10880 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10881 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10882 | // Valid change to an unrestricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10883 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10884 | } |
| 10885 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10886 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10887 | // to an unsafe port, and that we resume the second HttpStreamFactoryImpl::Job |
| 10888 | // once the alternate protocol request fails. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10889 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) { |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10890 | HttpRequestInfo request; |
| 10891 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10892 | request.url = GURL("http://www.example.org/"); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10893 | |
| 10894 | // The alternate protocol request will error out before we attempt to connect, |
| 10895 | // so only the standard HTTP request will try to connect. |
| 10896 | MockRead data_reads[] = { |
| 10897 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10898 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10899 | MockRead(ASYNC, OK), |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10900 | }; |
| 10901 | StaticSocketDataProvider data( |
| 10902 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10903 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10904 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10905 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10906 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10907 | HttpServerProperties* http_server_properties = |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10908 | session->http_server_properties(); |
| 10909 | const int kUnsafePort = 7; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10910 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 10911 | kUnsafePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10912 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10913 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10914 | url::SchemeHostPort(request.url), alternative_service, expiration); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10915 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10916 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10917 | TestCompletionCallback callback; |
| 10918 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10919 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10920 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10921 | // The HTTP request should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10922 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10923 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10924 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10925 | ASSERT_TRUE(response); |
| 10926 | ASSERT_TRUE(response->headers); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10927 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10928 | |
| 10929 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10930 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10931 | EXPECT_EQ("hello world", response_data); |
| 10932 | } |
| 10933 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10934 | TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10935 | HttpRequestInfo request; |
| 10936 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10937 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10938 | |
| 10939 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10940 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10941 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10942 | MockRead("\r\n"), |
| 10943 | MockRead("hello world"), |
| 10944 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 10945 | MockRead(ASYNC, OK)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10946 | |
| 10947 | StaticSocketDataProvider first_transaction( |
| 10948 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10949 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10950 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10951 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10952 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10953 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 10954 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10955 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10956 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10957 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10958 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10959 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 10960 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10961 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10962 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10963 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10964 | }; |
| 10965 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10966 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 10967 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10968 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10969 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10970 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10971 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 10972 | NULL, 0, NULL, 0); |
| 10973 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 10974 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10975 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10976 | &hanging_non_alternate_protocol_socket); |
| 10977 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10978 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10979 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10980 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10981 | auto trans = |
| 10982 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10983 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10984 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10985 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10986 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10987 | |
| 10988 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10989 | ASSERT_TRUE(response); |
| 10990 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10991 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10992 | |
| 10993 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10994 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10995 | EXPECT_EQ("hello world", response_data); |
| 10996 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10997 | trans = |
| 10998 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10999 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11000 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11001 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11002 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11003 | |
| 11004 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11005 | ASSERT_TRUE(response); |
| 11006 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11007 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11008 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11009 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11010 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11011 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11012 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11013 | } |
| 11014 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11015 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11016 | HttpRequestInfo request; |
| 11017 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11018 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11019 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11020 | // First transaction receives Alt-Svc header over HTTP/1.1. |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11021 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11022 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11023 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11024 | MockRead("\r\n"), |
| 11025 | MockRead("hello world"), |
| 11026 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11027 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11028 | }; |
| 11029 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11030 | StaticSocketDataProvider http11_data(data_reads, arraysize(data_reads), NULL, |
| 11031 | 0); |
| 11032 | session_deps_.socket_factory->AddSocketDataProvider(&http11_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11033 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11034 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
| 11035 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
| 11036 | |
| 11037 | // Second transaction starts an alternative and a non-alternative Job. |
| 11038 | // Both sockets hang. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11039 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 11040 | StaticSocketDataProvider hanging_socket1(NULL, 0, NULL, 0); |
| 11041 | hanging_socket1.set_connect_data(never_finishing_connect); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 11042 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket1); |
| 11043 | |
| 11044 | StaticSocketDataProvider hanging_socket2(NULL, 0, NULL, 0); |
| 11045 | hanging_socket2.set_connect_data(never_finishing_connect); |
| 11046 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket2); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11047 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11048 | // Third transaction starts an alternative and a non-alternative job. |
| 11049 | // The non-alternative job hangs, but the alternative one succeeds. |
| 11050 | // The second transaction, still pending, binds to this socket. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11051 | SpdySerializedFrame req1( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11052 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11053 | SpdySerializedFrame req2( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11054 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 3, LOWEST)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11055 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11056 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 1), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11057 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 11058 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11059 | SpdySerializedFrame data1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 11060 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11061 | SpdySerializedFrame data2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11062 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11063 | CreateMockRead(resp1, 2), CreateMockRead(data1, 3), |
| 11064 | CreateMockRead(resp2, 4), CreateMockRead(data2, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11065 | MockRead(ASYNC, 0, 6), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11066 | }; |
| 11067 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11068 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11069 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11070 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11071 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11072 | AddSSLSocketData(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11073 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 11074 | StaticSocketDataProvider hanging_socket3(NULL, 0, NULL, 0); |
| 11075 | hanging_socket3.set_connect_data(never_finishing_connect); |
| 11076 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket3); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11077 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11078 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11079 | TestCompletionCallback callback1; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11080 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11081 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11082 | int rv = trans1.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11083 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11084 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11085 | |
| 11086 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11087 | ASSERT_TRUE(response); |
| 11088 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11089 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11090 | |
| 11091 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11092 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11093 | EXPECT_EQ("hello world", response_data); |
| 11094 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11095 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11096 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11097 | rv = trans2.Start(&request, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11098 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11099 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11100 | TestCompletionCallback callback3; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11101 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11102 | rv = trans3.Start(&request, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11103 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11104 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11105 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
| 11106 | EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11107 | |
| 11108 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11109 | ASSERT_TRUE(response); |
| 11110 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11111 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11112 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11113 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11114 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11115 | EXPECT_EQ("hello!", response_data); |
| 11116 | |
| 11117 | response = trans3.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11118 | ASSERT_TRUE(response); |
| 11119 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11120 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11121 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11122 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11123 | ASSERT_THAT(ReadTransaction(&trans3, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11124 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11125 | } |
| 11126 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11127 | TEST_F(HttpNetworkTransactionTest, StallAlternativeServiceForNpnSpdy) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11128 | HttpRequestInfo request; |
| 11129 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11130 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11131 | |
| 11132 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11133 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11134 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11135 | MockRead("\r\n"), |
| 11136 | MockRead("hello world"), |
| 11137 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11138 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11139 | }; |
| 11140 | |
| 11141 | StaticSocketDataProvider first_transaction( |
| 11142 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11143 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11144 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11145 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11146 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11147 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11148 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11149 | StaticSocketDataProvider hanging_alternate_protocol_socket( |
| 11150 | NULL, 0, NULL, 0); |
| 11151 | hanging_alternate_protocol_socket.set_connect_data( |
| 11152 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11153 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11154 | &hanging_alternate_protocol_socket); |
| 11155 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11156 | // 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] | 11157 | StaticSocketDataProvider second_transaction(data_reads, arraysize(data_reads), |
| 11158 | NULL, 0); |
| 11159 | session_deps_.socket_factory->AddSocketDataProvider(&second_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11160 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11161 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11162 | TestCompletionCallback callback; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11163 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11164 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11165 | auto trans = |
| 11166 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11167 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11168 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11169 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11170 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11171 | |
| 11172 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11173 | ASSERT_TRUE(response); |
| 11174 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11175 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11176 | |
| 11177 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11178 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11179 | EXPECT_EQ("hello world", response_data); |
| 11180 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11181 | trans = |
| 11182 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11183 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11184 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11185 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11186 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11187 | |
| 11188 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11189 | ASSERT_TRUE(response); |
| 11190 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11191 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11192 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11193 | EXPECT_FALSE(response->was_alpn_negotiated); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11194 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11195 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11196 | EXPECT_EQ("hello world", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11197 | } |
| 11198 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11199 | class CapturingProxyResolver : public ProxyResolver { |
| 11200 | public: |
sammc | e90c921 | 2015-05-27 23:43:35 | [diff] [blame] | 11201 | CapturingProxyResolver() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11202 | ~CapturingProxyResolver() override {} |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11203 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11204 | int GetProxyForURL(const GURL& url, |
| 11205 | ProxyInfo* results, |
| 11206 | const CompletionCallback& callback, |
maksim.sisov | 7e15726 | 2016-10-20 11:19:55 | [diff] [blame] | 11207 | std::unique_ptr<Request>* request, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11208 | const NetLogWithSource& net_log) override { |
[email protected] | fae7669f | 2010-08-02 21:49:40 | [diff] [blame] | 11209 | ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, |
| 11210 | HostPortPair("myproxy", 80)); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11211 | results->UseProxyServer(proxy_server); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11212 | resolved_.push_back(url); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11213 | return OK; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11214 | } |
| 11215 | |
[email protected] | 2447640 | 2010-07-20 20:55:17 | [diff] [blame] | 11216 | const std::vector<GURL>& resolved() const { return resolved_; } |
| 11217 | |
| 11218 | private: |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11219 | std::vector<GURL> resolved_; |
| 11220 | |
| 11221 | DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); |
| 11222 | }; |
| 11223 | |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 11224 | class CapturingProxyResolverFactory : public ProxyResolverFactory { |
| 11225 | public: |
| 11226 | explicit CapturingProxyResolverFactory(CapturingProxyResolver* resolver) |
| 11227 | : ProxyResolverFactory(false), resolver_(resolver) {} |
| 11228 | |
| 11229 | int CreateProxyResolver( |
| 11230 | const scoped_refptr<ProxyResolverScriptData>& pac_script, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11231 | std::unique_ptr<ProxyResolver>* resolver, |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 11232 | const net::CompletionCallback& callback, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11233 | std::unique_ptr<Request>* request) override { |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11234 | *resolver = base::MakeUnique<ForwardingProxyResolver>(resolver_); |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 11235 | return OK; |
| 11236 | } |
| 11237 | |
| 11238 | private: |
| 11239 | ProxyResolver* resolver_; |
| 11240 | }; |
| 11241 | |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11242 | // Test that proxy is resolved using the origin url, |
| 11243 | // regardless of the alternative server. |
| 11244 | TEST_F(HttpNetworkTransactionTest, UseOriginNotAlternativeForProxy) { |
| 11245 | // Configure proxy to bypass www.example.org, which is the origin URL. |
| 11246 | ProxyConfig proxy_config; |
| 11247 | proxy_config.proxy_rules().ParseFromString("myproxy:70"); |
| 11248 | proxy_config.proxy_rules().bypass_rules.AddRuleFromString("www.example.org"); |
| 11249 | auto proxy_config_service = |
| 11250 | base::MakeUnique<ProxyConfigServiceFixed>(proxy_config); |
| 11251 | |
| 11252 | CapturingProxyResolver capturing_proxy_resolver; |
| 11253 | auto proxy_resolver_factory = base::MakeUnique<CapturingProxyResolverFactory>( |
| 11254 | &capturing_proxy_resolver); |
| 11255 | |
| 11256 | TestNetLog net_log; |
| 11257 | |
| 11258 | session_deps_.proxy_service = base::MakeUnique<ProxyService>( |
| 11259 | std::move(proxy_config_service), std::move(proxy_resolver_factory), |
| 11260 | &net_log); |
| 11261 | |
| 11262 | session_deps_.net_log = &net_log; |
| 11263 | |
| 11264 | // Configure alternative service with a hostname that is not bypassed by the |
| 11265 | // proxy. |
| 11266 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11267 | HttpServerProperties* http_server_properties = |
| 11268 | session->http_server_properties(); |
| 11269 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 11270 | HostPortPair alternative("www.example.com", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11271 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11272 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11273 | http_server_properties->SetHttp2AlternativeService( |
| 11274 | server, alternative_service, expiration); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11275 | |
| 11276 | // Non-alternative job should hang. |
| 11277 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
| 11278 | StaticSocketDataProvider hanging_alternate_protocol_socket(nullptr, 0, |
| 11279 | nullptr, 0); |
| 11280 | hanging_alternate_protocol_socket.set_connect_data(never_finishing_connect); |
| 11281 | session_deps_.socket_factory->AddSocketDataProvider( |
| 11282 | &hanging_alternate_protocol_socket); |
| 11283 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11284 | AddSSLSocketData(); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11285 | |
| 11286 | HttpRequestInfo request; |
| 11287 | request.method = "GET"; |
| 11288 | request.url = GURL("https://www.example.org/"); |
| 11289 | request.load_flags = 0; |
| 11290 | |
| 11291 | SpdySerializedFrame req( |
| 11292 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
| 11293 | |
| 11294 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
| 11295 | |
| 11296 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 11297 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 11298 | MockRead spdy_reads[] = { |
| 11299 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
| 11300 | }; |
| 11301 | |
| 11302 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11303 | arraysize(spdy_writes)); |
| 11304 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 11305 | |
| 11306 | TestCompletionCallback callback; |
| 11307 | |
| 11308 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 11309 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11310 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11311 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 11312 | |
| 11313 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 11314 | ASSERT_TRUE(response); |
| 11315 | ASSERT_TRUE(response->headers); |
| 11316 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 11317 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11318 | EXPECT_TRUE(response->was_alpn_negotiated); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11319 | |
| 11320 | std::string response_data; |
| 11321 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 11322 | EXPECT_EQ("hello!", response_data); |
| 11323 | |
| 11324 | // Origin host bypasses proxy, no resolution should have happened. |
| 11325 | ASSERT_TRUE(capturing_proxy_resolver.resolved().empty()); |
| 11326 | } |
| 11327 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11328 | TEST_F(HttpNetworkTransactionTest, UseAlternativeServiceForTunneledNpnSpdy) { |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11329 | ProxyConfig proxy_config; |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11330 | proxy_config.set_auto_detect(true); |
| 11331 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 11332 | |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11333 | CapturingProxyResolver capturing_proxy_resolver; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11334 | session_deps_.proxy_service = base::MakeUnique<ProxyService>( |
| 11335 | base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), |
| 11336 | base::MakeUnique<CapturingProxyResolverFactory>( |
| 11337 | &capturing_proxy_resolver), |
| 11338 | nullptr); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11339 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11340 | session_deps_.net_log = &net_log; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11341 | |
| 11342 | HttpRequestInfo request; |
| 11343 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11344 | request.url = GURL("https://www.example.org/"); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11345 | |
| 11346 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11347 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11348 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11349 | MockRead("\r\n"), |
| 11350 | MockRead("hello world"), |
| 11351 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11352 | MockRead(ASYNC, OK), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11353 | }; |
| 11354 | |
| 11355 | StaticSocketDataProvider first_transaction( |
| 11356 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11357 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11358 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11359 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11360 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11361 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11362 | AddSSLSocketData(); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11363 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11364 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11365 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11366 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11367 | MockWrite(ASYNC, 0, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11368 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 11369 | "Host: www.example.org:443\r\n" |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11370 | "Proxy-Connection: keep-alive\r\n\r\n"), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11371 | CreateMockWrite(req, 2), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11372 | }; |
| 11373 | |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11374 | const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 11375 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 11376 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11377 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11378 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11379 | MockRead(ASYNC, 1, kCONNECTResponse), CreateMockRead(resp, 3), |
| 11380 | CreateMockRead(data, 4), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11381 | }; |
| 11382 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11383 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11384 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11385 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11386 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11387 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11388 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 11389 | NULL, 0, NULL, 0); |
| 11390 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 11391 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11392 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11393 | &hanging_non_alternate_protocol_socket); |
| 11394 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11395 | TestCompletionCallback callback; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11396 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11397 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11398 | auto trans = |
| 11399 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11400 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11401 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 11402 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11403 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 11404 | |
| 11405 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 11406 | ASSERT_TRUE(response); |
| 11407 | ASSERT_TRUE(response->headers); |
| 11408 | EXPECT_EQ("HTTP/0.9 200 OK", response->headers->GetStatusLine()); |
| 11409 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11410 | EXPECT_TRUE(response->was_alpn_negotiated); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 11411 | |
| 11412 | std::string response_data; |
| 11413 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 11414 | EXPECT_EQ("hello world", response_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11415 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11416 | trans = |
| 11417 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11418 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11419 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11420 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11421 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11422 | |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 11423 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11424 | ASSERT_TRUE(response); |
| 11425 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11426 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11427 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11428 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11429 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11430 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11431 | EXPECT_EQ("hello!", response_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11432 | ASSERT_EQ(2u, capturing_proxy_resolver.resolved().size()); |
| 11433 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11434 | capturing_proxy_resolver.resolved()[0].spec()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11435 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11436 | capturing_proxy_resolver.resolved()[1].spec()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11437 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11438 | LoadTimingInfo load_timing_info; |
| 11439 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 11440 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11441 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11442 | } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11443 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11444 | TEST_F(HttpNetworkTransactionTest, |
bnc | 1c196c6e | 2016-05-28 13:51:48 | [diff] [blame] | 11445 | UseAlternativeServiceForNpnSpdyWithExistingSpdySession) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11446 | HttpRequestInfo request; |
| 11447 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11448 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11449 | |
| 11450 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11451 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11452 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11453 | MockRead("\r\n"), |
| 11454 | MockRead("hello world"), |
| 11455 | MockRead(ASYNC, OK), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11456 | }; |
| 11457 | |
| 11458 | StaticSocketDataProvider first_transaction( |
| 11459 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11460 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11461 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11462 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11463 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11464 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11465 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11466 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11467 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11468 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11469 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11470 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 11471 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11472 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11473 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11474 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11475 | }; |
| 11476 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11477 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11478 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11479 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11480 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 11481 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11482 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11483 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11484 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11485 | auto trans = |
| 11486 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11487 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11488 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11489 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11490 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11491 | |
| 11492 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11493 | ASSERT_TRUE(response); |
| 11494 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11495 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11496 | |
| 11497 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11498 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11499 | EXPECT_EQ("hello world", response_data); |
| 11500 | |
| 11501 | // Set up an initial SpdySession in the pool to reuse. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11502 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 11503 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 11504 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 11505 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 11506 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 11507 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11508 | trans = |
| 11509 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11510 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11511 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11512 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11513 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11514 | |
| 11515 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11516 | ASSERT_TRUE(response); |
| 11517 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11518 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11519 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11520 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11521 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11522 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11523 | EXPECT_EQ("hello!", response_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11524 | } |
| 11525 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11526 | // GenerateAuthToken is a mighty big test. |
| 11527 | // It tests all permutation of GenerateAuthToken behavior: |
| 11528 | // - Synchronous and Asynchronous completion. |
| 11529 | // - OK or error on completion. |
| 11530 | // - Direct connection, non-authenticating proxy, and authenticating proxy. |
| 11531 | // - HTTP or HTTPS backend (to include proxy tunneling). |
| 11532 | // - Non-authenticating and authenticating backend. |
| 11533 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 11534 | // In all, there are 44 reasonable permuations (for example, if there are |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11535 | // problems generating an auth token for an authenticating proxy, we don't |
| 11536 | // need to test all permutations of the backend server). |
| 11537 | // |
| 11538 | // The test proceeds by going over each of the configuration cases, and |
| 11539 | // potentially running up to three rounds in each of the tests. The TestConfig |
| 11540 | // specifies both the configuration for the test as well as the expectations |
| 11541 | // for the results. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11542 | TEST_F(HttpNetworkTransactionTest, GenerateAuthToken) { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11543 | static const char kServer[] = "http://www.example.com"; |
| 11544 | static const char kSecureServer[] = "https://www.example.com"; |
| 11545 | static const char kProxy[] = "myproxy:70"; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11546 | |
| 11547 | enum AuthTiming { |
| 11548 | AUTH_NONE, |
| 11549 | AUTH_SYNC, |
| 11550 | AUTH_ASYNC, |
| 11551 | }; |
| 11552 | |
| 11553 | const MockWrite kGet( |
| 11554 | "GET / HTTP/1.1\r\n" |
| 11555 | "Host: www.example.com\r\n" |
| 11556 | "Connection: keep-alive\r\n\r\n"); |
| 11557 | const MockWrite kGetProxy( |
| 11558 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11559 | "Host: www.example.com\r\n" |
| 11560 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 11561 | const MockWrite kGetAuth( |
| 11562 | "GET / HTTP/1.1\r\n" |
| 11563 | "Host: www.example.com\r\n" |
| 11564 | "Connection: keep-alive\r\n" |
| 11565 | "Authorization: auth_token\r\n\r\n"); |
| 11566 | const MockWrite kGetProxyAuth( |
| 11567 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11568 | "Host: www.example.com\r\n" |
| 11569 | "Proxy-Connection: keep-alive\r\n" |
| 11570 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 11571 | const MockWrite kGetAuthThroughProxy( |
| 11572 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11573 | "Host: www.example.com\r\n" |
| 11574 | "Proxy-Connection: keep-alive\r\n" |
| 11575 | "Authorization: auth_token\r\n\r\n"); |
| 11576 | const MockWrite kGetAuthWithProxyAuth( |
| 11577 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11578 | "Host: www.example.com\r\n" |
| 11579 | "Proxy-Connection: keep-alive\r\n" |
| 11580 | "Proxy-Authorization: auth_token\r\n" |
| 11581 | "Authorization: auth_token\r\n\r\n"); |
| 11582 | const MockWrite kConnect( |
| 11583 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 11584 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11585 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 11586 | const MockWrite kConnectProxyAuth( |
| 11587 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 11588 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11589 | "Proxy-Connection: keep-alive\r\n" |
| 11590 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 11591 | |
| 11592 | const MockRead kSuccess( |
| 11593 | "HTTP/1.1 200 OK\r\n" |
| 11594 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11595 | "Content-Length: 3\r\n\r\n" |
| 11596 | "Yes"); |
| 11597 | const MockRead kFailure( |
| 11598 | "Should not be called."); |
| 11599 | const MockRead kServerChallenge( |
| 11600 | "HTTP/1.1 401 Unauthorized\r\n" |
| 11601 | "WWW-Authenticate: Mock realm=server\r\n" |
| 11602 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11603 | "Content-Length: 14\r\n\r\n" |
| 11604 | "Unauthorized\r\n"); |
| 11605 | const MockRead kProxyChallenge( |
| 11606 | "HTTP/1.1 407 Unauthorized\r\n" |
| 11607 | "Proxy-Authenticate: Mock realm=proxy\r\n" |
| 11608 | "Proxy-Connection: close\r\n" |
| 11609 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11610 | "Content-Length: 14\r\n\r\n" |
| 11611 | "Unauthorized\r\n"); |
| 11612 | const MockRead kProxyConnected( |
| 11613 | "HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 11614 | |
| 11615 | // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with |
| 11616 | // no constructors, but the C++ compiler on Windows warns about |
| 11617 | // unspecified data in compound literals. So, moved to using constructors, |
| 11618 | // and TestRound's created with the default constructor should not be used. |
| 11619 | struct TestRound { |
| 11620 | TestRound() |
| 11621 | : expected_rv(ERR_UNEXPECTED), |
| 11622 | extra_write(NULL), |
| 11623 | extra_read(NULL) { |
| 11624 | } |
| 11625 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 11626 | int expected_rv_arg) |
| 11627 | : write(write_arg), |
| 11628 | read(read_arg), |
| 11629 | expected_rv(expected_rv_arg), |
| 11630 | extra_write(NULL), |
| 11631 | extra_read(NULL) { |
| 11632 | } |
| 11633 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 11634 | int expected_rv_arg, const MockWrite* extra_write_arg, |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 11635 | const MockRead* extra_read_arg) |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11636 | : write(write_arg), |
| 11637 | read(read_arg), |
| 11638 | expected_rv(expected_rv_arg), |
| 11639 | extra_write(extra_write_arg), |
| 11640 | extra_read(extra_read_arg) { |
| 11641 | } |
| 11642 | MockWrite write; |
| 11643 | MockRead read; |
| 11644 | int expected_rv; |
| 11645 | const MockWrite* extra_write; |
| 11646 | const MockRead* extra_read; |
| 11647 | }; |
| 11648 | |
| 11649 | static const int kNoSSL = 500; |
| 11650 | |
| 11651 | struct TestConfig { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11652 | int line_number; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 11653 | const char* const proxy_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11654 | AuthTiming proxy_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11655 | int first_generate_proxy_token_rv; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 11656 | const char* const server_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11657 | AuthTiming server_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11658 | int first_generate_server_token_rv; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11659 | int num_auth_rounds; |
| 11660 | int first_ssl_round; |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11661 | TestRound rounds[4]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11662 | } test_configs[] = { |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11663 | // Non-authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11664 | {__LINE__, |
| 11665 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11666 | AUTH_NONE, |
| 11667 | OK, |
| 11668 | kServer, |
| 11669 | AUTH_NONE, |
| 11670 | OK, |
| 11671 | 1, |
| 11672 | kNoSSL, |
| 11673 | {TestRound(kGet, kSuccess, OK)}}, |
| 11674 | // Authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11675 | {__LINE__, |
| 11676 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11677 | AUTH_NONE, |
| 11678 | OK, |
| 11679 | kServer, |
| 11680 | AUTH_SYNC, |
| 11681 | OK, |
| 11682 | 2, |
| 11683 | kNoSSL, |
| 11684 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11685 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11686 | {__LINE__, |
| 11687 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11688 | AUTH_NONE, |
| 11689 | OK, |
| 11690 | kServer, |
| 11691 | AUTH_SYNC, |
| 11692 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11693 | 3, |
| 11694 | kNoSSL, |
| 11695 | {TestRound(kGet, kServerChallenge, OK), |
| 11696 | TestRound(kGet, kServerChallenge, OK), |
| 11697 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11698 | {__LINE__, |
| 11699 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11700 | AUTH_NONE, |
| 11701 | OK, |
| 11702 | kServer, |
| 11703 | AUTH_SYNC, |
| 11704 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 11705 | 2, |
| 11706 | kNoSSL, |
| 11707 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11708 | {__LINE__, |
| 11709 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11710 | AUTH_NONE, |
| 11711 | OK, |
| 11712 | kServer, |
| 11713 | AUTH_SYNC, |
| 11714 | ERR_UNDOCUMENTED_SECURITY_LIBRARY_STATUS, |
| 11715 | 2, |
| 11716 | kNoSSL, |
| 11717 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11718 | {__LINE__, |
| 11719 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11720 | AUTH_SYNC, |
| 11721 | ERR_FAILED, |
| 11722 | kServer, |
| 11723 | AUTH_NONE, |
| 11724 | OK, |
| 11725 | 2, |
| 11726 | kNoSSL, |
| 11727 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 11728 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11729 | {__LINE__, |
| 11730 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11731 | AUTH_ASYNC, |
| 11732 | ERR_FAILED, |
| 11733 | kServer, |
| 11734 | AUTH_NONE, |
| 11735 | OK, |
| 11736 | 2, |
| 11737 | kNoSSL, |
| 11738 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 11739 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11740 | {__LINE__, |
| 11741 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11742 | AUTH_NONE, |
| 11743 | OK, |
| 11744 | kServer, |
| 11745 | AUTH_SYNC, |
| 11746 | ERR_FAILED, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11747 | 2, |
| 11748 | kNoSSL, |
| 11749 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11750 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11751 | {__LINE__, |
| 11752 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11753 | AUTH_NONE, |
| 11754 | OK, |
| 11755 | kServer, |
| 11756 | AUTH_ASYNC, |
| 11757 | ERR_FAILED, |
| 11758 | 2, |
| 11759 | kNoSSL, |
| 11760 | {TestRound(kGet, kServerChallenge, OK), |
| 11761 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11762 | {__LINE__, |
| 11763 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11764 | AUTH_NONE, |
| 11765 | OK, |
| 11766 | kServer, |
| 11767 | AUTH_ASYNC, |
| 11768 | OK, |
| 11769 | 2, |
| 11770 | kNoSSL, |
| 11771 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11772 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11773 | {__LINE__, |
| 11774 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11775 | AUTH_NONE, |
| 11776 | OK, |
| 11777 | kServer, |
| 11778 | AUTH_ASYNC, |
| 11779 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11780 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11781 | kNoSSL, |
| 11782 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11783 | // The second round uses a HttpAuthHandlerMock that always succeeds. |
| 11784 | TestRound(kGet, kServerChallenge, OK), |
| 11785 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11786 | // Non-authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11787 | {__LINE__, |
| 11788 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11789 | AUTH_NONE, |
| 11790 | OK, |
| 11791 | kServer, |
| 11792 | AUTH_NONE, |
| 11793 | OK, |
| 11794 | 1, |
| 11795 | kNoSSL, |
| 11796 | {TestRound(kGetProxy, kSuccess, OK)}}, |
| 11797 | // Authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11798 | {__LINE__, |
| 11799 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11800 | AUTH_NONE, |
| 11801 | OK, |
| 11802 | kServer, |
| 11803 | AUTH_SYNC, |
| 11804 | OK, |
| 11805 | 2, |
| 11806 | kNoSSL, |
| 11807 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11808 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11809 | {__LINE__, |
| 11810 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11811 | AUTH_NONE, |
| 11812 | OK, |
| 11813 | kServer, |
| 11814 | AUTH_SYNC, |
| 11815 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11816 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11817 | kNoSSL, |
| 11818 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11819 | TestRound(kGetProxy, kServerChallenge, OK), |
| 11820 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11821 | {__LINE__, |
| 11822 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11823 | AUTH_NONE, |
| 11824 | OK, |
| 11825 | kServer, |
| 11826 | AUTH_ASYNC, |
| 11827 | OK, |
| 11828 | 2, |
| 11829 | kNoSSL, |
| 11830 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11831 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11832 | {__LINE__, |
| 11833 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11834 | AUTH_NONE, |
| 11835 | OK, |
| 11836 | kServer, |
| 11837 | AUTH_ASYNC, |
| 11838 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11839 | 2, |
| 11840 | kNoSSL, |
| 11841 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11842 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11843 | // Non-authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11844 | {__LINE__, |
| 11845 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11846 | AUTH_SYNC, |
| 11847 | OK, |
| 11848 | kServer, |
| 11849 | AUTH_NONE, |
| 11850 | OK, |
| 11851 | 2, |
| 11852 | kNoSSL, |
| 11853 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11854 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11855 | {__LINE__, |
| 11856 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11857 | AUTH_SYNC, |
| 11858 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11859 | kServer, |
| 11860 | AUTH_NONE, |
| 11861 | OK, |
| 11862 | 2, |
| 11863 | kNoSSL, |
| 11864 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11865 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11866 | {__LINE__, |
| 11867 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11868 | AUTH_ASYNC, |
| 11869 | OK, |
| 11870 | kServer, |
| 11871 | AUTH_NONE, |
| 11872 | OK, |
| 11873 | 2, |
| 11874 | kNoSSL, |
| 11875 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11876 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11877 | {__LINE__, |
| 11878 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11879 | AUTH_ASYNC, |
| 11880 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11881 | kServer, |
| 11882 | AUTH_NONE, |
| 11883 | OK, |
| 11884 | 2, |
| 11885 | kNoSSL, |
| 11886 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11887 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11888 | {__LINE__, |
| 11889 | kProxy, |
| 11890 | AUTH_ASYNC, |
| 11891 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11892 | kServer, |
| 11893 | AUTH_NONE, |
| 11894 | OK, |
| 11895 | 3, |
| 11896 | kNoSSL, |
| 11897 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 11898 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 11899 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11900 | // Authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11901 | {__LINE__, |
| 11902 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11903 | AUTH_SYNC, |
| 11904 | OK, |
| 11905 | kServer, |
| 11906 | AUTH_SYNC, |
| 11907 | OK, |
| 11908 | 3, |
| 11909 | kNoSSL, |
| 11910 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11911 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11912 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11913 | {__LINE__, |
| 11914 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11915 | AUTH_SYNC, |
| 11916 | OK, |
| 11917 | kServer, |
| 11918 | AUTH_SYNC, |
| 11919 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11920 | 3, |
| 11921 | kNoSSL, |
| 11922 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11923 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11924 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11925 | {__LINE__, |
| 11926 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11927 | AUTH_ASYNC, |
| 11928 | OK, |
| 11929 | kServer, |
| 11930 | AUTH_SYNC, |
| 11931 | OK, |
| 11932 | 3, |
| 11933 | kNoSSL, |
| 11934 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11935 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11936 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11937 | {__LINE__, |
| 11938 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11939 | AUTH_ASYNC, |
| 11940 | OK, |
| 11941 | kServer, |
| 11942 | AUTH_SYNC, |
| 11943 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11944 | 3, |
| 11945 | kNoSSL, |
| 11946 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11947 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11948 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11949 | {__LINE__, |
| 11950 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11951 | AUTH_SYNC, |
| 11952 | OK, |
| 11953 | kServer, |
| 11954 | AUTH_ASYNC, |
| 11955 | OK, |
| 11956 | 3, |
| 11957 | kNoSSL, |
| 11958 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11959 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11960 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11961 | {__LINE__, |
| 11962 | kProxy, |
| 11963 | AUTH_SYNC, |
| 11964 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11965 | kServer, |
| 11966 | AUTH_ASYNC, |
| 11967 | OK, |
| 11968 | 4, |
| 11969 | kNoSSL, |
| 11970 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 11971 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 11972 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11973 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 11974 | {__LINE__, |
| 11975 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11976 | AUTH_SYNC, |
| 11977 | OK, |
| 11978 | kServer, |
| 11979 | AUTH_ASYNC, |
| 11980 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11981 | 3, |
| 11982 | kNoSSL, |
| 11983 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11984 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11985 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11986 | {__LINE__, |
| 11987 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11988 | AUTH_ASYNC, |
| 11989 | OK, |
| 11990 | kServer, |
| 11991 | AUTH_ASYNC, |
| 11992 | OK, |
| 11993 | 3, |
| 11994 | kNoSSL, |
| 11995 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11996 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11997 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11998 | {__LINE__, |
| 11999 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12000 | AUTH_ASYNC, |
| 12001 | OK, |
| 12002 | kServer, |
| 12003 | AUTH_ASYNC, |
| 12004 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12005 | 3, |
| 12006 | kNoSSL, |
| 12007 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12008 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12009 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12010 | {__LINE__, |
| 12011 | kProxy, |
| 12012 | AUTH_ASYNC, |
| 12013 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12014 | kServer, |
| 12015 | AUTH_ASYNC, |
| 12016 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12017 | 4, |
| 12018 | kNoSSL, |
| 12019 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12020 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 12021 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12022 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12023 | // Non-authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12024 | {__LINE__, |
| 12025 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12026 | AUTH_NONE, |
| 12027 | OK, |
| 12028 | kSecureServer, |
| 12029 | AUTH_NONE, |
| 12030 | OK, |
| 12031 | 1, |
| 12032 | 0, |
| 12033 | {TestRound(kGet, kSuccess, OK)}}, |
| 12034 | // Authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12035 | {__LINE__, |
| 12036 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12037 | AUTH_NONE, |
| 12038 | OK, |
| 12039 | kSecureServer, |
| 12040 | AUTH_SYNC, |
| 12041 | OK, |
| 12042 | 2, |
| 12043 | 0, |
| 12044 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12045 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12046 | {__LINE__, |
| 12047 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12048 | AUTH_NONE, |
| 12049 | OK, |
| 12050 | kSecureServer, |
| 12051 | AUTH_SYNC, |
| 12052 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12053 | 2, |
| 12054 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12055 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12056 | {__LINE__, |
| 12057 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12058 | AUTH_NONE, |
| 12059 | OK, |
| 12060 | kSecureServer, |
| 12061 | AUTH_ASYNC, |
| 12062 | OK, |
| 12063 | 2, |
| 12064 | 0, |
| 12065 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12066 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12067 | {__LINE__, |
| 12068 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12069 | AUTH_NONE, |
| 12070 | OK, |
| 12071 | kSecureServer, |
| 12072 | AUTH_ASYNC, |
| 12073 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12074 | 2, |
| 12075 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12076 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12077 | // Non-authenticating HTTPS server with a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12078 | {__LINE__, |
| 12079 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12080 | AUTH_NONE, |
| 12081 | OK, |
| 12082 | kSecureServer, |
| 12083 | AUTH_NONE, |
| 12084 | OK, |
| 12085 | 1, |
| 12086 | 0, |
| 12087 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 12088 | // Authenticating HTTPS server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12089 | {__LINE__, |
| 12090 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12091 | AUTH_NONE, |
| 12092 | OK, |
| 12093 | kSecureServer, |
| 12094 | AUTH_SYNC, |
| 12095 | OK, |
| 12096 | 2, |
| 12097 | 0, |
| 12098 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12099 | TestRound(kGetAuth, 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 | kSecureServer, |
| 12105 | AUTH_SYNC, |
| 12106 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12107 | 2, |
| 12108 | 0, |
| 12109 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12110 | TestRound(kGet, 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 | kSecureServer, |
| 12116 | AUTH_ASYNC, |
| 12117 | OK, |
| 12118 | 2, |
| 12119 | 0, |
| 12120 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12121 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12122 | {__LINE__, |
| 12123 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12124 | AUTH_NONE, |
| 12125 | OK, |
| 12126 | kSecureServer, |
| 12127 | AUTH_ASYNC, |
| 12128 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12129 | 2, |
| 12130 | 0, |
| 12131 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12132 | TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12133 | // Non-Authenticating HTTPS server through an authenticating proxy. |
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 | OK, |
| 12138 | kSecureServer, |
| 12139 | AUTH_NONE, |
| 12140 | OK, |
| 12141 | 2, |
| 12142 | 1, |
| 12143 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12144 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
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_SYNC, |
| 12148 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12149 | kSecureServer, |
| 12150 | AUTH_NONE, |
| 12151 | OK, |
| 12152 | 2, |
| 12153 | kNoSSL, |
| 12154 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12155 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12156 | {__LINE__, |
| 12157 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12158 | AUTH_SYNC, |
| 12159 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 12160 | kSecureServer, |
| 12161 | AUTH_NONE, |
| 12162 | OK, |
| 12163 | 2, |
| 12164 | kNoSSL, |
| 12165 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12166 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12167 | {__LINE__, |
| 12168 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12169 | AUTH_SYNC, |
| 12170 | ERR_UNEXPECTED, |
| 12171 | kSecureServer, |
| 12172 | AUTH_NONE, |
| 12173 | OK, |
| 12174 | 2, |
| 12175 | kNoSSL, |
| 12176 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12177 | TestRound(kConnect, kProxyConnected, ERR_UNEXPECTED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12178 | {__LINE__, |
| 12179 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12180 | AUTH_ASYNC, |
| 12181 | OK, |
| 12182 | kSecureServer, |
| 12183 | AUTH_NONE, |
| 12184 | OK, |
| 12185 | 2, |
| 12186 | 1, |
| 12187 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12188 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12189 | {__LINE__, |
| 12190 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12191 | AUTH_ASYNC, |
| 12192 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12193 | kSecureServer, |
| 12194 | AUTH_NONE, |
| 12195 | OK, |
| 12196 | 2, |
| 12197 | kNoSSL, |
| 12198 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12199 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12200 | // Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12201 | {__LINE__, |
| 12202 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12203 | AUTH_SYNC, |
| 12204 | OK, |
| 12205 | kSecureServer, |
| 12206 | AUTH_SYNC, |
| 12207 | OK, |
| 12208 | 3, |
| 12209 | 1, |
| 12210 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12211 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12212 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12213 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12214 | {__LINE__, |
| 12215 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12216 | AUTH_SYNC, |
| 12217 | OK, |
| 12218 | kSecureServer, |
| 12219 | AUTH_SYNC, |
| 12220 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12221 | 3, |
| 12222 | 1, |
| 12223 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12224 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12225 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12226 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12227 | {__LINE__, |
| 12228 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12229 | AUTH_ASYNC, |
| 12230 | OK, |
| 12231 | kSecureServer, |
| 12232 | AUTH_SYNC, |
| 12233 | OK, |
| 12234 | 3, |
| 12235 | 1, |
| 12236 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12237 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12238 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12239 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12240 | {__LINE__, |
| 12241 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12242 | AUTH_ASYNC, |
| 12243 | OK, |
| 12244 | kSecureServer, |
| 12245 | AUTH_SYNC, |
| 12246 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12247 | 3, |
| 12248 | 1, |
| 12249 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12250 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12251 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12252 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12253 | {__LINE__, |
| 12254 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12255 | AUTH_SYNC, |
| 12256 | OK, |
| 12257 | kSecureServer, |
| 12258 | AUTH_ASYNC, |
| 12259 | OK, |
| 12260 | 3, |
| 12261 | 1, |
| 12262 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12263 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12264 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12265 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12266 | {__LINE__, |
| 12267 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12268 | AUTH_SYNC, |
| 12269 | OK, |
| 12270 | kSecureServer, |
| 12271 | AUTH_ASYNC, |
| 12272 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12273 | 3, |
| 12274 | 1, |
| 12275 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12276 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12277 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12278 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12279 | {__LINE__, |
| 12280 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12281 | AUTH_ASYNC, |
| 12282 | OK, |
| 12283 | kSecureServer, |
| 12284 | AUTH_ASYNC, |
| 12285 | OK, |
| 12286 | 3, |
| 12287 | 1, |
| 12288 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12289 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12290 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12291 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12292 | {__LINE__, |
| 12293 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12294 | AUTH_ASYNC, |
| 12295 | OK, |
| 12296 | kSecureServer, |
| 12297 | AUTH_ASYNC, |
| 12298 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12299 | 3, |
| 12300 | 1, |
| 12301 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12302 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12303 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12304 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12305 | {__LINE__, |
| 12306 | kProxy, |
| 12307 | AUTH_ASYNC, |
| 12308 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12309 | kSecureServer, |
| 12310 | AUTH_ASYNC, |
| 12311 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12312 | 4, |
| 12313 | 2, |
| 12314 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12315 | TestRound(kConnect, kProxyChallenge, OK), |
| 12316 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12317 | &kServerChallenge), |
| 12318 | TestRound(kGet, kSuccess, OK)}}, |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12319 | }; |
| 12320 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12321 | for (const auto& test_config : test_configs) { |
| 12322 | SCOPED_TRACE(::testing::Message() << "Test config at " |
| 12323 | << test_config.line_number); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12324 | HttpAuthHandlerMock::Factory* auth_factory( |
| 12325 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12326 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 12327 | SSLInfo empty_ssl_info; |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 12328 | |
| 12329 | // Set up authentication handlers as necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12330 | if (test_config.proxy_auth_timing != AUTH_NONE) { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12331 | for (int n = 0; n < 3; n++) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12332 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 12333 | std::string auth_challenge = "Mock realm=proxy"; |
| 12334 | GURL origin(test_config.proxy_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 12335 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 12336 | auth_challenge.end()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12337 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12338 | empty_ssl_info, origin, |
| 12339 | NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12340 | auth_handler->SetGenerateExpectation( |
| 12341 | test_config.proxy_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12342 | n == 0 ? test_config.first_generate_proxy_token_rv : OK); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12343 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 12344 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12345 | } |
| 12346 | if (test_config.server_auth_timing != AUTH_NONE) { |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 12347 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12348 | std::string auth_challenge = "Mock realm=server"; |
| 12349 | GURL origin(test_config.server_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 12350 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 12351 | auth_challenge.end()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12352 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12353 | empty_ssl_info, origin, |
| 12354 | NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12355 | auth_handler->SetGenerateExpectation( |
| 12356 | test_config.server_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12357 | test_config.first_generate_server_token_rv); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12358 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12359 | |
| 12360 | // The second handler always succeeds. It should only be used where there |
| 12361 | // are multiple auth sessions for server auth in the same network |
| 12362 | // transaction using the same auth scheme. |
| 12363 | std::unique_ptr<HttpAuthHandlerMock> second_handler = |
| 12364 | base::MakeUnique<HttpAuthHandlerMock>(); |
| 12365 | second_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 12366 | empty_ssl_info, origin, |
| 12367 | NetLogWithSource()); |
| 12368 | second_handler->SetGenerateExpectation(true, OK); |
| 12369 | auth_factory->AddMockHandler(second_handler.release(), |
| 12370 | HttpAuth::AUTH_SERVER); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12371 | } |
| 12372 | if (test_config.proxy_url) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12373 | session_deps_.proxy_service = |
| 12374 | ProxyService::CreateFixed(test_config.proxy_url); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12375 | } else { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12376 | session_deps_.proxy_service = ProxyService::CreateDirect(); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12377 | } |
| 12378 | |
| 12379 | HttpRequestInfo request; |
| 12380 | request.method = "GET"; |
| 12381 | request.url = GURL(test_config.server_url); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12382 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12383 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12384 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12385 | SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
| 12386 | |
| 12387 | std::vector<std::vector<MockRead>> mock_reads(1); |
| 12388 | std::vector<std::vector<MockWrite>> mock_writes(1); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12389 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 12390 | SCOPED_TRACE(round); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12391 | const TestRound& read_write_round = test_config.rounds[round]; |
| 12392 | |
| 12393 | // Set up expected reads and writes. |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12394 | mock_reads.back().push_back(read_write_round.read); |
| 12395 | mock_writes.back().push_back(read_write_round.write); |
| 12396 | |
| 12397 | // kProxyChallenge uses Proxy-Connection: close which means that the |
| 12398 | // socket is closed and a new one will be created for the next request. |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 12399 | if (read_write_round.read.data == kProxyChallenge.data) { |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12400 | mock_reads.push_back(std::vector<MockRead>()); |
| 12401 | mock_writes.push_back(std::vector<MockWrite>()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12402 | } |
| 12403 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12404 | if (read_write_round.extra_read) { |
| 12405 | mock_reads.back().push_back(*read_write_round.extra_read); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12406 | } |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12407 | if (read_write_round.extra_write) { |
| 12408 | mock_writes.back().push_back(*read_write_round.extra_write); |
| 12409 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12410 | |
| 12411 | // Add an SSL sequence if necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12412 | if (round >= test_config.first_ssl_round) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12413 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12414 | &ssl_socket_data_provider); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12415 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12416 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12417 | std::vector<std::unique_ptr<StaticSocketDataProvider>> data_providers; |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12418 | for (size_t i = 0; i < mock_reads.size(); ++i) { |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12419 | data_providers.push_back(base::MakeUnique<StaticSocketDataProvider>( |
davidben | 5f8b6bc | 2015-11-25 03:19:54 | [diff] [blame] | 12420 | mock_reads[i].data(), mock_reads[i].size(), mock_writes[i].data(), |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12421 | mock_writes[i].size())); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12422 | session_deps_.socket_factory->AddSocketDataProvider( |
olli.raula | 525048c | 2015-12-10 07:38:32 | [diff] [blame] | 12423 | data_providers.back().get()); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12424 | } |
| 12425 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12426 | // Transaction must be created after DataProviders, so it's destroyed before |
| 12427 | // they are as well. |
| 12428 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 12429 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12430 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 12431 | SCOPED_TRACE(round); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12432 | const TestRound& read_write_round = test_config.rounds[round]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12433 | // Start or restart the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12434 | TestCompletionCallback callback; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12435 | int rv; |
| 12436 | if (round == 0) { |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12437 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12438 | } else { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12439 | rv = trans.RestartWithAuth( |
| 12440 | AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12441 | } |
| 12442 | if (rv == ERR_IO_PENDING) |
| 12443 | rv = callback.WaitForResult(); |
| 12444 | |
| 12445 | // Compare results with expected data. |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12446 | EXPECT_THAT(rv, IsError(read_write_round.expected_rv)); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12447 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | c0c82849 | 2015-05-15 01:25:55 | [diff] [blame] | 12448 | if (read_write_round.expected_rv != OK) { |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12449 | EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
| 12450 | continue; |
| 12451 | } |
| 12452 | if (round + 1 < test_config.num_auth_rounds) { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12453 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12454 | } else { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12455 | EXPECT_FALSE(response->auth_challenge); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12456 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12457 | } |
| 12458 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 12459 | } |
| 12460 | } |
| 12461 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12462 | TEST_F(HttpNetworkTransactionTest, MultiRoundAuth) { |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12463 | // Do multi-round authentication and make sure it works correctly. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12464 | HttpAuthHandlerMock::Factory* auth_factory( |
| 12465 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12466 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12467 | session_deps_.proxy_service = ProxyService::CreateDirect(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12468 | session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
| 12469 | session_deps_.host_resolver->set_synchronous_mode(true); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12470 | |
| 12471 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 12472 | auth_handler->set_connection_based(true); |
| 12473 | std::string auth_challenge = "Mock realm=server"; |
| 12474 | GURL origin("http://www.example.com"); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 12475 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 12476 | auth_challenge.end()); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 12477 | SSLInfo empty_ssl_info; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12478 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12479 | empty_ssl_info, origin, NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12480 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12481 | |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12482 | int rv = OK; |
| 12483 | const HttpResponseInfo* response = NULL; |
| 12484 | HttpRequestInfo request; |
| 12485 | request.method = "GET"; |
| 12486 | request.url = origin; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12487 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12488 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12489 | |
| 12490 | // Use a TCP Socket Pool with only one connection per group. This is used |
| 12491 | // to validate that the TCP socket is not released to the pool between |
| 12492 | // each round of multi-round authentication. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12493 | HttpNetworkSessionPeer session_peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12494 | TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12495 | 50, // Max sockets for pool |
| 12496 | 1, // Max sockets per group |
tbansal | 7b403bcc | 2016-04-13 22:33:21 | [diff] [blame] | 12497 | session_deps_.host_resolver.get(), session_deps_.socket_factory.get(), |
| 12498 | NULL, session_deps_.net_log); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12499 | auto mock_pool_manager = base::MakeUnique<MockClientSocketPoolManager>(); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 12500 | mock_pool_manager->SetTransportSocketPool(transport_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 12501 | session_peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12502 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12503 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12504 | TestCompletionCallback callback; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12505 | |
| 12506 | const MockWrite kGet( |
| 12507 | "GET / HTTP/1.1\r\n" |
| 12508 | "Host: www.example.com\r\n" |
| 12509 | "Connection: keep-alive\r\n\r\n"); |
| 12510 | const MockWrite kGetAuth( |
| 12511 | "GET / HTTP/1.1\r\n" |
| 12512 | "Host: www.example.com\r\n" |
| 12513 | "Connection: keep-alive\r\n" |
| 12514 | "Authorization: auth_token\r\n\r\n"); |
| 12515 | |
| 12516 | const MockRead kServerChallenge( |
| 12517 | "HTTP/1.1 401 Unauthorized\r\n" |
| 12518 | "WWW-Authenticate: Mock realm=server\r\n" |
| 12519 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12520 | "Content-Length: 14\r\n\r\n" |
| 12521 | "Unauthorized\r\n"); |
| 12522 | const MockRead kSuccess( |
| 12523 | "HTTP/1.1 200 OK\r\n" |
| 12524 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12525 | "Content-Length: 3\r\n\r\n" |
| 12526 | "Yes"); |
| 12527 | |
| 12528 | MockWrite writes[] = { |
| 12529 | // First round |
| 12530 | kGet, |
| 12531 | // Second round |
| 12532 | kGetAuth, |
| 12533 | // Third round |
| 12534 | kGetAuth, |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 12535 | // Fourth round |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12536 | kGetAuth, |
| 12537 | // Competing request |
| 12538 | kGet, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12539 | }; |
| 12540 | MockRead reads[] = { |
| 12541 | // First round |
| 12542 | kServerChallenge, |
| 12543 | // Second round |
| 12544 | kServerChallenge, |
| 12545 | // Third round |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 12546 | kServerChallenge, |
| 12547 | // Fourth round |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12548 | kSuccess, |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12549 | // Competing response |
| 12550 | kSuccess, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12551 | }; |
| 12552 | StaticSocketDataProvider data_provider(reads, arraysize(reads), |
| 12553 | writes, arraysize(writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12554 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12555 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 12556 | const char kSocketGroup[] = "www.example.com:80"; |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12557 | |
| 12558 | // First round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12559 | auth_handler->SetGenerateExpectation(false, OK); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12560 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12561 | if (rv == ERR_IO_PENDING) |
| 12562 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12563 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12564 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12565 | ASSERT_TRUE(response); |
| 12566 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12567 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12568 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 12569 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12570 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12571 | // In between rounds, another request comes in for the same domain. |
| 12572 | // It should not be able to grab the TCP socket that trans has already |
| 12573 | // claimed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12574 | HttpNetworkTransaction trans_compete(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12575 | TestCompletionCallback callback_compete; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12576 | rv = trans_compete.Start(&request, callback_compete.callback(), |
| 12577 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12578 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12579 | // callback_compete.WaitForResult at this point would stall forever, |
| 12580 | // since the HttpNetworkTransaction does not release the request back to |
| 12581 | // the pool until after authentication completes. |
| 12582 | |
| 12583 | // Second round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12584 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12585 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12586 | if (rv == ERR_IO_PENDING) |
| 12587 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12588 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12589 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12590 | ASSERT_TRUE(response); |
| 12591 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12592 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12593 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 12594 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12595 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12596 | // Third round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12597 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12598 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12599 | if (rv == ERR_IO_PENDING) |
| 12600 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12601 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12602 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12603 | ASSERT_TRUE(response); |
| 12604 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12605 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12606 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 12607 | auth_handler->state()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 12608 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12609 | // Fourth round of authentication, which completes successfully. |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 12610 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12611 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 12612 | if (rv == ERR_IO_PENDING) |
| 12613 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12614 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12615 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12616 | ASSERT_TRUE(response); |
| 12617 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12618 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12619 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12620 | // In WAIT_FOR_CHALLENGE, although in reality the auth handler is done. A real |
| 12621 | // auth handler should transition to a DONE state in concert with the remote |
| 12622 | // server. But that's not something we can test here with a mock handler. |
| 12623 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_CHALLENGE, |
| 12624 | auth_handler->state()); |
| 12625 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12626 | // Read the body since the fourth round was successful. This will also |
| 12627 | // release the socket back to the pool. |
| 12628 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(50)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12629 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12630 | if (rv == ERR_IO_PENDING) |
| 12631 | rv = callback.WaitForResult(); |
| 12632 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12633 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12634 | EXPECT_EQ(0, rv); |
| 12635 | // There are still 0 idle sockets, since the trans_compete transaction |
| 12636 | // will be handed it immediately after trans releases it to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12637 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12638 | |
| 12639 | // The competing request can now finish. Wait for the headers and then |
| 12640 | // read the body. |
| 12641 | rv = callback_compete.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12642 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12643 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12644 | if (rv == ERR_IO_PENDING) |
| 12645 | rv = callback.WaitForResult(); |
| 12646 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12647 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12648 | EXPECT_EQ(0, rv); |
| 12649 | |
| 12650 | // Finally, the socket is released to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12651 | EXPECT_EQ(1, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12652 | } |
| 12653 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12654 | // This tests the case that a request is issued via http instead of spdy after |
| 12655 | // npn is negotiated. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12656 | TEST_F(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12657 | HttpRequestInfo request; |
| 12658 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12659 | request.url = GURL("https://www.example.org/"); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12660 | |
| 12661 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12662 | MockWrite( |
| 12663 | "GET / HTTP/1.1\r\n" |
| 12664 | "Host: www.example.org\r\n" |
| 12665 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12666 | }; |
| 12667 | |
| 12668 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12669 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12670 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12671 | MockRead("\r\n"), |
| 12672 | MockRead("hello world"), |
| 12673 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12674 | }; |
| 12675 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12676 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12677 | ssl.next_proto = kProtoHTTP11; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12678 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12679 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12680 | |
| 12681 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 12682 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12683 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12684 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12685 | TestCompletionCallback callback; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12686 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12687 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12688 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12689 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12690 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12691 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12692 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12693 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12694 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12695 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12696 | ASSERT_TRUE(response); |
| 12697 | ASSERT_TRUE(response->headers); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12698 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12699 | |
| 12700 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12701 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12702 | EXPECT_EQ("hello world", response_data); |
| 12703 | |
| 12704 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12705 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12706 | } |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12707 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12708 | // Simulate the SSL handshake completing with an NPN negotiation followed by an |
| 12709 | // immediate server closing of the socket. |
| 12710 | // Regression test for https://crbug.com/46369. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12711 | TEST_F(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12712 | HttpRequestInfo request; |
| 12713 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12714 | request.url = GURL("https://www.example.org/"); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12715 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12716 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12717 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12718 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12719 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12720 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 12721 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12722 | MockWrite spdy_writes[] = {CreateMockWrite(req, 1)}; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12723 | |
| 12724 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12725 | MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12726 | }; |
| 12727 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12728 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 12729 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12730 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12731 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12732 | TestCompletionCallback callback; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12733 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12734 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12735 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12736 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12737 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12738 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12739 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12740 | } |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 12741 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 12742 | // A subclass of HttpAuthHandlerMock that records the request URL when |
| 12743 | // it gets it. This is needed since the auth handler may get destroyed |
| 12744 | // before we get a chance to query it. |
| 12745 | class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock { |
| 12746 | public: |
| 12747 | explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {} |
| 12748 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12749 | ~UrlRecordingHttpAuthHandlerMock() override {} |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 12750 | |
| 12751 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12752 | int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 12753 | const HttpRequestInfo* request, |
| 12754 | const CompletionCallback& callback, |
| 12755 | std::string* auth_token) override { |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 12756 | *url_ = request->url; |
| 12757 | return HttpAuthHandlerMock::GenerateAuthTokenImpl( |
| 12758 | credentials, request, callback, auth_token); |
| 12759 | } |
| 12760 | |
| 12761 | private: |
| 12762 | GURL* url_; |
| 12763 | }; |
| 12764 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12765 | // Test that if we cancel the transaction as the connection is completing, that |
| 12766 | // everything tears down correctly. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12767 | TEST_F(HttpNetworkTransactionTest, SimpleCancel) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12768 | // Setup everything about the connection to complete synchronously, so that |
| 12769 | // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
| 12770 | // for is the callback from the HttpStreamRequest. |
| 12771 | // Then cancel the transaction. |
| 12772 | // Verify that we don't crash. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12773 | MockConnect mock_connect(SYNCHRONOUS, OK); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12774 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12775 | MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), |
| 12776 | MockRead(SYNCHRONOUS, "hello world"), |
| 12777 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12778 | }; |
| 12779 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12780 | HttpRequestInfo request; |
| 12781 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12782 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12783 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12784 | session_deps_.host_resolver->set_synchronous_mode(true); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12785 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12786 | auto trans = |
| 12787 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12788 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12789 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 12790 | data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12791 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12792 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12793 | TestCompletionCallback callback; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12794 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12795 | BoundTestNetLog log; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12796 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12797 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12798 | trans.reset(); // Cancel the transaction here. |
| 12799 | |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 12800 | base::RunLoop().RunUntilIdle(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 12801 | } |
| 12802 | |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12803 | // Test that if a transaction is cancelled after receiving the headers, the |
| 12804 | // stream is drained properly and added back to the socket pool. The main |
| 12805 | // purpose of this test is to make sure that an HttpStreamParser can be read |
| 12806 | // from after the HttpNetworkTransaction and the objects it owns have been |
| 12807 | // deleted. |
| 12808 | // See http://crbug.com/368418 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12809 | TEST_F(HttpNetworkTransactionTest, CancelAfterHeaders) { |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12810 | MockRead data_reads[] = { |
| 12811 | MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"), |
| 12812 | MockRead(ASYNC, "Content-Length: 2\r\n"), |
| 12813 | MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"), |
| 12814 | MockRead(ASYNC, "1"), |
| 12815 | // 2 async reads are necessary to trigger a ReadResponseBody call after the |
| 12816 | // HttpNetworkTransaction has been deleted. |
| 12817 | MockRead(ASYNC, "2"), |
| 12818 | MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this. |
| 12819 | }; |
| 12820 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 12821 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12822 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12823 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12824 | |
| 12825 | { |
| 12826 | HttpRequestInfo request; |
| 12827 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12828 | request.url = GURL("http://www.example.org/"); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12829 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12830 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12831 | TestCompletionCallback callback; |
| 12832 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12833 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12834 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12835 | callback.WaitForResult(); |
| 12836 | |
| 12837 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12838 | ASSERT_TRUE(response); |
| 12839 | EXPECT_TRUE(response->headers); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12840 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12841 | |
| 12842 | // The transaction and HttpRequestInfo are deleted. |
| 12843 | } |
| 12844 | |
| 12845 | // Let the HttpResponseBodyDrainer drain the socket. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 12846 | base::RunLoop().RunUntilIdle(); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12847 | |
| 12848 | // Socket should now be idle, waiting to be reused. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12849 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12850 | } |
| 12851 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12852 | // Test a basic GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12853 | TEST_F(HttpNetworkTransactionTest, ProxyGet) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12854 | session_deps_.proxy_service = |
| 12855 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12856 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12857 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12858 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12859 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12860 | HttpRequestInfo request; |
| 12861 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12862 | request.url = GURL("http://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12863 | |
| 12864 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12865 | MockWrite( |
| 12866 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 12867 | "Host: www.example.org\r\n" |
| 12868 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12869 | }; |
| 12870 | |
| 12871 | MockRead data_reads1[] = { |
| 12872 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12873 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 12874 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12875 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12876 | }; |
| 12877 | |
| 12878 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 12879 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12880 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12881 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12882 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12883 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12884 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 12885 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12886 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 12887 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 12888 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12889 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12890 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12891 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12892 | |
| 12893 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12894 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12895 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12896 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12897 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12898 | |
| 12899 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 12900 | EXPECT_EQ(200, response->headers->response_code()); |
| 12901 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 12902 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 12903 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 12904 | HostPortPair::FromString("myproxy:70")), |
| 12905 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 12906 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 12907 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 12908 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12909 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12910 | |
| 12911 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12912 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12913 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12914 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12915 | } |
| 12916 | |
| 12917 | // Test a basic HTTPS GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12918 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGet) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12919 | session_deps_.proxy_service = |
| 12920 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12921 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12922 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12923 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12924 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12925 | HttpRequestInfo request; |
| 12926 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12927 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12928 | |
| 12929 | // Since we have proxy, should try to establish tunnel. |
| 12930 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12931 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 12932 | "Host: www.example.org:443\r\n" |
| 12933 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12934 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12935 | MockWrite("GET / HTTP/1.1\r\n" |
| 12936 | "Host: www.example.org\r\n" |
| 12937 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12938 | }; |
| 12939 | |
| 12940 | MockRead data_reads1[] = { |
| 12941 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 12942 | |
| 12943 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12944 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 12945 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12946 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12947 | }; |
| 12948 | |
| 12949 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 12950 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12951 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12952 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12953 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12954 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12955 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12956 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12957 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 12958 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12959 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 12960 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 12961 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12962 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12963 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12964 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12965 | |
| 12966 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12967 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 12968 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12969 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12970 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 12971 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 12972 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12973 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12974 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 12975 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 12976 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12977 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12978 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12979 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12980 | |
| 12981 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 12982 | EXPECT_EQ(200, response->headers->response_code()); |
| 12983 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 12984 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 12985 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 12986 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 12987 | HostPortPair::FromString("myproxy:70")), |
| 12988 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 12989 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 12990 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 12991 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12992 | |
| 12993 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12994 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12995 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12996 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12997 | } |
| 12998 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12999 | // Test a basic HTTPS GET request through a proxy, connecting to an IPv6 |
| 13000 | // literal host. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13001 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetIPv6) { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13002 | session_deps_.proxy_service = |
| 13003 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 13004 | BoundTestNetLog log; |
| 13005 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13006 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13007 | |
| 13008 | HttpRequestInfo request; |
| 13009 | request.method = "GET"; |
| 13010 | request.url = GURL("https://[::1]:443/"); |
| 13011 | |
| 13012 | // Since we have proxy, should try to establish tunnel. |
| 13013 | MockWrite data_writes1[] = { |
| 13014 | MockWrite("CONNECT [::1]:443 HTTP/1.1\r\n" |
| 13015 | "Host: [::1]:443\r\n" |
| 13016 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 13017 | |
| 13018 | MockWrite("GET / HTTP/1.1\r\n" |
| 13019 | "Host: [::1]\r\n" |
| 13020 | "Connection: keep-alive\r\n\r\n"), |
| 13021 | }; |
| 13022 | |
| 13023 | MockRead data_reads1[] = { |
| 13024 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 13025 | |
| 13026 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13027 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 13028 | MockRead("Content-Length: 100\r\n\r\n"), |
| 13029 | MockRead(SYNCHRONOUS, OK), |
| 13030 | }; |
| 13031 | |
| 13032 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 13033 | data_writes1, arraysize(data_writes1)); |
| 13034 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 13035 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 13036 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13037 | |
| 13038 | TestCompletionCallback callback1; |
| 13039 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13040 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13041 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13042 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13043 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13044 | |
| 13045 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13046 | EXPECT_THAT(rv, IsOk()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13047 | TestNetLogEntry::List entries; |
| 13048 | log.GetEntries(&entries); |
| 13049 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13050 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 13051 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13052 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13053 | entries, pos, |
| 13054 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 13055 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13056 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13057 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13058 | ASSERT_TRUE(response); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13059 | |
| 13060 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 13061 | EXPECT_EQ(200, response->headers->response_code()); |
| 13062 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 13063 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 13064 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 13065 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 13066 | HostPortPair::FromString("myproxy:70")), |
| 13067 | response->proxy_server); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13068 | |
| 13069 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13070 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13071 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 13072 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 13073 | } |
| 13074 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13075 | // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 13076 | // while establishing the tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13077 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 13078 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13079 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13080 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13081 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13082 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13083 | HttpRequestInfo request; |
| 13084 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13085 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13086 | |
| 13087 | // Since we have proxy, should try to establish tunnel. |
| 13088 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13089 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 13090 | "Host: www.example.org:443\r\n" |
| 13091 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13092 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13093 | MockWrite("GET / HTTP/1.1\r\n" |
| 13094 | "Host: www.example.org\r\n" |
| 13095 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13096 | }; |
| 13097 | |
| 13098 | MockRead data_reads1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13099 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13100 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13101 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13102 | }; |
| 13103 | |
| 13104 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 13105 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13106 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13107 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13108 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13109 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13110 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13111 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13112 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13113 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13114 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13115 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13116 | |
| 13117 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13118 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 13119 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 13120 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13121 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13122 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 13123 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13124 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 13125 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13126 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 13127 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13128 | } |
| 13129 | |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13130 | // Test for crbug.com/55424. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13131 | TEST_F(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13132 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13133 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13134 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13135 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13136 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13137 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13138 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13139 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13140 | }; |
| 13141 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13142 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 13143 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13144 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13145 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13146 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13147 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13148 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13149 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13150 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13151 | |
| 13152 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13153 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 13154 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 13155 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13156 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 13157 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13158 | |
| 13159 | HttpRequestInfo request; |
| 13160 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13161 | request.url = GURL("https://www.example.org/"); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13162 | |
| 13163 | // This is the important line that marks this as a preconnect. |
| 13164 | request.motivation = HttpRequestInfo::PRECONNECT_MOTIVATED; |
| 13165 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13166 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13167 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13168 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13169 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13170 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13171 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13172 | } |
| 13173 | |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13174 | // Given a net error, cause that error to be returned from the first Write() |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13175 | // call and verify that the HttpNetworkTransaction fails with that error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13176 | void HttpNetworkTransactionTest::CheckErrorIsPassedBack( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13177 | int error, IoMode mode) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13178 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13179 | request_info.url = GURL("https://www.example.com/"); |
| 13180 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13181 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13182 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13183 | SSLSocketDataProvider ssl_data(mode, OK); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13184 | MockWrite data_writes[] = { |
| 13185 | MockWrite(mode, error), |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13186 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13187 | StaticSocketDataProvider data(NULL, 0, data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13188 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13189 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13190 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13191 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13192 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13193 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13194 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13195 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13196 | if (rv == ERR_IO_PENDING) |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13197 | rv = callback.WaitForResult(); |
| 13198 | ASSERT_EQ(error, rv); |
| 13199 | } |
| 13200 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13201 | TEST_F(HttpNetworkTransactionTest, SSLWriteCertError) { |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13202 | // Just check a grab bag of cert errors. |
| 13203 | static const int kErrors[] = { |
| 13204 | ERR_CERT_COMMON_NAME_INVALID, |
| 13205 | ERR_CERT_AUTHORITY_INVALID, |
| 13206 | ERR_CERT_DATE_INVALID, |
| 13207 | }; |
| 13208 | for (size_t i = 0; i < arraysize(kErrors); i++) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13209 | CheckErrorIsPassedBack(kErrors[i], ASYNC); |
| 13210 | CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13211 | } |
| 13212 | } |
| 13213 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13214 | // Ensure that a client certificate is removed from the SSL client auth |
| 13215 | // cache when: |
| 13216 | // 1) No proxy is involved. |
| 13217 | // 2) TLS False Start is disabled. |
| 13218 | // 3) The initial TLS handshake requests a client certificate. |
| 13219 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13220 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_NoFalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13221 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13222 | request_info.url = GURL("https://www.example.com/"); |
| 13223 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13224 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13225 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13226 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13227 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13228 | |
| 13229 | // [ssl_]data1 contains the data for the first SSL handshake. When a |
| 13230 | // CertificateRequest is received for the first time, the handshake will |
| 13231 | // be aborted to allow the caller to provide a certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13232 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13233 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13234 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13235 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13236 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13237 | |
| 13238 | // [ssl_]data2 contains the data for the second SSL handshake. When TLS |
| 13239 | // False Start is not being used, the result of the SSL handshake will be |
| 13240 | // returned as part of the SSLClientSocket::Connect() call. This test |
| 13241 | // matches the result of a server sending a handshake_failure alert, |
| 13242 | // rather than a Finished message, because it requires a client |
| 13243 | // certificate and none was supplied. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13244 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13245 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13246 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13247 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13248 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13249 | |
| 13250 | // [ssl_]data3 contains the data for the third SSL handshake. When a |
| 13251 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 13252 | // HttpNetworkTransaction will attempt to fallback to TLSv1.1 if the previous |
| 13253 | // connection was attempted with TLSv1.2. This is transparent to the caller |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13254 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 13255 | // requiring a client certificate, this fallback handshake should also |
| 13256 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13257 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13258 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13259 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13260 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13261 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13262 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13263 | // [ssl_]data4 contains the data for the fourth SSL handshake. When a |
| 13264 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 13265 | // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous |
| 13266 | // connection was attempted with TLSv1.1. This is transparent to the caller |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13267 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 13268 | // requiring a client certificate, this fallback handshake should also |
| 13269 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13270 | SSLSocketDataProvider ssl_data4(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13271 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13272 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13273 | StaticSocketDataProvider data4(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13274 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13275 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13276 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13277 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13278 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13279 | // Begin the SSL handshake with the peer. This consumes ssl_data1. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13280 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13281 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13282 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13283 | |
| 13284 | // Complete the SSL handshake, which should abort due to requiring a |
| 13285 | // client certificate. |
| 13286 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13287 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13288 | |
| 13289 | // Indicate that no certificate should be supplied. From the perspective |
| 13290 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 13291 | // certificate, so this is the same as supply a |
| 13292 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13293 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13294 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13295 | |
| 13296 | // Ensure the certificate was added to the client auth cache before |
| 13297 | // allowing the connection to continue restarting. |
| 13298 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13299 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13300 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13301 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13302 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13303 | |
| 13304 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13305 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 13306 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13307 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13308 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13309 | |
| 13310 | // Ensure that the client certificate is removed from the cache on a |
| 13311 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13312 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13313 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13314 | } |
| 13315 | |
| 13316 | // Ensure that a client certificate is removed from the SSL client auth |
| 13317 | // cache when: |
| 13318 | // 1) No proxy is involved. |
| 13319 | // 2) TLS False Start is enabled. |
| 13320 | // 3) The initial TLS handshake requests a client certificate. |
| 13321 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13322 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_FalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13323 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13324 | request_info.url = GURL("https://www.example.com/"); |
| 13325 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13326 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13327 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13328 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13329 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13330 | |
| 13331 | // When TLS False Start is used, SSLClientSocket::Connect() calls will |
| 13332 | // return successfully after reading up to the peer's Certificate message. |
| 13333 | // This is to allow the caller to call SSLClientSocket::Write(), which can |
| 13334 | // enqueue application data to be sent in the same packet as the |
| 13335 | // ChangeCipherSpec and Finished messages. |
| 13336 | // The actual handshake will be finished when SSLClientSocket::Read() is |
| 13337 | // called, which expects to process the peer's ChangeCipherSpec and |
| 13338 | // Finished messages. If there was an error negotiating with the peer, |
| 13339 | // such as due to the peer requiring a client certificate when none was |
| 13340 | // supplied, the alert sent by the peer won't be processed until Read() is |
| 13341 | // called. |
| 13342 | |
| 13343 | // Like the non-False Start case, when a client certificate is requested by |
| 13344 | // the peer, the handshake is aborted during the Connect() call. |
| 13345 | // [ssl_]data1 represents the initial SSL handshake with the peer. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13346 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13347 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13348 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13349 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13350 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13351 | |
| 13352 | // When a client certificate is supplied, Connect() will not be aborted |
| 13353 | // when the peer requests the certificate. Instead, the handshake will |
| 13354 | // artificially succeed, allowing the caller to write the HTTP request to |
| 13355 | // the socket. The handshake messages are not processed until Read() is |
| 13356 | // called, which then detects that the handshake was aborted, due to the |
| 13357 | // peer sending a handshake_failure because it requires a client |
| 13358 | // certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13359 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13360 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13361 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13362 | MockRead data2_reads[] = { |
| 13363 | MockRead(ASYNC /* async */, ERR_SSL_PROTOCOL_ERROR), |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13364 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13365 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13366 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13367 | |
| 13368 | // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13369 | // the data for the SSL handshake once the TLSv1.1 connection falls back to |
| 13370 | // TLSv1. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13371 | SSLSocketDataProvider ssl_data3(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13372 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13373 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13374 | StaticSocketDataProvider data3(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13375 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13376 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13377 | // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection |
| 13378 | // falls back to SSLv3. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13379 | SSLSocketDataProvider ssl_data4(ASYNC, OK); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13380 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13381 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13382 | StaticSocketDataProvider data4(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13383 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13384 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 13385 | // Need one more if TLSv1.2 is enabled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13386 | SSLSocketDataProvider ssl_data5(ASYNC, OK); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 13387 | ssl_data5.cert_request_info = cert_request.get(); |
| 13388 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13389 | StaticSocketDataProvider data5(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 13390 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 13391 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13392 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13393 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13394 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13395 | // Begin the initial SSL handshake. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13396 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13397 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13398 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13399 | |
| 13400 | // Complete the SSL handshake, which should abort due to requiring a |
| 13401 | // client certificate. |
| 13402 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13403 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13404 | |
| 13405 | // Indicate that no certificate should be supplied. From the perspective |
| 13406 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 13407 | // certificate, so this is the same as supply a |
| 13408 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13409 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13410 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13411 | |
| 13412 | // Ensure the certificate was added to the client auth cache before |
| 13413 | // allowing the connection to continue restarting. |
| 13414 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13415 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13416 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13417 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13418 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13419 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13420 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13421 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 13422 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13423 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13424 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13425 | |
| 13426 | // Ensure that the client certificate is removed from the cache on a |
| 13427 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13428 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13429 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13430 | } |
| 13431 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13432 | // Ensure that a client certificate is removed from the SSL client auth |
| 13433 | // cache when: |
| 13434 | // 1) An HTTPS proxy is involved. |
| 13435 | // 3) The HTTPS proxy requests a client certificate. |
| 13436 | // 4) The client supplies an invalid/unacceptable certificate for the |
| 13437 | // proxy. |
| 13438 | // The test is repeated twice, first for connecting to an HTTPS endpoint, |
| 13439 | // then for connecting to an HTTP endpoint. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13440 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 13441 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13442 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13443 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13444 | |
| 13445 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13446 | cert_request->host_and_port = HostPortPair("proxy", 70); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13447 | |
| 13448 | // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of |
| 13449 | // [ssl_]data[1-3]. Rather than represending the endpoint |
| 13450 | // (www.example.com:443), they represent failures with the HTTPS proxy |
| 13451 | // (proxy:70). |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13452 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13453 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13454 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13455 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13456 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13457 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13458 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13459 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13460 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13461 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13462 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13463 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13464 | // TODO(wtc): find out why this unit test doesn't need [ssl_]data3. |
| 13465 | #if 0 |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13466 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13467 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13468 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13469 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13470 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13471 | #endif |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13472 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13473 | HttpRequestInfo requests[2]; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13474 | requests[0].url = GURL("https://www.example.com/"); |
| 13475 | requests[0].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13476 | requests[0].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13477 | |
| 13478 | requests[1].url = GURL("http://www.example.com/"); |
| 13479 | requests[1].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13480 | requests[1].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13481 | |
| 13482 | for (size_t i = 0; i < arraysize(requests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13483 | session_deps_.socket_factory->ResetNextMockIndexes(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13484 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13485 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13486 | |
| 13487 | // Begin the SSL handshake with the proxy. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13488 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13489 | int rv = trans.Start(&requests[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13490 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13491 | |
| 13492 | // Complete the SSL handshake, which should abort due to requiring a |
| 13493 | // client certificate. |
| 13494 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13495 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13496 | |
| 13497 | // Indicate that no certificate should be supplied. From the perspective |
| 13498 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 13499 | // certificate, so this is the same as supply a |
| 13500 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13501 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13502 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13503 | |
| 13504 | // Ensure the certificate was added to the client auth cache before |
| 13505 | // allowing the connection to continue restarting. |
| 13506 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13507 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13508 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13509 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13510 | ASSERT_FALSE(client_cert); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13511 | // Ensure the certificate was NOT cached for the endpoint. This only |
| 13512 | // applies to HTTPS requests, but is fine to check for HTTP requests. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13513 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13514 | HostPortPair("www.example.com", 443), &client_cert, |
| 13515 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13516 | |
| 13517 | // Restart the handshake. This will consume ssl_data2, which fails, and |
| 13518 | // then consume ssl_data3, which should also fail. The result code is |
| 13519 | // checked against what ssl_data3 should return. |
| 13520 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13521 | ASSERT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13522 | |
| 13523 | // Now that the new handshake has failed, ensure that the client |
| 13524 | // certificate was removed from the client auth cache. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13525 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13526 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13527 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13528 | HostPortPair("www.example.com", 443), &client_cert, |
| 13529 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13530 | } |
| 13531 | } |
| 13532 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13533 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPooling) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13534 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13535 | session_deps_.host_resolver = base::MakeUnique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13536 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13537 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13538 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13539 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13540 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13541 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13542 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13543 | SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13544 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13545 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13546 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13547 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13548 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13549 | SpdySerializedFrame host1_resp_body( |
| 13550 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13551 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13552 | SpdySerializedFrame host2_resp_body( |
| 13553 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13554 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13555 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 13556 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13557 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13558 | }; |
| 13559 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 13560 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13561 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13562 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 13563 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13564 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13565 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 13566 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13567 | HttpRequestInfo request1; |
| 13568 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13569 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13570 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13571 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13572 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13573 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13574 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13575 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13576 | |
| 13577 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13578 | ASSERT_TRUE(response); |
| 13579 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13580 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13581 | |
| 13582 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13583 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13584 | EXPECT_EQ("hello!", response_data); |
| 13585 | |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13586 | // Preload mail.example.com into HostCache. |
| 13587 | HostPortPair host_port("mail.example.com", 443); |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 13588 | HostResolver::RequestInfo resolve_info(host_port); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13589 | AddressList ignored; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 13590 | std::unique_ptr<HostResolver::Request> request; |
| 13591 | rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 13592 | &ignored, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13593 | &request, NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13594 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 13595 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13596 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13597 | |
| 13598 | HttpRequestInfo request2; |
| 13599 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13600 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13601 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13602 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13603 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13604 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13605 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13606 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13607 | |
| 13608 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13609 | ASSERT_TRUE(response); |
| 13610 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13611 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13612 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13613 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13614 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13615 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13616 | } |
| 13617 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13618 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) { |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13619 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13620 | session_deps_.host_resolver = base::MakeUnique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13621 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13622 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13623 | AddSSLSocketData(); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13624 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13625 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13626 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13627 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13628 | SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13629 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13630 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13631 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13632 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13633 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13634 | SpdySerializedFrame host1_resp_body( |
| 13635 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13636 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13637 | SpdySerializedFrame host2_resp_body( |
| 13638 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13639 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13640 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 13641 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13642 | MockRead(ASYNC, 0, 6), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13643 | }; |
| 13644 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 13645 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13646 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13647 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 13648 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13649 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13650 | |
| 13651 | TestCompletionCallback callback; |
| 13652 | HttpRequestInfo request1; |
| 13653 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13654 | request1.url = GURL("https://www.example.org/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13655 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13656 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13657 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13658 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13659 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13660 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13661 | |
| 13662 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13663 | ASSERT_TRUE(response); |
| 13664 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13665 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13666 | |
| 13667 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13668 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13669 | EXPECT_EQ("hello!", response_data); |
| 13670 | |
| 13671 | HttpRequestInfo request2; |
| 13672 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13673 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13674 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13675 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13676 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13677 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13678 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13679 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13680 | |
| 13681 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13682 | ASSERT_TRUE(response); |
| 13683 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13684 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13685 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13686 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13687 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13688 | EXPECT_EQ("hello!", response_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13689 | } |
| 13690 | |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 13691 | // Regression test for https://crbug.com/546991. |
| 13692 | // The server might not be able to serve an IP pooled request, and might send a |
| 13693 | // 421 Misdirected Request response status to indicate this. |
| 13694 | // HttpNetworkTransaction should reset the request and retry without IP pooling. |
| 13695 | TEST_F(HttpNetworkTransactionTest, RetryWithoutConnectionPooling) { |
| 13696 | // Two hosts resolve to the same IP address. |
| 13697 | const std::string ip_addr = "1.2.3.4"; |
| 13698 | IPAddress ip; |
| 13699 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 13700 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 13701 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13702 | session_deps_.host_resolver = base::MakeUnique<MockCachingHostResolver>(); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 13703 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 13704 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 13705 | |
| 13706 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13707 | |
| 13708 | // Two requests on the first connection. |
| 13709 | SpdySerializedFrame req1( |
| 13710 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 13711 | spdy_util_.UpdateWithStreamDestruction(1); |
| 13712 | SpdySerializedFrame req2( |
| 13713 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
| 13714 | SpdySerializedFrame rst( |
| 13715 | spdy_util_.ConstructSpdyRstStream(3, ERROR_CODE_CANCEL)); |
| 13716 | MockWrite writes1[] = { |
| 13717 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 13718 | CreateMockWrite(rst, 6), |
| 13719 | }; |
| 13720 | |
| 13721 | // The first one succeeds, the second gets error 421 Misdirected Request. |
| 13722 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 13723 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 13724 | SpdyHeaderBlock response_headers; |
| 13725 | response_headers[SpdyTestUtil::GetStatusKey()] = "421"; |
| 13726 | SpdySerializedFrame resp2( |
| 13727 | spdy_util_.ConstructSpdyReply(3, std::move(response_headers))); |
| 13728 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 13729 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 13730 | |
| 13731 | MockConnect connect1(ASYNC, OK, peer_addr); |
| 13732 | SequencedSocketData data1(connect1, reads1, arraysize(reads1), writes1, |
| 13733 | arraysize(writes1)); |
| 13734 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 13735 | |
| 13736 | AddSSLSocketData(); |
| 13737 | |
| 13738 | // Retry the second request on a second connection. |
| 13739 | SpdyTestUtil spdy_util2; |
| 13740 | SpdySerializedFrame req3( |
| 13741 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 13742 | MockWrite writes2[] = { |
| 13743 | CreateMockWrite(req3, 0), |
| 13744 | }; |
| 13745 | |
| 13746 | SpdySerializedFrame resp3(spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 13747 | SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 13748 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 13749 | MockRead(ASYNC, 0, 3)}; |
| 13750 | |
| 13751 | MockConnect connect2(ASYNC, OK, peer_addr); |
| 13752 | SequencedSocketData data2(connect2, reads2, arraysize(reads2), writes2, |
| 13753 | arraysize(writes2)); |
| 13754 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 13755 | |
| 13756 | AddSSLSocketData(); |
| 13757 | |
| 13758 | // Preload mail.example.org into HostCache. |
| 13759 | HostPortPair host_port("mail.example.org", 443); |
| 13760 | HostResolver::RequestInfo resolve_info(host_port); |
| 13761 | AddressList ignored; |
| 13762 | std::unique_ptr<HostResolver::Request> request; |
| 13763 | TestCompletionCallback callback; |
| 13764 | int rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 13765 | &ignored, callback.callback(), |
| 13766 | &request, NetLogWithSource()); |
| 13767 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13768 | rv = callback.WaitForResult(); |
| 13769 | EXPECT_THAT(rv, IsOk()); |
| 13770 | |
| 13771 | HttpRequestInfo request1; |
| 13772 | request1.method = "GET"; |
| 13773 | request1.url = GURL("https://www.example.org/"); |
| 13774 | request1.load_flags = 0; |
| 13775 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 13776 | |
| 13777 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 13778 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13779 | rv = callback.WaitForResult(); |
| 13780 | EXPECT_THAT(rv, IsOk()); |
| 13781 | |
| 13782 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 13783 | ASSERT_TRUE(response); |
| 13784 | ASSERT_TRUE(response->headers); |
| 13785 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 13786 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 13787 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 13788 | std::string response_data; |
| 13789 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 13790 | EXPECT_EQ("hello!", response_data); |
| 13791 | |
| 13792 | HttpRequestInfo request2; |
| 13793 | request2.method = "GET"; |
| 13794 | request2.url = GURL("https://mail.example.org/"); |
| 13795 | request2.load_flags = 0; |
| 13796 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 13797 | |
| 13798 | BoundTestNetLog log; |
| 13799 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 13800 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13801 | rv = callback.WaitForResult(); |
| 13802 | EXPECT_THAT(rv, IsOk()); |
| 13803 | |
| 13804 | response = trans2.GetResponseInfo(); |
| 13805 | ASSERT_TRUE(response); |
| 13806 | ASSERT_TRUE(response->headers); |
| 13807 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 13808 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 13809 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 13810 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 13811 | EXPECT_EQ("hello!", response_data); |
| 13812 | |
| 13813 | TestNetLogEntry::List entries; |
| 13814 | log.GetEntries(&entries); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 13815 | ExpectLogContainsSomewhere( |
| 13816 | entries, 0, NetLogEventType::HTTP_TRANSACTION_RESTART_MISDIRECTED_REQUEST, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 13817 | NetLogEventPhase::NONE); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 13818 | } |
| 13819 | |
| 13820 | // Test that HTTP 421 responses are properly returned to the caller if received |
| 13821 | // on the retry as well. HttpNetworkTransaction should not infinite loop or lose |
| 13822 | // portions of the response. |
| 13823 | TEST_F(HttpNetworkTransactionTest, ReturnHTTP421OnRetry) { |
| 13824 | // Two hosts resolve to the same IP address. |
| 13825 | const std::string ip_addr = "1.2.3.4"; |
| 13826 | IPAddress ip; |
| 13827 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 13828 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 13829 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13830 | session_deps_.host_resolver = base::MakeUnique<MockCachingHostResolver>(); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 13831 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 13832 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 13833 | |
| 13834 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13835 | |
| 13836 | // Two requests on the first connection. |
| 13837 | SpdySerializedFrame req1( |
| 13838 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 13839 | spdy_util_.UpdateWithStreamDestruction(1); |
| 13840 | SpdySerializedFrame req2( |
| 13841 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
| 13842 | SpdySerializedFrame rst( |
| 13843 | spdy_util_.ConstructSpdyRstStream(3, ERROR_CODE_CANCEL)); |
| 13844 | MockWrite writes1[] = { |
| 13845 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 13846 | CreateMockWrite(rst, 6), |
| 13847 | }; |
| 13848 | |
| 13849 | // The first one succeeds, the second gets error 421 Misdirected Request. |
| 13850 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 13851 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 13852 | SpdyHeaderBlock response_headers; |
| 13853 | response_headers[SpdyTestUtil::GetStatusKey()] = "421"; |
| 13854 | SpdySerializedFrame resp2( |
| 13855 | spdy_util_.ConstructSpdyReply(3, response_headers.Clone())); |
| 13856 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 13857 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 13858 | |
| 13859 | MockConnect connect1(ASYNC, OK, peer_addr); |
| 13860 | SequencedSocketData data1(connect1, reads1, arraysize(reads1), writes1, |
| 13861 | arraysize(writes1)); |
| 13862 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 13863 | |
| 13864 | AddSSLSocketData(); |
| 13865 | |
| 13866 | // Retry the second request on a second connection. It returns 421 Misdirected |
| 13867 | // Retry again. |
| 13868 | SpdyTestUtil spdy_util2; |
| 13869 | SpdySerializedFrame req3( |
| 13870 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 13871 | MockWrite writes2[] = { |
| 13872 | CreateMockWrite(req3, 0), |
| 13873 | }; |
| 13874 | |
| 13875 | SpdySerializedFrame resp3( |
| 13876 | spdy_util2.ConstructSpdyReply(1, std::move(response_headers))); |
| 13877 | SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 13878 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 13879 | MockRead(ASYNC, 0, 3)}; |
| 13880 | |
| 13881 | MockConnect connect2(ASYNC, OK, peer_addr); |
| 13882 | SequencedSocketData data2(connect2, reads2, arraysize(reads2), writes2, |
| 13883 | arraysize(writes2)); |
| 13884 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 13885 | |
| 13886 | AddSSLSocketData(); |
| 13887 | |
| 13888 | // Preload mail.example.org into HostCache. |
| 13889 | HostPortPair host_port("mail.example.org", 443); |
| 13890 | HostResolver::RequestInfo resolve_info(host_port); |
| 13891 | AddressList ignored; |
| 13892 | std::unique_ptr<HostResolver::Request> request; |
| 13893 | TestCompletionCallback callback; |
| 13894 | int rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 13895 | &ignored, callback.callback(), |
| 13896 | &request, NetLogWithSource()); |
| 13897 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13898 | rv = callback.WaitForResult(); |
| 13899 | EXPECT_THAT(rv, IsOk()); |
| 13900 | |
| 13901 | HttpRequestInfo request1; |
| 13902 | request1.method = "GET"; |
| 13903 | request1.url = GURL("https://www.example.org/"); |
| 13904 | request1.load_flags = 0; |
| 13905 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 13906 | |
| 13907 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 13908 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13909 | rv = callback.WaitForResult(); |
| 13910 | EXPECT_THAT(rv, IsOk()); |
| 13911 | |
| 13912 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 13913 | ASSERT_TRUE(response); |
| 13914 | ASSERT_TRUE(response->headers); |
| 13915 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 13916 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 13917 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 13918 | std::string response_data; |
| 13919 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 13920 | EXPECT_EQ("hello!", response_data); |
| 13921 | |
| 13922 | HttpRequestInfo request2; |
| 13923 | request2.method = "GET"; |
| 13924 | request2.url = GURL("https://mail.example.org/"); |
| 13925 | request2.load_flags = 0; |
| 13926 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 13927 | |
| 13928 | BoundTestNetLog log; |
| 13929 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 13930 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13931 | rv = callback.WaitForResult(); |
| 13932 | EXPECT_THAT(rv, IsOk()); |
| 13933 | |
| 13934 | // After a retry, the 421 Misdirected Request is reported back up to the |
| 13935 | // caller. |
| 13936 | response = trans2.GetResponseInfo(); |
| 13937 | ASSERT_TRUE(response); |
| 13938 | ASSERT_TRUE(response->headers); |
| 13939 | EXPECT_EQ("HTTP/1.1 421", response->headers->GetStatusLine()); |
| 13940 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 13941 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 13942 | EXPECT_TRUE(response->ssl_info.cert); |
| 13943 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 13944 | EXPECT_EQ("hello!", response_data); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 13945 | } |
| 13946 | |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 13947 | class OneTimeCachingHostResolver : public MockHostResolverBase { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13948 | public: |
| 13949 | explicit OneTimeCachingHostResolver(const HostPortPair& host_port) |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 13950 | : MockHostResolverBase(/* use_caching = */ true), host_port_(host_port) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13951 | ~OneTimeCachingHostResolver() override {} |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13952 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13953 | int ResolveFromCache(const RequestInfo& info, |
| 13954 | AddressList* addresses, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13955 | const NetLogWithSource& net_log) override { |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 13956 | int rv = MockHostResolverBase::ResolveFromCache(info, addresses, net_log); |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 13957 | if (rv == OK && info.host_port_pair().Equals(host_port_)) |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 13958 | GetHostCache()->clear(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13959 | return rv; |
| 13960 | } |
| 13961 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13962 | private: |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13963 | const HostPortPair host_port_; |
| 13964 | }; |
| 13965 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13966 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 13967 | UseIPConnectionPoolingWithHostCacheExpiration) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13968 | // Set up a special HttpNetworkSession with a OneTimeCachingHostResolver. |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 13969 | session_deps_.host_resolver = base::MakeUnique<OneTimeCachingHostResolver>( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13970 | HostPortPair("mail.example.com", 443)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13971 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13972 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13973 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13974 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13975 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13976 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13977 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13978 | SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13979 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13980 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13981 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13982 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13983 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13984 | SpdySerializedFrame host1_resp_body( |
| 13985 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13986 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13987 | SpdySerializedFrame host2_resp_body( |
| 13988 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13989 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13990 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 13991 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13992 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13993 | }; |
| 13994 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 13995 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13996 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13997 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 13998 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13999 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14000 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 14001 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14002 | HttpRequestInfo request1; |
| 14003 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14004 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14005 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14006 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14007 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14008 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14009 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14010 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14011 | |
| 14012 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14013 | ASSERT_TRUE(response); |
| 14014 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14015 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14016 | |
| 14017 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14018 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14019 | EXPECT_EQ("hello!", response_data); |
| 14020 | |
| 14021 | // Preload cache entries into HostCache. |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14022 | HostResolver::RequestInfo resolve_info(HostPortPair("mail.example.com", 443)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14023 | AddressList ignored; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 14024 | std::unique_ptr<HostResolver::Request> request; |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 14025 | rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 14026 | &ignored, callback.callback(), |
| 14027 | &request, NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14028 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 14029 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14030 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14031 | |
| 14032 | HttpRequestInfo request2; |
| 14033 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14034 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14035 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14036 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14037 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14038 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14039 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14040 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14041 | |
| 14042 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14043 | ASSERT_TRUE(response); |
| 14044 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14045 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14046 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14047 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14048 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14049 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14050 | } |
| 14051 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14052 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14053 | const std::string https_url = "https://www.example.org:8080/"; |
| 14054 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14055 | |
| 14056 | // SPDY GET for HTTPS URL |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14057 | SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14058 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14059 | |
| 14060 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14061 | CreateMockWrite(req1, 0), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14062 | }; |
| 14063 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14064 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14065 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 14066 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 14067 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3)}; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14068 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14069 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 14070 | arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14071 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 14072 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14073 | |
| 14074 | // HTTP GET for the HTTP URL |
| 14075 | MockWrite writes2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14076 | MockWrite(ASYNC, 0, |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 14077 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14078 | "Host: www.example.org:8080\r\n" |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 14079 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14080 | }; |
| 14081 | |
| 14082 | MockRead reads2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14083 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 14084 | MockRead(ASYNC, 2, "hello"), |
| 14085 | MockRead(ASYNC, OK, 3), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14086 | }; |
| 14087 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14088 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 14089 | arraysize(writes2)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14090 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14091 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14092 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14093 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14094 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 14095 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14096 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14097 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14098 | |
| 14099 | // Start the first transaction to set up the SpdySession |
| 14100 | HttpRequestInfo request1; |
| 14101 | request1.method = "GET"; |
| 14102 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14103 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14104 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14105 | TestCompletionCallback callback1; |
| 14106 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14107 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 14108 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14109 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14110 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14111 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 14112 | |
| 14113 | // Now, start the HTTP request |
| 14114 | HttpRequestInfo request2; |
| 14115 | request2.method = "GET"; |
| 14116 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14117 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14118 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14119 | TestCompletionCallback callback2; |
| 14120 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14121 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 14122 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14123 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14124 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14125 | EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 14126 | } |
| 14127 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14128 | // Alternative service requires HTTP/2 (or SPDY), but HTTP/1.1 is negotiated |
| 14129 | // with the alternative server. That connection should not be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14130 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceNotOnHttp11) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14131 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 14132 | HostPortPair alternative("www.example.org", 444); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14133 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14134 | // Negotiate HTTP/1.1 with alternative. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14135 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14136 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14137 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14138 | |
| 14139 | // No data should be read from the alternative, because HTTP/1.1 is |
| 14140 | // negotiated. |
| 14141 | StaticSocketDataProvider data; |
| 14142 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14143 | |
| 14144 | // 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] | 14145 | // negotiated. In order to test this, a failed connection to the server is |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14146 | // mocked. This way the request relies on the alternate Job. |
| 14147 | StaticSocketDataProvider data_refused; |
| 14148 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 14149 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 14150 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14151 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14152 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 14153 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14154 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 14155 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 14156 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 14157 | http_server_properties->SetHttp2AlternativeService( |
| 14158 | server, alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14159 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14160 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 14161 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14162 | request.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14163 | request.url = GURL("https://www.example.org:443"); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14164 | TestCompletionCallback callback; |
| 14165 | |
| 14166 | // HTTP/2 (or SPDY) is required for alternative service, if HTTP/1.1 is |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14167 | // negotiated, the alternate Job should fail with ERR_ALPN_NEGOTIATION_FAILED. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14168 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14169 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_ALPN_NEGOTIATION_FAILED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14170 | } |
| 14171 | |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14172 | // 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] | 14173 | // server, and an alternate one to the alternative server. If the former |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14174 | // succeeds, the request should succeed, even if the latter fails because |
| 14175 | // HTTP/1.1 is negotiated which is insufficient for alternative service. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14176 | TEST_F(HttpNetworkTransactionTest, FailedAlternativeServiceIsNotUserVisible) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14177 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 14178 | HostPortPair alternative("www.example.org", 444); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14179 | |
| 14180 | // Negotiate HTTP/1.1 with alternative. |
| 14181 | SSLSocketDataProvider alternative_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14182 | alternative_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14183 | session_deps_.socket_factory->AddSSLSocketDataProvider(&alternative_ssl); |
| 14184 | |
| 14185 | // No data should be read from the alternative, because HTTP/1.1 is |
| 14186 | // negotiated. |
| 14187 | StaticSocketDataProvider data; |
| 14188 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14189 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14190 | // Negotiate HTTP/1.1 with server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14191 | SSLSocketDataProvider origin_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14192 | origin_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14193 | session_deps_.socket_factory->AddSSLSocketDataProvider(&origin_ssl); |
| 14194 | |
| 14195 | MockWrite http_writes[] = { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14196 | MockWrite("GET / HTTP/1.1\r\n" |
| 14197 | "Host: www.example.org\r\n" |
| 14198 | "Connection: keep-alive\r\n\r\n"), |
| 14199 | MockWrite("GET /second HTTP/1.1\r\n" |
| 14200 | "Host: www.example.org\r\n" |
| 14201 | "Connection: keep-alive\r\n\r\n"), |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14202 | }; |
| 14203 | |
| 14204 | MockRead http_reads[] = { |
| 14205 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14206 | MockRead("Content-Type: text/html\r\n"), |
| 14207 | MockRead("Content-Length: 6\r\n\r\n"), |
| 14208 | MockRead("foobar"), |
| 14209 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14210 | MockRead("Content-Type: text/html\r\n"), |
| 14211 | MockRead("Content-Length: 7\r\n\r\n"), |
| 14212 | MockRead("another"), |
| 14213 | }; |
| 14214 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 14215 | http_writes, arraysize(http_writes)); |
| 14216 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 14217 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14218 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14219 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 14220 | HttpServerProperties* http_server_properties = |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14221 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 14222 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 14223 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 14224 | http_server_properties->SetHttp2AlternativeService( |
| 14225 | server, alternative_service, expiration); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14226 | |
| 14227 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 14228 | HttpRequestInfo request1; |
| 14229 | request1.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14230 | request1.url = GURL("https://www.example.org:443"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14231 | request1.load_flags = 0; |
| 14232 | TestCompletionCallback callback1; |
| 14233 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14234 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14235 | rv = callback1.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14236 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14237 | |
| 14238 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14239 | ASSERT_TRUE(response1); |
| 14240 | ASSERT_TRUE(response1->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14241 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 14242 | |
| 14243 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14244 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14245 | EXPECT_EQ("foobar", response_data1); |
| 14246 | |
| 14247 | // Alternative should be marked as broken, because HTTP/1.1 is not sufficient |
| 14248 | // for alternative service. |
| 14249 | EXPECT_TRUE( |
| 14250 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
| 14251 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14252 | // Since |alternative_service| is broken, a second transaction to server |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14253 | // should not start an alternate Job. It should pool to existing connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14254 | // to server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14255 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 14256 | HttpRequestInfo request2; |
| 14257 | request2.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14258 | request2.url = GURL("https://www.example.org:443/second"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14259 | request2.load_flags = 0; |
| 14260 | TestCompletionCallback callback2; |
| 14261 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14262 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14263 | rv = callback2.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14264 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14265 | |
| 14266 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14267 | ASSERT_TRUE(response2); |
| 14268 | ASSERT_TRUE(response2->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14269 | EXPECT_EQ("HTTP/1.1 200 OK", response2->headers->GetStatusLine()); |
| 14270 | |
| 14271 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14272 | ASSERT_THAT(ReadTransaction(&trans2, &response_data2), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14273 | EXPECT_EQ("another", response_data2); |
| 14274 | } |
| 14275 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14276 | // Alternative service requires HTTP/2 (or SPDY), but there is already a |
| 14277 | // HTTP/1.1 socket open to the alternative server. That socket should not be |
| 14278 | // used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14279 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceShouldNotPoolToHttp11) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14280 | url::SchemeHostPort server("https", "origin.example.org", 443); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14281 | HostPortPair alternative("alternative.example.org", 443); |
| 14282 | std::string origin_url = "https://origin.example.org:443"; |
| 14283 | std::string alternative_url = "https://alternative.example.org:443"; |
| 14284 | |
| 14285 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 14286 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14287 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14288 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14289 | |
| 14290 | // HTTP/1.1 data for |request1| and |request2|. |
| 14291 | MockWrite http_writes[] = { |
| 14292 | MockWrite( |
| 14293 | "GET / HTTP/1.1\r\n" |
| 14294 | "Host: alternative.example.org\r\n" |
| 14295 | "Connection: keep-alive\r\n\r\n"), |
| 14296 | MockWrite( |
| 14297 | "GET / HTTP/1.1\r\n" |
| 14298 | "Host: alternative.example.org\r\n" |
| 14299 | "Connection: keep-alive\r\n\r\n"), |
| 14300 | }; |
| 14301 | |
| 14302 | MockRead http_reads[] = { |
| 14303 | MockRead( |
| 14304 | "HTTP/1.1 200 OK\r\n" |
| 14305 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 14306 | "Content-Length: 40\r\n\r\n" |
| 14307 | "first HTTP/1.1 response from alternative"), |
| 14308 | MockRead( |
| 14309 | "HTTP/1.1 200 OK\r\n" |
| 14310 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 14311 | "Content-Length: 41\r\n\r\n" |
| 14312 | "second HTTP/1.1 response from alternative"), |
| 14313 | }; |
| 14314 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 14315 | http_writes, arraysize(http_writes)); |
| 14316 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 14317 | |
| 14318 | // This test documents that an alternate Job should not pool to an already |
| 14319 | // existing HTTP/1.1 connection. In order to test this, a failed connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14320 | // to the server is mocked. This way |request2| relies on the alternate Job. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14321 | StaticSocketDataProvider data_refused; |
| 14322 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 14323 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 14324 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14325 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14326 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 14327 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14328 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 14329 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 14330 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 14331 | http_server_properties->SetHttp2AlternativeService( |
| 14332 | server, alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14333 | |
| 14334 | // First transaction to alternative to open an HTTP/1.1 socket. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14335 | HttpRequestInfo request1; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 14336 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14337 | request1.method = "GET"; |
| 14338 | request1.url = GURL(alternative_url); |
| 14339 | request1.load_flags = 0; |
| 14340 | TestCompletionCallback callback1; |
| 14341 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14342 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14343 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14344 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14345 | ASSERT_TRUE(response1); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14346 | ASSERT_TRUE(response1->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14347 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14348 | EXPECT_TRUE(response1->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14349 | EXPECT_FALSE(response1->was_fetched_via_spdy); |
| 14350 | std::string response_data1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14351 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14352 | EXPECT_EQ("first HTTP/1.1 response from alternative", response_data1); |
| 14353 | |
| 14354 | // Request for origin.example.org, which has an alternative service. This |
| 14355 | // will start two Jobs: the alternative looks for connections to pool to, |
| 14356 | // 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] | 14357 | // open other connections to alternative server. The Job to server fails, so |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14358 | // this request fails. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14359 | HttpRequestInfo request2; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 14360 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14361 | request2.method = "GET"; |
| 14362 | request2.url = GURL(origin_url); |
| 14363 | request2.load_flags = 0; |
| 14364 | TestCompletionCallback callback2; |
| 14365 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14366 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14367 | EXPECT_THAT(callback2.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14368 | |
| 14369 | // Another transaction to alternative. This is to test that the HTTP/1.1 |
| 14370 | // socket is still open and in the pool. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14371 | HttpRequestInfo request3; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 14372 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14373 | request3.method = "GET"; |
| 14374 | request3.url = GURL(alternative_url); |
| 14375 | request3.load_flags = 0; |
| 14376 | TestCompletionCallback callback3; |
| 14377 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14378 | rv = trans3.Start(&request3, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14379 | EXPECT_THAT(callback3.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14380 | const HttpResponseInfo* response3 = trans3.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14381 | ASSERT_TRUE(response3); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14382 | ASSERT_TRUE(response3->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14383 | EXPECT_EQ("HTTP/1.1 200 OK", response3->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14384 | EXPECT_TRUE(response3->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14385 | EXPECT_FALSE(response3->was_fetched_via_spdy); |
| 14386 | std::string response_data3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14387 | ASSERT_THAT(ReadTransaction(&trans3, &response_data3), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14388 | EXPECT_EQ("second HTTP/1.1 response from alternative", response_data3); |
| 14389 | } |
| 14390 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14391 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14392 | const std::string https_url = "https://www.example.org:8080/"; |
| 14393 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14394 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14395 | // Separate SPDY util instance for naked and wrapped requests. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14396 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14397 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14398 | // SPDY GET for HTTPS URL (through CONNECT tunnel) |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14399 | const HostPortPair host_port_pair("www.example.org", 8080); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14400 | SpdySerializedFrame connect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 14401 | spdy_util_.ConstructSpdyConnect(NULL, 0, 1, LOWEST, host_port_pair)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14402 | SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14403 | spdy_util_wrapped.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14404 | SpdySerializedFrame wrapped_req1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 14405 | spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 14406 | |
| 14407 | // SPDY GET for HTTP URL (through the proxy, but not the tunnel). |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 14408 | SpdyHeaderBlock req2_block; |
| 14409 | req2_block[spdy_util_.GetMethodKey()] = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14410 | req2_block[spdy_util_.GetHostKey()] = "www.example.org:8080"; |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 14411 | req2_block[spdy_util_.GetSchemeKey()] = "http"; |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 14412 | req2_block[spdy_util_.GetPathKey()] = "/"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14413 | SpdySerializedFrame req2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14414 | spdy_util_.ConstructSpdyHeaders(3, std::move(req2_block), MEDIUM, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14415 | |
| 14416 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14417 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_req1, 2), |
| 14418 | CreateMockWrite(req2, 6), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14419 | }; |
| 14420 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14421 | SpdySerializedFrame conn_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14422 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14423 | SpdySerializedFrame resp1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14424 | spdy_util_wrapped.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14425 | SpdySerializedFrame body1(spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 14426 | SpdySerializedFrame wrapped_resp1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14427 | spdy_util_wrapped.ConstructWrappedSpdyFrame(resp1, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14428 | SpdySerializedFrame wrapped_body1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14429 | spdy_util_wrapped.ConstructWrappedSpdyFrame(body1, 1)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14430 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14431 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14432 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14433 | CreateMockRead(conn_resp, 1), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14434 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14435 | CreateMockRead(wrapped_resp1, 4), |
| 14436 | CreateMockRead(wrapped_body1, 5), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14437 | MockRead(ASYNC, ERR_IO_PENDING, 7), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14438 | CreateMockRead(resp2, 8), |
| 14439 | CreateMockRead(body2, 9), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14440 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 10), |
| 14441 | }; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14442 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14443 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 14444 | arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14445 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 14446 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14447 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 14448 | session_deps_.proxy_service = |
| 14449 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14450 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14451 | session_deps_.net_log = &log; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14452 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14453 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14454 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14455 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14456 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14457 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 14458 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14459 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14460 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14461 | |
| 14462 | // Start the first transaction to set up the SpdySession |
| 14463 | HttpRequestInfo request1; |
| 14464 | request1.method = "GET"; |
| 14465 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14466 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14467 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14468 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14469 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14470 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14471 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 14472 | data1.RunUntilPaused(); |
| 14473 | base::RunLoop().RunUntilIdle(); |
| 14474 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14475 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14476 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 14477 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 14478 | LoadTimingInfo load_timing_info1; |
| 14479 | EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); |
| 14480 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 14481 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 14482 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14483 | // Now, start the HTTP request. |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14484 | HttpRequestInfo request2; |
| 14485 | request2.method = "GET"; |
| 14486 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14487 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14488 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14489 | TestCompletionCallback callback2; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14490 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14491 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14492 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 14493 | data1.RunUntilPaused(); |
| 14494 | base::RunLoop().RunUntilIdle(); |
| 14495 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14496 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14497 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14498 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 14499 | |
| 14500 | LoadTimingInfo load_timing_info2; |
| 14501 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
| 14502 | // The established SPDY sessions is considered reused by the HTTP request. |
| 14503 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 14504 | // HTTP requests over a SPDY session should have a different connection |
| 14505 | // socket_log_id than requests over a tunnel. |
| 14506 | 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] | 14507 | } |
| 14508 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14509 | // Test that in the case where we have a SPDY session to a SPDY proxy |
| 14510 | // that we do not pool other origins that resolve to the same IP when |
| 14511 | // the certificate does not match the new origin. |
| 14512 | // http://crbug.com/134690 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14513 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14514 | const std::string url1 = "http://www.example.org/"; |
| 14515 | const std::string url2 = "https://news.example.org/"; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14516 | const std::string ip_addr = "1.2.3.4"; |
| 14517 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14518 | // Second SpdyTestUtil instance for the second socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14519 | SpdyTestUtil spdy_util_secure; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14520 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14521 | // SPDY GET for HTTP URL (through SPDY proxy) |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 14522 | SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14523 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14524 | SpdySerializedFrame req1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14525 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14526 | |
| 14527 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14528 | CreateMockWrite(req1, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14529 | }; |
| 14530 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14531 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14532 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14533 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14534 | MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(resp1, 2), |
| 14535 | CreateMockRead(body1, 3), MockRead(ASYNC, OK, 4), // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14536 | }; |
| 14537 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14538 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 14539 | arraysize(writes1)); |
martijn | fe9636e | 2016-02-06 14:33:32 | [diff] [blame] | 14540 | IPAddress ip; |
martijn | 654c8c4 | 2016-02-10 22:10:59 | [diff] [blame] | 14541 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14542 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 14543 | MockConnect connect_data1(ASYNC, OK, peer_addr); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14544 | data1.set_connect_data(connect_data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14545 | |
| 14546 | // SPDY GET for HTTPS URL (direct) |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14547 | SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14548 | spdy_util_secure.ConstructSpdyGet(url2.c_str(), 1, MEDIUM)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14549 | |
| 14550 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14551 | CreateMockWrite(req2, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14552 | }; |
| 14553 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14554 | SpdySerializedFrame resp2(spdy_util_secure.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14555 | SpdySerializedFrame body2(spdy_util_secure.ConstructSpdyDataFrame(1, true)); |
| 14556 | MockRead reads2[] = {CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14557 | MockRead(ASYNC, OK, 3)}; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14558 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14559 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 14560 | arraysize(writes2)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14561 | MockConnect connect_data2(ASYNC, OK); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14562 | data2.set_connect_data(connect_data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14563 | |
| 14564 | // Set up a proxy config that sends HTTP requests to a proxy, and |
| 14565 | // all others direct. |
| 14566 | ProxyConfig proxy_config; |
| 14567 | proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14568 | session_deps_.proxy_service = base::MakeUnique<ProxyService>( |
| 14569 | base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), nullptr, |
| 14570 | nullptr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14571 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14572 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14573 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14574 | // Load a valid cert. Note, that this does not need to |
| 14575 | // be valid for proxy because the MockSSLClientSocket does |
| 14576 | // not actually verify it. But SpdySession will use this |
| 14577 | // to see if it is valid for the new origin |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14578 | ssl1.cert = ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem"); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14579 | ASSERT_TRUE(ssl1.cert); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14580 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 14581 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14582 | |
| 14583 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14584 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14585 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 14586 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14587 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14588 | session_deps_.host_resolver = base::MakeUnique<MockCachingHostResolver>(); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14589 | session_deps_.host_resolver->rules()->AddRule("news.example.org", ip_addr); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14590 | session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14591 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14592 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14593 | |
| 14594 | // Start the first transaction to set up the SpdySession |
| 14595 | HttpRequestInfo request1; |
| 14596 | request1.method = "GET"; |
| 14597 | request1.url = GURL(url1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14598 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14599 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14600 | TestCompletionCallback callback1; |
| 14601 | ASSERT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14602 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14603 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 14604 | data1.RunUntilPaused(); |
| 14605 | base::RunLoop().RunUntilIdle(); |
| 14606 | data1.Resume(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14607 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14608 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14609 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 14610 | |
| 14611 | // Now, start the HTTP request |
| 14612 | HttpRequestInfo request2; |
| 14613 | request2.method = "GET"; |
| 14614 | request2.url = GURL(url2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14615 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14616 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14617 | TestCompletionCallback callback2; |
| 14618 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14619 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 14620 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14621 | |
| 14622 | ASSERT_TRUE(callback2.have_result()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14623 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14624 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 14625 | } |
| 14626 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14627 | // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 14628 | // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 14629 | // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 14630 | // SpdySession) do work. http://crbug.com/224701 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14631 | TEST_F(HttpNetworkTransactionTest, ErrorSocketNotConnected) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14632 | const std::string https_url = "https://www.example.org/"; |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14633 | |
| 14634 | MockRead reads1[] = { |
| 14635 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 14636 | }; |
| 14637 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14638 | SequencedSocketData data1(reads1, arraysize(reads1), NULL, 0); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14639 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14640 | SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14641 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, MEDIUM)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14642 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14643 | CreateMockWrite(req2, 0), |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14644 | }; |
| 14645 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14646 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14647 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14648 | MockRead reads2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14649 | CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
| 14650 | MockRead(ASYNC, OK, 3) // EOF |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14651 | }; |
| 14652 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14653 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 14654 | arraysize(writes2)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14655 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14656 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14657 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14658 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 14659 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14660 | |
| 14661 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14662 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14663 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 14664 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14665 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14666 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14667 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14668 | |
| 14669 | // Start the first transaction to set up the SpdySession and verify that |
| 14670 | // connection was closed. |
| 14671 | HttpRequestInfo request1; |
| 14672 | request1.method = "GET"; |
| 14673 | request1.url = GURL(https_url); |
| 14674 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14675 | HttpNetworkTransaction trans1(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14676 | TestCompletionCallback callback1; |
| 14677 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14678 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14679 | EXPECT_THAT(callback1.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14680 | |
| 14681 | // Now, start the second request and make sure it succeeds. |
| 14682 | HttpRequestInfo request2; |
| 14683 | request2.method = "GET"; |
| 14684 | request2.url = GURL(https_url); |
| 14685 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14686 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14687 | TestCompletionCallback callback2; |
| 14688 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14689 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14690 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14691 | ASSERT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14692 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 14693 | } |
| 14694 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14695 | TEST_F(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14696 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 14697 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14698 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 14699 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14700 | |
| 14701 | // Use two different hosts with different IPs so they don't get pooled. |
| 14702 | session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); |
| 14703 | session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14704 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14705 | |
| 14706 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14707 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14708 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14709 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14710 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 14711 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 14712 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14713 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14714 | spdy_util_.ConstructSpdyGet("https://www.a.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14715 | MockWrite spdy1_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14716 | CreateMockWrite(host1_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14717 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14718 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14719 | SpdySerializedFrame host1_resp_body( |
| 14720 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14721 | MockRead spdy1_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14722 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 14723 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14724 | }; |
| 14725 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14726 | // Use a separate test instance for the separate SpdySession that will be |
| 14727 | // created. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14728 | SpdyTestUtil spdy_util_2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14729 | auto spdy1_data = base::MakeUnique<SequencedSocketData>( |
| 14730 | spdy1_reads, arraysize(spdy1_reads), spdy1_writes, |
| 14731 | arraysize(spdy1_writes)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14732 | session_deps_.socket_factory->AddSocketDataProvider(spdy1_data.get()); |
| 14733 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14734 | SpdySerializedFrame host2_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14735 | spdy_util_2.ConstructSpdyGet("https://www.b.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14736 | MockWrite spdy2_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14737 | CreateMockWrite(host2_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14738 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14739 | SpdySerializedFrame host2_resp(spdy_util_2.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14740 | SpdySerializedFrame host2_resp_body( |
| 14741 | spdy_util_2.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14742 | MockRead spdy2_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14743 | CreateMockRead(host2_resp, 1), CreateMockRead(host2_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 14744 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14745 | }; |
| 14746 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14747 | auto spdy2_data = base::MakeUnique<SequencedSocketData>( |
| 14748 | spdy2_reads, arraysize(spdy2_reads), spdy2_writes, |
| 14749 | arraysize(spdy2_writes)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14750 | session_deps_.socket_factory->AddSocketDataProvider(spdy2_data.get()); |
| 14751 | |
| 14752 | MockWrite http_write[] = { |
| 14753 | MockWrite("GET / HTTP/1.1\r\n" |
| 14754 | "Host: www.a.com\r\n" |
| 14755 | "Connection: keep-alive\r\n\r\n"), |
| 14756 | }; |
| 14757 | |
| 14758 | MockRead http_read[] = { |
| 14759 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14760 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 14761 | MockRead("Content-Length: 6\r\n\r\n"), |
| 14762 | MockRead("hello!"), |
| 14763 | }; |
| 14764 | StaticSocketDataProvider http_data(http_read, arraysize(http_read), |
| 14765 | http_write, arraysize(http_write)); |
| 14766 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 14767 | |
| 14768 | HostPortPair host_port_pair_a("www.a.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 14769 | SpdySessionKey spdy_session_key_a( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 14770 | host_port_pair_a, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14771 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14772 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14773 | |
| 14774 | TestCompletionCallback callback; |
| 14775 | HttpRequestInfo request1; |
| 14776 | request1.method = "GET"; |
| 14777 | request1.url = GURL("https://www.a.com/"); |
| 14778 | request1.load_flags = 0; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14779 | auto trans = |
| 14780 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14781 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14782 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14783 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14784 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14785 | |
| 14786 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14787 | ASSERT_TRUE(response); |
| 14788 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14789 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14790 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14791 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14792 | |
| 14793 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14794 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14795 | EXPECT_EQ("hello!", response_data); |
| 14796 | trans.reset(); |
| 14797 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14798 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14799 | |
| 14800 | HostPortPair host_port_pair_b("www.b.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 14801 | SpdySessionKey spdy_session_key_b( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 14802 | host_port_pair_b, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14803 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14804 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14805 | HttpRequestInfo request2; |
| 14806 | request2.method = "GET"; |
| 14807 | request2.url = GURL("https://www.b.com/"); |
| 14808 | request2.load_flags = 0; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14809 | trans = |
| 14810 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14811 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14812 | rv = trans->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14813 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14814 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14815 | |
| 14816 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14817 | ASSERT_TRUE(response); |
| 14818 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14819 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14820 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14821 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14822 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14823 | EXPECT_EQ("hello!", response_data); |
| 14824 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14825 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14826 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14827 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14828 | |
| 14829 | HostPortPair host_port_pair_a1("www.a.com", 80); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 14830 | SpdySessionKey spdy_session_key_a1( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 14831 | host_port_pair_a1, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14832 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14833 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14834 | HttpRequestInfo request3; |
| 14835 | request3.method = "GET"; |
| 14836 | request3.url = GURL("http://www.a.com/"); |
| 14837 | request3.load_flags = 0; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14838 | trans = |
| 14839 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14840 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14841 | rv = trans->Start(&request3, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14842 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14843 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14844 | |
| 14845 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14846 | ASSERT_TRUE(response); |
| 14847 | ASSERT_TRUE(response->headers); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14848 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 14849 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14850 | EXPECT_FALSE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14851 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14852 | EXPECT_EQ("hello!", response_data); |
| 14853 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14854 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14855 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14856 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14857 | } |
| 14858 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14859 | TEST_F(HttpNetworkTransactionTest, HttpSyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14860 | HttpRequestInfo request; |
| 14861 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14862 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14863 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14864 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14865 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14866 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14867 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14868 | StaticSocketDataProvider data; |
| 14869 | data.set_connect_data(mock_connect); |
| 14870 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14871 | |
| 14872 | TestCompletionCallback callback; |
| 14873 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14874 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14875 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14876 | |
| 14877 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14878 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14879 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14880 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 14881 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14882 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 14883 | |
| 14884 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14885 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 14886 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14887 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14888 | |
| 14889 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14890 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14891 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14892 | } |
| 14893 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14894 | TEST_F(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14895 | HttpRequestInfo request; |
| 14896 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14897 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14898 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14899 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14900 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14901 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14902 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14903 | StaticSocketDataProvider data; |
| 14904 | data.set_connect_data(mock_connect); |
| 14905 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14906 | |
| 14907 | TestCompletionCallback callback; |
| 14908 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14909 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14910 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14911 | |
| 14912 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14913 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14914 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14915 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 14916 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14917 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 14918 | |
| 14919 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14920 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 14921 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14922 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14923 | |
| 14924 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14925 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14926 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14927 | } |
| 14928 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14929 | TEST_F(HttpNetworkTransactionTest, HttpSyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14930 | HttpRequestInfo request; |
| 14931 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14932 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14933 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14934 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14935 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14936 | |
| 14937 | MockWrite data_writes[] = { |
| 14938 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14939 | }; |
| 14940 | MockRead data_reads[] = { |
| 14941 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 14942 | }; |
| 14943 | |
| 14944 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14945 | data_writes, arraysize(data_writes)); |
| 14946 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14947 | |
| 14948 | TestCompletionCallback callback; |
| 14949 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14950 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14951 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14952 | |
| 14953 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14954 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14955 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14956 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14957 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14958 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 14959 | } |
| 14960 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14961 | TEST_F(HttpNetworkTransactionTest, HttpAsyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14962 | HttpRequestInfo request; |
| 14963 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14964 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14965 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14966 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14967 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14968 | |
| 14969 | MockWrite data_writes[] = { |
| 14970 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
| 14971 | }; |
| 14972 | MockRead data_reads[] = { |
| 14973 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 14974 | }; |
| 14975 | |
| 14976 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14977 | data_writes, arraysize(data_writes)); |
| 14978 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14979 | |
| 14980 | TestCompletionCallback callback; |
| 14981 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14982 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14983 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14984 | |
| 14985 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14986 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14987 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14988 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14989 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14990 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 14991 | } |
| 14992 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14993 | TEST_F(HttpNetworkTransactionTest, HttpSyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14994 | HttpRequestInfo request; |
| 14995 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14996 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14997 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14998 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14999 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15000 | |
| 15001 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15002 | MockWrite( |
| 15003 | "GET / HTTP/1.1\r\n" |
| 15004 | "Host: www.example.org\r\n" |
| 15005 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15006 | }; |
| 15007 | MockRead data_reads[] = { |
| 15008 | MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15009 | }; |
| 15010 | |
| 15011 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 15012 | data_writes, arraysize(data_writes)); |
| 15013 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15014 | |
| 15015 | TestCompletionCallback callback; |
| 15016 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15017 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15018 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15019 | |
| 15020 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15021 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15022 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15023 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15024 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15025 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 15026 | } |
| 15027 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15028 | TEST_F(HttpNetworkTransactionTest, HttpAsyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15029 | HttpRequestInfo request; |
| 15030 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15031 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15032 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15033 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15034 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15035 | |
| 15036 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15037 | MockWrite( |
| 15038 | "GET / HTTP/1.1\r\n" |
| 15039 | "Host: www.example.org\r\n" |
| 15040 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15041 | }; |
| 15042 | MockRead data_reads[] = { |
| 15043 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 15044 | }; |
| 15045 | |
| 15046 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 15047 | data_writes, arraysize(data_writes)); |
| 15048 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15049 | |
| 15050 | TestCompletionCallback callback; |
| 15051 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15052 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15053 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15054 | |
| 15055 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15056 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15057 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15058 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15059 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15060 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 15061 | } |
| 15062 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15063 | TEST_F(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15064 | HttpRequestInfo request; |
| 15065 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15066 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15067 | request.extra_headers.SetHeader("X-Foo", "bar"); |
| 15068 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15069 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15070 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15071 | |
| 15072 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15073 | MockWrite( |
| 15074 | "GET / HTTP/1.1\r\n" |
| 15075 | "Host: www.example.org\r\n" |
| 15076 | "Connection: keep-alive\r\n" |
| 15077 | "X-Foo: bar\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15078 | }; |
| 15079 | MockRead data_reads[] = { |
| 15080 | MockRead("HTTP/1.1 200 OK\r\n" |
| 15081 | "Content-Length: 5\r\n\r\n" |
| 15082 | "hello"), |
| 15083 | MockRead(ASYNC, ERR_UNEXPECTED), |
| 15084 | }; |
| 15085 | |
| 15086 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 15087 | data_writes, arraysize(data_writes)); |
| 15088 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15089 | |
| 15090 | TestCompletionCallback callback; |
| 15091 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15092 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15093 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15094 | |
| 15095 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15096 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15097 | |
| 15098 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15099 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15100 | std::string foo; |
| 15101 | EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo)); |
| 15102 | EXPECT_EQ("bar", foo); |
| 15103 | } |
| 15104 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15105 | namespace { |
| 15106 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 15107 | // Fake HttpStream that simply records calls to SetPriority(). |
| 15108 | class FakeStream : public HttpStream, |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15109 | public base::SupportsWeakPtr<FakeStream> { |
| 15110 | public: |
| 15111 | explicit FakeStream(RequestPriority priority) : priority_(priority) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15112 | ~FakeStream() override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15113 | |
| 15114 | RequestPriority priority() const { return priority_; } |
| 15115 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15116 | int InitializeStream(const HttpRequestInfo* request_info, |
| 15117 | RequestPriority priority, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15118 | const NetLogWithSource& net_log, |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15119 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15120 | return ERR_IO_PENDING; |
| 15121 | } |
| 15122 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15123 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 15124 | HttpResponseInfo* response, |
| 15125 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15126 | ADD_FAILURE(); |
| 15127 | return ERR_UNEXPECTED; |
| 15128 | } |
| 15129 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15130 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15131 | ADD_FAILURE(); |
| 15132 | return ERR_UNEXPECTED; |
| 15133 | } |
| 15134 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15135 | int ReadResponseBody(IOBuffer* buf, |
| 15136 | int buf_len, |
| 15137 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15138 | ADD_FAILURE(); |
| 15139 | return ERR_UNEXPECTED; |
| 15140 | } |
| 15141 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15142 | void Close(bool not_reusable) override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15143 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15144 | bool IsResponseBodyComplete() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15145 | ADD_FAILURE(); |
| 15146 | return false; |
| 15147 | } |
| 15148 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15149 | bool IsConnectionReused() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15150 | ADD_FAILURE(); |
| 15151 | return false; |
| 15152 | } |
| 15153 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15154 | void SetConnectionReused() override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15155 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 15156 | bool CanReuseConnection() const override { return false; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15157 | |
sclittle | 4de1bab9 | 2015-09-22 21:28:24 | [diff] [blame] | 15158 | int64_t GetTotalReceivedBytes() const override { |
[email protected] | bc92bc97 | 2013-12-13 08:32:59 | [diff] [blame] | 15159 | ADD_FAILURE(); |
| 15160 | return 0; |
| 15161 | } |
| 15162 | |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 15163 | int64_t GetTotalSentBytes() const override { |
| 15164 | ADD_FAILURE(); |
| 15165 | return 0; |
| 15166 | } |
| 15167 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15168 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15169 | ADD_FAILURE(); |
| 15170 | return false; |
| 15171 | } |
| 15172 | |
rch | cd37901 | 2017-04-12 21:53:32 | [diff] [blame] | 15173 | bool GetAlternativeService( |
| 15174 | AlternativeService* alternative_service) const override { |
| 15175 | ADD_FAILURE(); |
| 15176 | return false; |
| 15177 | } |
| 15178 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15179 | void GetSSLInfo(SSLInfo* ssl_info) override { ADD_FAILURE(); } |
| 15180 | |
| 15181 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15182 | ADD_FAILURE(); |
| 15183 | } |
| 15184 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15185 | bool GetRemoteEndpoint(IPEndPoint* endpoint) override { return false; } |
| 15186 | |
nharper | 78e6d2b | 2016-09-21 05:42:35 | [diff] [blame] | 15187 | Error GetTokenBindingSignature(crypto::ECPrivateKey* key, |
| 15188 | TokenBindingType tb_type, |
| 15189 | std::vector<uint8_t>* out) override { |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 15190 | ADD_FAILURE(); |
| 15191 | return ERR_NOT_IMPLEMENTED; |
| 15192 | } |
| 15193 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15194 | void Drain(HttpNetworkSession* session) override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15195 | |
zhongyi | ca364fbb | 2015-12-12 03:39:12 | [diff] [blame] | 15196 | void PopulateNetErrorDetails(NetErrorDetails* details) override { return; } |
| 15197 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15198 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15199 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 15200 | HttpStream* RenewStreamForAuth() override { return NULL; } |
| 15201 | |
Andrey Kosyakov | 83a6eee | 2017-08-14 19:20:04 | [diff] [blame] | 15202 | void SetRequestHeadersCallback(RequestHeadersCallback callback) override {} |
| 15203 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15204 | private: |
| 15205 | RequestPriority priority_; |
| 15206 | |
| 15207 | DISALLOW_COPY_AND_ASSIGN(FakeStream); |
| 15208 | }; |
| 15209 | |
| 15210 | // Fake HttpStreamRequest that simply records calls to SetPriority() |
| 15211 | // and vends FakeStreams with its current priority. |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15212 | class FakeStreamRequest : public HttpStreamRequest, |
| 15213 | public base::SupportsWeakPtr<FakeStreamRequest> { |
| 15214 | public: |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15215 | FakeStreamRequest(RequestPriority priority, |
| 15216 | HttpStreamRequest::Delegate* delegate) |
| 15217 | : priority_(priority), |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15218 | delegate_(delegate), |
| 15219 | websocket_stream_create_helper_(NULL) {} |
| 15220 | |
| 15221 | FakeStreamRequest(RequestPriority priority, |
| 15222 | HttpStreamRequest::Delegate* delegate, |
| 15223 | WebSocketHandshakeStreamBase::CreateHelper* create_helper) |
| 15224 | : priority_(priority), |
| 15225 | delegate_(delegate), |
| 15226 | websocket_stream_create_helper_(create_helper) {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15227 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15228 | ~FakeStreamRequest() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15229 | |
| 15230 | RequestPriority priority() const { return priority_; } |
| 15231 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15232 | const WebSocketHandshakeStreamBase::CreateHelper* |
| 15233 | websocket_stream_create_helper() const { |
| 15234 | return websocket_stream_create_helper_; |
| 15235 | } |
| 15236 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15237 | // Create a new FakeStream and pass it to the request's |
| 15238 | // delegate. Returns a weak pointer to the FakeStream. |
| 15239 | base::WeakPtr<FakeStream> FinishStreamRequest() { |
bnc | 5029f463 | 2017-06-08 16:19:00 | [diff] [blame] | 15240 | auto fake_stream = base::MakeUnique<FakeStream>(priority_); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15241 | // Do this before calling OnStreamReady() as OnStreamReady() may |
| 15242 | // immediately delete |fake_stream|. |
| 15243 | base::WeakPtr<FakeStream> weak_stream = fake_stream->AsWeakPtr(); |
bnc | 5029f463 | 2017-06-08 16:19:00 | [diff] [blame] | 15244 | delegate_->OnStreamReady(SSLConfig(), ProxyInfo(), std::move(fake_stream)); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15245 | return weak_stream; |
| 15246 | } |
| 15247 | |
asanka | 681f02d | 2017-02-22 17:06:39 | [diff] [blame] | 15248 | int RestartTunnelWithProxyAuth() override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15249 | ADD_FAILURE(); |
| 15250 | return ERR_UNEXPECTED; |
| 15251 | } |
| 15252 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15253 | LoadState GetLoadState() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15254 | ADD_FAILURE(); |
| 15255 | return LoadState(); |
| 15256 | } |
| 15257 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15258 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15259 | |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15260 | bool was_alpn_negotiated() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15261 | |
bnc | 6227b26e | 2016-08-12 02:00:43 | [diff] [blame] | 15262 | NextProto negotiated_protocol() const override { return kProtoUnknown; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15263 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15264 | bool using_spdy() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15265 | |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 15266 | const ConnectionAttempts& connection_attempts() const override { |
| 15267 | static ConnectionAttempts no_attempts; |
| 15268 | return no_attempts; |
| 15269 | } |
| 15270 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15271 | private: |
| 15272 | RequestPriority priority_; |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15273 | HttpStreamRequest::Delegate* const delegate_; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15274 | WebSocketHandshakeStreamBase::CreateHelper* websocket_stream_create_helper_; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15275 | |
| 15276 | DISALLOW_COPY_AND_ASSIGN(FakeStreamRequest); |
| 15277 | }; |
| 15278 | |
| 15279 | // Fake HttpStreamFactory that vends FakeStreamRequests. |
| 15280 | class FakeStreamFactory : public HttpStreamFactory { |
| 15281 | public: |
| 15282 | FakeStreamFactory() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15283 | ~FakeStreamFactory() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15284 | |
| 15285 | // Returns a WeakPtr<> to the last HttpStreamRequest returned by |
| 15286 | // RequestStream() (which may be NULL if it was destroyed already). |
| 15287 | base::WeakPtr<FakeStreamRequest> last_stream_request() { |
| 15288 | return last_stream_request_; |
| 15289 | } |
| 15290 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15291 | std::unique_ptr<HttpStreamRequest> RequestStream( |
| 15292 | const HttpRequestInfo& info, |
| 15293 | RequestPriority priority, |
| 15294 | const SSLConfig& server_ssl_config, |
| 15295 | const SSLConfig& proxy_ssl_config, |
| 15296 | HttpStreamRequest::Delegate* delegate, |
| 15297 | bool enable_ip_based_pooling, |
| 15298 | bool enable_alternative_services, |
| 15299 | const NetLogWithSource& net_log) override { |
| 15300 | auto fake_request = base::MakeUnique<FakeStreamRequest>(priority, delegate); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15301 | last_stream_request_ = fake_request->AsWeakPtr(); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15302 | return std::move(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15303 | } |
| 15304 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15305 | std::unique_ptr<HttpStreamRequest> RequestBidirectionalStreamImpl( |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 15306 | const HttpRequestInfo& info, |
| 15307 | RequestPriority priority, |
| 15308 | const SSLConfig& server_ssl_config, |
| 15309 | const SSLConfig& proxy_ssl_config, |
| 15310 | HttpStreamRequest::Delegate* delegate, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15311 | bool enable_ip_based_pooling, |
bnc | accd496 | 2017-04-06 21:00:26 | [diff] [blame] | 15312 | bool enable_alternative_services, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15313 | const NetLogWithSource& net_log) override { |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 15314 | NOTREACHED(); |
| 15315 | return nullptr; |
| 15316 | } |
| 15317 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15318 | std::unique_ptr<HttpStreamRequest> RequestWebSocketHandshakeStream( |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15319 | const HttpRequestInfo& info, |
| 15320 | RequestPriority priority, |
| 15321 | const SSLConfig& server_ssl_config, |
| 15322 | const SSLConfig& proxy_ssl_config, |
| 15323 | HttpStreamRequest::Delegate* delegate, |
[email protected] | 467086b | 2013-11-12 08:19:46 | [diff] [blame] | 15324 | WebSocketHandshakeStreamBase::CreateHelper* create_helper, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15325 | bool enable_ip_based_pooling, |
bnc | accd496 | 2017-04-06 21:00:26 | [diff] [blame] | 15326 | bool enable_alternative_services, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15327 | const NetLogWithSource& net_log) override { |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15328 | auto fake_request = |
| 15329 | base::MakeUnique<FakeStreamRequest>(priority, delegate, create_helper); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15330 | last_stream_request_ = fake_request->AsWeakPtr(); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15331 | return std::move(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15332 | } |
| 15333 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15334 | void PreconnectStreams(int num_streams, |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 15335 | const HttpRequestInfo& info) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15336 | ADD_FAILURE(); |
| 15337 | } |
| 15338 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15339 | const HostMappingRules* GetHostMappingRules() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15340 | ADD_FAILURE(); |
| 15341 | return NULL; |
| 15342 | } |
| 15343 | |
xunjieli | f5267de | 2017-01-20 21:18:57 | [diff] [blame] | 15344 | void DumpMemoryStats(base::trace_event::ProcessMemoryDump* pmd, |
| 15345 | const std::string& parent_absolute_name) const override { |
| 15346 | ADD_FAILURE(); |
| 15347 | } |
| 15348 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15349 | private: |
| 15350 | base::WeakPtr<FakeStreamRequest> last_stream_request_; |
| 15351 | |
| 15352 | DISALLOW_COPY_AND_ASSIGN(FakeStreamFactory); |
| 15353 | }; |
| 15354 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15355 | // TODO(ricea): Maybe unify this with the one in |
| 15356 | // url_request_http_job_unittest.cc ? |
| 15357 | class FakeWebSocketBasicHandshakeStream : public WebSocketHandshakeStreamBase { |
| 15358 | public: |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15359 | FakeWebSocketBasicHandshakeStream( |
| 15360 | std::unique_ptr<ClientSocketHandle> connection, |
| 15361 | bool using_proxy) |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 15362 | : state_(std::move(connection), using_proxy, false) {} |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15363 | |
| 15364 | // Fake implementation of HttpStreamBase methods. |
| 15365 | // This ends up being quite "real" because this object has to really send data |
| 15366 | // on the mock socket. It might be easier to use the real implementation, but |
| 15367 | // the fact that the WebSocket code is not compiled on iOS makes that |
| 15368 | // difficult. |
| 15369 | int InitializeStream(const HttpRequestInfo* request_info, |
| 15370 | RequestPriority priority, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15371 | const NetLogWithSource& net_log, |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15372 | const CompletionCallback& callback) override { |
| 15373 | state_.Initialize(request_info, priority, net_log, callback); |
| 15374 | return OK; |
| 15375 | } |
| 15376 | |
| 15377 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 15378 | HttpResponseInfo* response, |
| 15379 | const CompletionCallback& callback) override { |
| 15380 | return parser()->SendRequest(state_.GenerateRequestLine(), request_headers, |
| 15381 | response, callback); |
| 15382 | } |
| 15383 | |
| 15384 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
| 15385 | return parser()->ReadResponseHeaders(callback); |
| 15386 | } |
| 15387 | |
| 15388 | int ReadResponseBody(IOBuffer* buf, |
| 15389 | int buf_len, |
| 15390 | const CompletionCallback& callback) override { |
| 15391 | NOTREACHED(); |
| 15392 | return ERR_IO_PENDING; |
| 15393 | } |
| 15394 | |
| 15395 | void Close(bool not_reusable) override { |
| 15396 | if (parser()) |
| 15397 | parser()->Close(true); |
| 15398 | } |
| 15399 | |
| 15400 | bool IsResponseBodyComplete() const override { |
| 15401 | NOTREACHED(); |
| 15402 | return false; |
| 15403 | } |
| 15404 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15405 | bool IsConnectionReused() const override { |
| 15406 | NOTREACHED(); |
| 15407 | return false; |
| 15408 | } |
| 15409 | void SetConnectionReused() override { NOTREACHED(); } |
| 15410 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 15411 | bool CanReuseConnection() const override { return false; } |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15412 | |
sclittle | 4de1bab9 | 2015-09-22 21:28:24 | [diff] [blame] | 15413 | int64_t GetTotalReceivedBytes() const override { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15414 | NOTREACHED(); |
| 15415 | return 0; |
| 15416 | } |
| 15417 | |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 15418 | int64_t GetTotalSentBytes() const override { |
| 15419 | NOTREACHED(); |
| 15420 | return 0; |
| 15421 | } |
| 15422 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15423 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
| 15424 | NOTREACHED(); |
| 15425 | return false; |
| 15426 | } |
| 15427 | |
rch | cd37901 | 2017-04-12 21:53:32 | [diff] [blame] | 15428 | bool GetAlternativeService( |
| 15429 | AlternativeService* alternative_service) const override { |
| 15430 | ADD_FAILURE(); |
| 15431 | return false; |
| 15432 | } |
| 15433 | |
Adam Rice | cb76ac6 | 2015-02-20 05:33:25 | [diff] [blame] | 15434 | void GetSSLInfo(SSLInfo* ssl_info) override {} |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15435 | |
| 15436 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
| 15437 | NOTREACHED(); |
| 15438 | } |
| 15439 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15440 | bool GetRemoteEndpoint(IPEndPoint* endpoint) override { return false; } |
| 15441 | |
nharper | 78e6d2b | 2016-09-21 05:42:35 | [diff] [blame] | 15442 | Error GetTokenBindingSignature(crypto::ECPrivateKey* key, |
| 15443 | TokenBindingType tb_type, |
| 15444 | std::vector<uint8_t>* out) override { |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 15445 | ADD_FAILURE(); |
| 15446 | return ERR_NOT_IMPLEMENTED; |
| 15447 | } |
| 15448 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15449 | void Drain(HttpNetworkSession* session) override { NOTREACHED(); } |
| 15450 | |
zhongyi | ca364fbb | 2015-12-12 03:39:12 | [diff] [blame] | 15451 | void PopulateNetErrorDetails(NetErrorDetails* details) override { return; } |
| 15452 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15453 | void SetPriority(RequestPriority priority) override { NOTREACHED(); } |
| 15454 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15455 | HttpStream* RenewStreamForAuth() override { |
| 15456 | NOTREACHED(); |
| 15457 | return nullptr; |
| 15458 | } |
| 15459 | |
| 15460 | // Fake implementation of WebSocketHandshakeStreamBase method(s) |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15461 | std::unique_ptr<WebSocketStream> Upgrade() override { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15462 | NOTREACHED(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15463 | return std::unique_ptr<WebSocketStream>(); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15464 | } |
| 15465 | |
| 15466 | private: |
| 15467 | HttpStreamParser* parser() const { return state_.parser(); } |
| 15468 | HttpBasicState state_; |
| 15469 | |
| 15470 | DISALLOW_COPY_AND_ASSIGN(FakeWebSocketBasicHandshakeStream); |
| 15471 | }; |
| 15472 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15473 | // TODO(yhirano): Split this class out into a net/websockets file, if it is |
| 15474 | // worth doing. |
| 15475 | class FakeWebSocketStreamCreateHelper : |
| 15476 | public WebSocketHandshakeStreamBase::CreateHelper { |
| 15477 | public: |
bnc | 615cf2f | 2017-05-19 18:53:26 | [diff] [blame] | 15478 | std::unique_ptr<WebSocketHandshakeStreamBase> CreateBasicStream( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15479 | std::unique_ptr<ClientSocketHandle> connection, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 15480 | bool using_proxy) override { |
bnc | 615cf2f | 2017-05-19 18:53:26 | [diff] [blame] | 15481 | return base::MakeUnique<FakeWebSocketBasicHandshakeStream>( |
| 15482 | std::move(connection), using_proxy); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15483 | } |
| 15484 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15485 | ~FakeWebSocketStreamCreateHelper() override {} |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15486 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15487 | virtual std::unique_ptr<WebSocketStream> Upgrade() { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15488 | NOTREACHED(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15489 | return std::unique_ptr<WebSocketStream>(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15490 | } |
| 15491 | }; |
| 15492 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15493 | } // namespace |
| 15494 | |
| 15495 | // Make sure that HttpNetworkTransaction passes on its priority to its |
| 15496 | // stream request on start. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15497 | TEST_F(HttpNetworkTransactionTest, SetStreamRequestPriorityOnStart) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15498 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15499 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15500 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15501 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15502 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15503 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15504 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15505 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15506 | ASSERT_FALSE(fake_factory->last_stream_request()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15507 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15508 | TestCompletionCallback callback; |
| 15509 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15510 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15511 | |
| 15512 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 15513 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15514 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15515 | EXPECT_EQ(LOW, fake_request->priority()); |
| 15516 | } |
| 15517 | |
| 15518 | // Make sure that HttpNetworkTransaction passes on its priority |
| 15519 | // updates to its stream request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15520 | TEST_F(HttpNetworkTransactionTest, SetStreamRequestPriority) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15521 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15522 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15523 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15524 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15525 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15526 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15527 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15528 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15529 | TestCompletionCallback callback; |
| 15530 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15531 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15532 | |
| 15533 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 15534 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15535 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15536 | EXPECT_EQ(LOW, fake_request->priority()); |
| 15537 | |
| 15538 | trans.SetPriority(LOWEST); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15539 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15540 | EXPECT_EQ(LOWEST, fake_request->priority()); |
| 15541 | } |
| 15542 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15543 | // Make sure that HttpNetworkTransaction passes on its priority |
| 15544 | // updates to its stream. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15545 | TEST_F(HttpNetworkTransactionTest, SetStreamPriority) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15546 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15547 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15548 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15549 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15550 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15551 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15552 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15553 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15554 | TestCompletionCallback callback; |
| 15555 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15556 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15557 | |
| 15558 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 15559 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15560 | ASSERT_TRUE(fake_request); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15561 | base::WeakPtr<FakeStream> fake_stream = fake_request->FinishStreamRequest(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15562 | ASSERT_TRUE(fake_stream); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15563 | EXPECT_EQ(LOW, fake_stream->priority()); |
| 15564 | |
| 15565 | trans.SetPriority(LOWEST); |
| 15566 | EXPECT_EQ(LOWEST, fake_stream->priority()); |
| 15567 | } |
| 15568 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15569 | TEST_F(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15570 | // The same logic needs to be tested for both ws: and wss: schemes, but this |
| 15571 | // test is already parameterised on NextProto, so it uses a loop to verify |
| 15572 | // that the different schemes work. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15573 | std::string test_cases[] = {"ws://www.example.org/", |
| 15574 | "wss://www.example.org/"}; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15575 | for (size_t i = 0; i < arraysize(test_cases); ++i) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15576 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15577 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15578 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
| 15579 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
[email protected] | 0191b51c | 2013-11-18 10:55:23 | [diff] [blame] | 15580 | peer.SetHttpStreamFactoryForWebSocket( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15581 | std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15582 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15583 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15584 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15585 | trans.SetWebSocketHandshakeStreamCreateHelper( |
| 15586 | &websocket_stream_create_helper); |
| 15587 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15588 | TestCompletionCallback callback; |
| 15589 | request.method = "GET"; |
| 15590 | request.url = GURL(test_cases[i]); |
| 15591 | |
| 15592 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15593 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15594 | |
| 15595 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 15596 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15597 | ASSERT_TRUE(fake_request); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15598 | EXPECT_EQ(&websocket_stream_create_helper, |
| 15599 | fake_request->websocket_stream_create_helper()); |
| 15600 | } |
| 15601 | } |
| 15602 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15603 | // Tests that when a used socket is returned to the SSL socket pool, it's closed |
| 15604 | // if the transport socket pool is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15605 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15606 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 15607 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15608 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 15609 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15610 | |
| 15611 | // Set up SSL request. |
| 15612 | |
| 15613 | HttpRequestInfo ssl_request; |
| 15614 | ssl_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15615 | ssl_request.url = GURL("https://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15616 | |
| 15617 | MockWrite ssl_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15618 | MockWrite( |
| 15619 | "GET / HTTP/1.1\r\n" |
| 15620 | "Host: www.example.org\r\n" |
| 15621 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15622 | }; |
| 15623 | MockRead ssl_reads[] = { |
| 15624 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15625 | MockRead("Content-Length: 11\r\n\r\n"), |
| 15626 | MockRead("hello world"), |
| 15627 | MockRead(SYNCHRONOUS, OK), |
| 15628 | }; |
| 15629 | StaticSocketDataProvider ssl_data(ssl_reads, arraysize(ssl_reads), |
| 15630 | ssl_writes, arraysize(ssl_writes)); |
| 15631 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 15632 | |
| 15633 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 15634 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15635 | |
| 15636 | // Set up HTTP request. |
| 15637 | |
| 15638 | HttpRequestInfo http_request; |
| 15639 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15640 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15641 | |
| 15642 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15643 | MockWrite( |
| 15644 | "GET / HTTP/1.1\r\n" |
| 15645 | "Host: www.example.org\r\n" |
| 15646 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15647 | }; |
| 15648 | MockRead http_reads[] = { |
| 15649 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15650 | MockRead("Content-Length: 7\r\n\r\n"), |
| 15651 | MockRead("falafel"), |
| 15652 | MockRead(SYNCHRONOUS, OK), |
| 15653 | }; |
| 15654 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 15655 | http_writes, arraysize(http_writes)); |
| 15656 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 15657 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15658 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15659 | |
| 15660 | // Start the SSL request. |
| 15661 | TestCompletionCallback ssl_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15662 | HttpNetworkTransaction ssl_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15663 | ASSERT_EQ(ERR_IO_PENDING, |
| 15664 | ssl_trans.Start(&ssl_request, ssl_callback.callback(), |
| 15665 | NetLogWithSource())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15666 | |
| 15667 | // Start the HTTP request. Pool should stall. |
| 15668 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15669 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15670 | ASSERT_EQ(ERR_IO_PENDING, |
| 15671 | http_trans.Start(&http_request, http_callback.callback(), |
| 15672 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15673 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15674 | |
| 15675 | // Wait for response from SSL request. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15676 | ASSERT_THAT(ssl_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15677 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15678 | ASSERT_THAT(ReadTransaction(&ssl_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15679 | EXPECT_EQ("hello world", response_data); |
| 15680 | |
| 15681 | // The SSL socket should automatically be closed, so the HTTP request can |
| 15682 | // start. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15683 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 15684 | ASSERT_FALSE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15685 | |
| 15686 | // The HTTP request can now complete. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15687 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15688 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15689 | EXPECT_EQ("falafel", response_data); |
| 15690 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15691 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15692 | } |
| 15693 | |
| 15694 | // Tests that when a SSL connection is established but there's no corresponding |
| 15695 | // request that needs it, the new socket is closed if the transport socket pool |
| 15696 | // is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15697 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15698 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 15699 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15700 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 15701 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15702 | |
| 15703 | // Set up an ssl request. |
| 15704 | |
| 15705 | HttpRequestInfo ssl_request; |
| 15706 | ssl_request.method = "GET"; |
| 15707 | ssl_request.url = GURL("https://www.foopy.com/"); |
| 15708 | |
| 15709 | // No data will be sent on the SSL socket. |
| 15710 | StaticSocketDataProvider ssl_data; |
| 15711 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 15712 | |
| 15713 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 15714 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15715 | |
| 15716 | // Set up HTTP request. |
| 15717 | |
| 15718 | HttpRequestInfo http_request; |
| 15719 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15720 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15721 | |
| 15722 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15723 | MockWrite( |
| 15724 | "GET / HTTP/1.1\r\n" |
| 15725 | "Host: www.example.org\r\n" |
| 15726 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15727 | }; |
| 15728 | MockRead http_reads[] = { |
| 15729 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15730 | MockRead("Content-Length: 7\r\n\r\n"), |
| 15731 | MockRead("falafel"), |
| 15732 | MockRead(SYNCHRONOUS, OK), |
| 15733 | }; |
| 15734 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 15735 | http_writes, arraysize(http_writes)); |
| 15736 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 15737 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15738 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15739 | |
| 15740 | // Preconnect an SSL socket. A preconnect is needed because connect jobs are |
| 15741 | // cancelled when a normal transaction is cancelled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15742 | HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 15743 | http_stream_factory->PreconnectStreams(1, ssl_request); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15744 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15745 | |
| 15746 | // Start the HTTP request. Pool should stall. |
| 15747 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15748 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15749 | ASSERT_EQ(ERR_IO_PENDING, |
| 15750 | http_trans.Start(&http_request, http_callback.callback(), |
| 15751 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15752 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15753 | |
| 15754 | // The SSL connection will automatically be closed once the connection is |
| 15755 | // established, to let the HTTP request start. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15756 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15757 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15758 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15759 | EXPECT_EQ("falafel", response_data); |
| 15760 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15761 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15762 | } |
| 15763 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15764 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15765 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15766 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 15767 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15768 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15769 | |
| 15770 | HttpRequestInfo request; |
| 15771 | request.method = "POST"; |
| 15772 | request.url = GURL("http://www.foo.com/"); |
| 15773 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15774 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15775 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15776 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15777 | // Send headers successfully, but get an error while sending the body. |
| 15778 | MockWrite data_writes[] = { |
| 15779 | MockWrite("POST / HTTP/1.1\r\n" |
| 15780 | "Host: www.foo.com\r\n" |
| 15781 | "Connection: keep-alive\r\n" |
| 15782 | "Content-Length: 3\r\n\r\n"), |
| 15783 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15784 | }; |
| 15785 | |
| 15786 | MockRead data_reads[] = { |
| 15787 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 15788 | MockRead("hello world"), |
| 15789 | MockRead(SYNCHRONOUS, OK), |
| 15790 | }; |
| 15791 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15792 | arraysize(data_writes)); |
| 15793 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15794 | |
| 15795 | TestCompletionCallback callback; |
| 15796 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15797 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15798 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15799 | |
| 15800 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15801 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15802 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15803 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15804 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15805 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15806 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15807 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 15808 | |
| 15809 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15810 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15811 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15812 | EXPECT_EQ("hello world", response_data); |
| 15813 | } |
| 15814 | |
| 15815 | // This test makes sure the retry logic doesn't trigger when reading an error |
| 15816 | // response from a server that rejected a POST with a CONNECTION_RESET. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15817 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15818 | PostReadsErrorResponseAfterResetOnReusedSocket) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15819 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15820 | MockWrite data_writes[] = { |
| 15821 | MockWrite("GET / HTTP/1.1\r\n" |
| 15822 | "Host: www.foo.com\r\n" |
| 15823 | "Connection: keep-alive\r\n\r\n"), |
| 15824 | MockWrite("POST / HTTP/1.1\r\n" |
| 15825 | "Host: www.foo.com\r\n" |
| 15826 | "Connection: keep-alive\r\n" |
| 15827 | "Content-Length: 3\r\n\r\n"), |
| 15828 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15829 | }; |
| 15830 | |
| 15831 | MockRead data_reads[] = { |
| 15832 | MockRead("HTTP/1.1 200 Peachy\r\n" |
| 15833 | "Content-Length: 14\r\n\r\n"), |
| 15834 | MockRead("first response"), |
| 15835 | MockRead("HTTP/1.1 400 Not OK\r\n" |
| 15836 | "Content-Length: 15\r\n\r\n"), |
| 15837 | MockRead("second response"), |
| 15838 | MockRead(SYNCHRONOUS, OK), |
| 15839 | }; |
| 15840 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15841 | arraysize(data_writes)); |
| 15842 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15843 | |
| 15844 | TestCompletionCallback callback; |
| 15845 | HttpRequestInfo request1; |
| 15846 | request1.method = "GET"; |
| 15847 | request1.url = GURL("http://www.foo.com/"); |
| 15848 | request1.load_flags = 0; |
| 15849 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15850 | auto trans1 = |
| 15851 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15852 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15853 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15854 | |
| 15855 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15856 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15857 | |
| 15858 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15859 | ASSERT_TRUE(response1); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15860 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15861 | EXPECT_TRUE(response1->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15862 | EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine()); |
| 15863 | |
| 15864 | std::string response_data1; |
| 15865 | rv = ReadTransaction(trans1.get(), &response_data1); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15866 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15867 | EXPECT_EQ("first response", response_data1); |
| 15868 | // Delete the transaction to release the socket back into the socket pool. |
| 15869 | trans1.reset(); |
| 15870 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15871 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15872 | element_readers.push_back( |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15873 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15874 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15875 | |
| 15876 | HttpRequestInfo request2; |
| 15877 | request2.method = "POST"; |
| 15878 | request2.url = GURL("http://www.foo.com/"); |
| 15879 | request2.upload_data_stream = &upload_data_stream; |
| 15880 | request2.load_flags = 0; |
| 15881 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15882 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15883 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15884 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15885 | |
| 15886 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15887 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15888 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15889 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15890 | ASSERT_TRUE(response2); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15891 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15892 | EXPECT_TRUE(response2->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15893 | EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine()); |
| 15894 | |
| 15895 | std::string response_data2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15896 | rv = ReadTransaction(&trans2, &response_data2); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15897 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15898 | EXPECT_EQ("second response", response_data2); |
| 15899 | } |
| 15900 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15901 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15902 | PostReadsErrorResponseAfterResetPartialBodySent) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15903 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15904 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 15905 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15906 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15907 | |
| 15908 | HttpRequestInfo request; |
| 15909 | request.method = "POST"; |
| 15910 | request.url = GURL("http://www.foo.com/"); |
| 15911 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15912 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15913 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15914 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15915 | // Send headers successfully, but get an error while sending the body. |
| 15916 | MockWrite data_writes[] = { |
| 15917 | MockWrite("POST / HTTP/1.1\r\n" |
| 15918 | "Host: www.foo.com\r\n" |
| 15919 | "Connection: keep-alive\r\n" |
| 15920 | "Content-Length: 3\r\n\r\n" |
| 15921 | "fo"), |
| 15922 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15923 | }; |
| 15924 | |
| 15925 | MockRead data_reads[] = { |
| 15926 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 15927 | MockRead("hello world"), |
| 15928 | MockRead(SYNCHRONOUS, OK), |
| 15929 | }; |
| 15930 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15931 | arraysize(data_writes)); |
| 15932 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15933 | |
| 15934 | TestCompletionCallback callback; |
| 15935 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15936 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15937 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15938 | |
| 15939 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15940 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15941 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15942 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15943 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15944 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15945 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15946 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 15947 | |
| 15948 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15949 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15950 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15951 | EXPECT_EQ("hello world", response_data); |
| 15952 | } |
| 15953 | |
| 15954 | // This tests the more common case than the previous test, where headers and |
| 15955 | // body are not merged into a single request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15956 | TEST_F(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) { |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 15957 | ChunkedUploadDataStream upload_data_stream(0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15958 | |
| 15959 | HttpRequestInfo request; |
| 15960 | request.method = "POST"; |
| 15961 | request.url = GURL("http://www.foo.com/"); |
| 15962 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15963 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15964 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15965 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15966 | // Send headers successfully, but get an error while sending the body. |
| 15967 | MockWrite data_writes[] = { |
| 15968 | MockWrite("POST / HTTP/1.1\r\n" |
| 15969 | "Host: www.foo.com\r\n" |
| 15970 | "Connection: keep-alive\r\n" |
| 15971 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 15972 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15973 | }; |
| 15974 | |
| 15975 | MockRead data_reads[] = { |
| 15976 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 15977 | MockRead("hello world"), |
| 15978 | MockRead(SYNCHRONOUS, OK), |
| 15979 | }; |
| 15980 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15981 | arraysize(data_writes)); |
| 15982 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15983 | |
| 15984 | TestCompletionCallback callback; |
| 15985 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15986 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15987 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15988 | // Make sure the headers are sent before adding a chunk. This ensures that |
| 15989 | // they can't be merged with the body in a single send. Not currently |
| 15990 | // necessary since a chunked body is never merged with headers, but this makes |
| 15991 | // the test more future proof. |
| 15992 | base::RunLoop().RunUntilIdle(); |
| 15993 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 15994 | upload_data_stream.AppendData("last chunk", 10, true); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15995 | |
| 15996 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15997 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15998 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15999 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16000 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16001 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16002 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16003 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 16004 | |
| 16005 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16006 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16007 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16008 | EXPECT_EQ("hello world", response_data); |
| 16009 | } |
| 16010 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16011 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16012 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16013 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 16014 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16015 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16016 | |
| 16017 | HttpRequestInfo request; |
| 16018 | request.method = "POST"; |
| 16019 | request.url = GURL("http://www.foo.com/"); |
| 16020 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16021 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16022 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16023 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16024 | |
| 16025 | MockWrite data_writes[] = { |
| 16026 | MockWrite("POST / HTTP/1.1\r\n" |
| 16027 | "Host: www.foo.com\r\n" |
| 16028 | "Connection: keep-alive\r\n" |
| 16029 | "Content-Length: 3\r\n\r\n"), |
| 16030 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16031 | }; |
| 16032 | |
| 16033 | MockRead data_reads[] = { |
| 16034 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 16035 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 16036 | MockRead("hello world"), |
| 16037 | MockRead(SYNCHRONOUS, OK), |
| 16038 | }; |
| 16039 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16040 | arraysize(data_writes)); |
| 16041 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16042 | |
| 16043 | TestCompletionCallback callback; |
| 16044 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16045 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16046 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16047 | |
| 16048 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16049 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16050 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16051 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16052 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16053 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16054 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16055 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 16056 | |
| 16057 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16058 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16059 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16060 | EXPECT_EQ("hello world", response_data); |
| 16061 | } |
| 16062 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16063 | TEST_F(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16064 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16065 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 16066 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16067 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16068 | |
| 16069 | HttpRequestInfo request; |
| 16070 | request.method = "POST"; |
| 16071 | request.url = GURL("http://www.foo.com/"); |
| 16072 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16073 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16074 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16075 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16076 | // Send headers successfully, but get an error while sending the body. |
| 16077 | MockWrite data_writes[] = { |
| 16078 | MockWrite("POST / HTTP/1.1\r\n" |
| 16079 | "Host: www.foo.com\r\n" |
| 16080 | "Connection: keep-alive\r\n" |
| 16081 | "Content-Length: 3\r\n\r\n"), |
| 16082 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16083 | }; |
| 16084 | |
| 16085 | MockRead data_reads[] = { |
| 16086 | MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"), |
| 16087 | MockRead("hello world"), |
| 16088 | MockRead(SYNCHRONOUS, OK), |
| 16089 | }; |
| 16090 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16091 | arraysize(data_writes)); |
| 16092 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16093 | |
| 16094 | TestCompletionCallback callback; |
| 16095 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16096 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16097 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16098 | |
| 16099 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16100 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16101 | } |
| 16102 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16103 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16104 | PostIgnoresNonErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16105 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16106 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 16107 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16108 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16109 | |
| 16110 | HttpRequestInfo request; |
| 16111 | request.method = "POST"; |
| 16112 | request.url = GURL("http://www.foo.com/"); |
| 16113 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16114 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16115 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16116 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16117 | // Send headers successfully, but get an error while sending the body. |
| 16118 | MockWrite data_writes[] = { |
| 16119 | MockWrite("POST / HTTP/1.1\r\n" |
| 16120 | "Host: www.foo.com\r\n" |
| 16121 | "Connection: keep-alive\r\n" |
| 16122 | "Content-Length: 3\r\n\r\n"), |
| 16123 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16124 | }; |
| 16125 | |
| 16126 | MockRead data_reads[] = { |
| 16127 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 16128 | MockRead("HTTP/1.0 302 Redirect\r\n"), |
| 16129 | MockRead("Location: http://somewhere-else.com/\r\n"), |
| 16130 | MockRead("Content-Length: 0\r\n\r\n"), |
| 16131 | MockRead(SYNCHRONOUS, OK), |
| 16132 | }; |
| 16133 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16134 | arraysize(data_writes)); |
| 16135 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16136 | |
| 16137 | TestCompletionCallback callback; |
| 16138 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16139 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16140 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16141 | |
| 16142 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16143 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16144 | } |
| 16145 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16146 | TEST_F(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16147 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16148 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 16149 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16150 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16151 | |
| 16152 | HttpRequestInfo request; |
| 16153 | request.method = "POST"; |
| 16154 | request.url = GURL("http://www.foo.com/"); |
| 16155 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16156 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16157 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16158 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16159 | // Send headers successfully, but get an error while sending the body. |
| 16160 | MockWrite data_writes[] = { |
| 16161 | MockWrite("POST / HTTP/1.1\r\n" |
| 16162 | "Host: www.foo.com\r\n" |
| 16163 | "Connection: keep-alive\r\n" |
| 16164 | "Content-Length: 3\r\n\r\n"), |
| 16165 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16166 | }; |
| 16167 | |
| 16168 | MockRead data_reads[] = { |
| 16169 | MockRead("HTTP 0.9 rocks!"), |
| 16170 | MockRead(SYNCHRONOUS, OK), |
| 16171 | }; |
| 16172 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16173 | arraysize(data_writes)); |
| 16174 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16175 | |
| 16176 | TestCompletionCallback callback; |
| 16177 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16178 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16179 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16180 | |
| 16181 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16182 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16183 | } |
| 16184 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16185 | TEST_F(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16186 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16187 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 16188 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16189 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16190 | |
| 16191 | HttpRequestInfo request; |
| 16192 | request.method = "POST"; |
| 16193 | request.url = GURL("http://www.foo.com/"); |
| 16194 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16195 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16196 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16197 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16198 | // Send headers successfully, but get an error while sending the body. |
| 16199 | MockWrite data_writes[] = { |
| 16200 | MockWrite("POST / HTTP/1.1\r\n" |
| 16201 | "Host: www.foo.com\r\n" |
| 16202 | "Connection: keep-alive\r\n" |
| 16203 | "Content-Length: 3\r\n\r\n"), |
| 16204 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16205 | }; |
| 16206 | |
| 16207 | MockRead data_reads[] = { |
| 16208 | MockRead("HTTP/1.0 400 Not a Full Response\r\n"), |
| 16209 | MockRead(SYNCHRONOUS, OK), |
| 16210 | }; |
| 16211 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16212 | arraysize(data_writes)); |
| 16213 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16214 | |
| 16215 | TestCompletionCallback callback; |
| 16216 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16217 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16218 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16219 | |
| 16220 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16221 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16222 | } |
| 16223 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16224 | // Verify that proxy headers are not sent to the destination server when |
| 16225 | // establishing a tunnel for a secure WebSocket connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16226 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWssTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16227 | HttpRequestInfo request; |
| 16228 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16229 | request.url = GURL("wss://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16230 | AddWebSocketHeaders(&request.extra_headers); |
| 16231 | |
| 16232 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 16233 | session_deps_.proxy_service = |
| 16234 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16235 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16236 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16237 | |
| 16238 | // Since a proxy is configured, try to establish a tunnel. |
| 16239 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16240 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 16241 | "Host: www.example.org:443\r\n" |
| 16242 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16243 | |
| 16244 | // After calling trans->RestartWithAuth(), this is the request we should |
| 16245 | // be issuing -- the final header line contains the credentials. |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16246 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 16247 | "Host: www.example.org:443\r\n" |
| 16248 | "Proxy-Connection: keep-alive\r\n" |
| 16249 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16250 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16251 | MockWrite("GET / HTTP/1.1\r\n" |
| 16252 | "Host: www.example.org\r\n" |
| 16253 | "Connection: Upgrade\r\n" |
| 16254 | "Upgrade: websocket\r\n" |
| 16255 | "Origin: http://www.example.org\r\n" |
| 16256 | "Sec-WebSocket-Version: 13\r\n" |
| 16257 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16258 | }; |
| 16259 | |
| 16260 | // The proxy responds to the connect with a 407, using a persistent |
| 16261 | // connection. |
| 16262 | MockRead data_reads[] = { |
| 16263 | // No credentials. |
| 16264 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 16265 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 16266 | MockRead("Content-Length: 0\r\n"), |
| 16267 | MockRead("Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16268 | |
| 16269 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 16270 | |
| 16271 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 16272 | MockRead("Upgrade: websocket\r\n"), |
| 16273 | MockRead("Connection: Upgrade\r\n"), |
| 16274 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 16275 | }; |
| 16276 | |
| 16277 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16278 | arraysize(data_writes)); |
| 16279 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16280 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 16281 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16282 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16283 | auto trans = |
| 16284 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16285 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 16286 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 16287 | &websocket_stream_create_helper); |
| 16288 | |
| 16289 | { |
| 16290 | TestCompletionCallback callback; |
| 16291 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16292 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16293 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16294 | |
| 16295 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16296 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16297 | } |
| 16298 | |
| 16299 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 16300 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16301 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16302 | EXPECT_EQ(407, response->headers->response_code()); |
| 16303 | |
| 16304 | { |
| 16305 | TestCompletionCallback callback; |
| 16306 | |
| 16307 | int rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 16308 | callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16309 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16310 | |
| 16311 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16312 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16313 | } |
| 16314 | |
| 16315 | response = trans->GetResponseInfo(); |
| 16316 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16317 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16318 | |
| 16319 | EXPECT_EQ(101, response->headers->response_code()); |
| 16320 | |
| 16321 | trans.reset(); |
| 16322 | session->CloseAllConnections(); |
| 16323 | } |
| 16324 | |
| 16325 | // Verify that proxy headers are not sent to the destination server when |
| 16326 | // establishing a tunnel for an insecure WebSocket connection. |
| 16327 | // This requires the authentication info to be injected into the auth cache |
| 16328 | // due to crbug.com/395064 |
| 16329 | // TODO(ricea): Change to use a 407 response once issue 395064 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16330 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWsTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16331 | HttpRequestInfo request; |
| 16332 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16333 | request.url = GURL("ws://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16334 | AddWebSocketHeaders(&request.extra_headers); |
| 16335 | |
| 16336 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 16337 | session_deps_.proxy_service = |
| 16338 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16339 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16340 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16341 | |
| 16342 | MockWrite data_writes[] = { |
| 16343 | // Try to establish a tunnel for the WebSocket connection, with |
| 16344 | // credentials. Because WebSockets have a separate set of socket pools, |
| 16345 | // they cannot and will not use the same TCP/IP connection as the |
| 16346 | // preflight HTTP request. |
| 16347 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16348 | "CONNECT www.example.org:80 HTTP/1.1\r\n" |
| 16349 | "Host: www.example.org:80\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16350 | "Proxy-Connection: keep-alive\r\n" |
| 16351 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 16352 | |
| 16353 | MockWrite( |
| 16354 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16355 | "Host: www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16356 | "Connection: Upgrade\r\n" |
| 16357 | "Upgrade: websocket\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16358 | "Origin: http://www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16359 | "Sec-WebSocket-Version: 13\r\n" |
| 16360 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
| 16361 | }; |
| 16362 | |
| 16363 | MockRead data_reads[] = { |
| 16364 | // HTTP CONNECT with credentials. |
| 16365 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 16366 | |
| 16367 | // WebSocket connection established inside tunnel. |
| 16368 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 16369 | MockRead("Upgrade: websocket\r\n"), |
| 16370 | MockRead("Connection: Upgrade\r\n"), |
| 16371 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 16372 | }; |
| 16373 | |
| 16374 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16375 | arraysize(data_writes)); |
| 16376 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16377 | |
| 16378 | session->http_auth_cache()->Add( |
| 16379 | GURL("http://myproxy:70/"), "MyRealm1", HttpAuth::AUTH_SCHEME_BASIC, |
| 16380 | "Basic realm=MyRealm1", AuthCredentials(kFoo, kBar), "/"); |
| 16381 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16382 | auto trans = |
| 16383 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16384 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 16385 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 16386 | &websocket_stream_create_helper); |
| 16387 | |
| 16388 | TestCompletionCallback callback; |
| 16389 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16390 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16391 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16392 | |
| 16393 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16394 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16395 | |
| 16396 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 16397 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16398 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16399 | |
| 16400 | EXPECT_EQ(101, response->headers->response_code()); |
| 16401 | |
| 16402 | trans.reset(); |
| 16403 | session->CloseAllConnections(); |
| 16404 | } |
| 16405 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16406 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16407 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16408 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 16409 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16410 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16411 | |
| 16412 | HttpRequestInfo request; |
| 16413 | request.method = "POST"; |
| 16414 | request.url = GURL("http://www.foo.com/"); |
| 16415 | request.upload_data_stream = &upload_data_stream; |
| 16416 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16417 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16418 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16419 | MockWrite data_writes[] = { |
| 16420 | MockWrite("POST / HTTP/1.1\r\n" |
| 16421 | "Host: www.foo.com\r\n" |
| 16422 | "Connection: keep-alive\r\n" |
| 16423 | "Content-Length: 3\r\n\r\n"), |
| 16424 | MockWrite("foo"), |
| 16425 | }; |
| 16426 | |
| 16427 | MockRead data_reads[] = { |
| 16428 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16429 | MockRead(SYNCHRONOUS, OK), |
| 16430 | }; |
| 16431 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16432 | arraysize(data_writes)); |
| 16433 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16434 | |
| 16435 | TestCompletionCallback callback; |
| 16436 | |
| 16437 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16438 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16439 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16440 | |
| 16441 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16442 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16443 | |
| 16444 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16445 | trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16446 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16447 | trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16448 | } |
| 16449 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16450 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost100Continue) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16451 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16452 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 16453 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16454 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16455 | |
| 16456 | HttpRequestInfo request; |
| 16457 | request.method = "POST"; |
| 16458 | request.url = GURL("http://www.foo.com/"); |
| 16459 | request.upload_data_stream = &upload_data_stream; |
| 16460 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16461 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16462 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16463 | MockWrite data_writes[] = { |
| 16464 | MockWrite("POST / HTTP/1.1\r\n" |
| 16465 | "Host: www.foo.com\r\n" |
| 16466 | "Connection: keep-alive\r\n" |
| 16467 | "Content-Length: 3\r\n\r\n"), |
| 16468 | MockWrite("foo"), |
| 16469 | }; |
| 16470 | |
| 16471 | MockRead data_reads[] = { |
| 16472 | MockRead("HTTP/1.1 100 Continue\r\n\r\n"), |
| 16473 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16474 | MockRead(SYNCHRONOUS, OK), |
| 16475 | }; |
| 16476 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16477 | arraysize(data_writes)); |
| 16478 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16479 | |
| 16480 | TestCompletionCallback callback; |
| 16481 | |
| 16482 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16483 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16484 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16485 | |
| 16486 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16487 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16488 | |
| 16489 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16490 | trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16491 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16492 | trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16493 | } |
| 16494 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16495 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesChunkedPost) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16496 | ChunkedUploadDataStream upload_data_stream(0); |
| 16497 | |
| 16498 | HttpRequestInfo request; |
| 16499 | request.method = "POST"; |
| 16500 | request.url = GURL("http://www.foo.com/"); |
| 16501 | request.upload_data_stream = &upload_data_stream; |
| 16502 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16503 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16504 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16505 | // Send headers successfully, but get an error while sending the body. |
| 16506 | MockWrite data_writes[] = { |
| 16507 | MockWrite("POST / HTTP/1.1\r\n" |
| 16508 | "Host: www.foo.com\r\n" |
| 16509 | "Connection: keep-alive\r\n" |
| 16510 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 16511 | MockWrite("1\r\nf\r\n"), MockWrite("2\r\noo\r\n"), MockWrite("0\r\n\r\n"), |
| 16512 | }; |
| 16513 | |
| 16514 | MockRead data_reads[] = { |
| 16515 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16516 | MockRead(SYNCHRONOUS, OK), |
| 16517 | }; |
| 16518 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16519 | arraysize(data_writes)); |
| 16520 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16521 | |
| 16522 | TestCompletionCallback callback; |
| 16523 | |
| 16524 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16525 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16526 | |
| 16527 | base::RunLoop().RunUntilIdle(); |
| 16528 | upload_data_stream.AppendData("f", 1, false); |
| 16529 | |
| 16530 | base::RunLoop().RunUntilIdle(); |
| 16531 | upload_data_stream.AppendData("oo", 2, true); |
| 16532 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16533 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16534 | |
| 16535 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16536 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16537 | |
| 16538 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16539 | trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16540 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16541 | trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16542 | } |
| 16543 | |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16544 | // Confirm that transactions whose throttle is created in (and stays in) |
| 16545 | // the unthrottled state are not blocked. |
| 16546 | TEST_F(HttpNetworkTransactionTest, ThrottlingUnthrottled) { |
| 16547 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16548 | std::unique_ptr<HttpNetworkSession> session( |
| 16549 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16550 | |
| 16551 | // Send a simple request and make sure it goes through. |
| 16552 | HttpRequestInfo request; |
| 16553 | request.method = "GET"; |
| 16554 | request.url = GURL("http://www.example.org/"); |
| 16555 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16556 | auto trans = |
| 16557 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16558 | |
| 16559 | MockWrite data_writes[] = { |
| 16560 | MockWrite("GET / HTTP/1.1\r\n" |
| 16561 | "Host: www.example.org\r\n" |
| 16562 | "Connection: keep-alive\r\n\r\n"), |
| 16563 | }; |
| 16564 | MockRead data_reads[] = { |
| 16565 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16566 | MockRead(SYNCHRONOUS, OK), |
| 16567 | }; |
| 16568 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16569 | arraysize(data_writes)); |
| 16570 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16571 | |
| 16572 | TestCompletionCallback callback; |
| 16573 | trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16574 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 16575 | } |
| 16576 | |
| 16577 | // Confirm requests can be blocked by a throttler, and are resumed |
| 16578 | // when the throttle is unblocked. |
| 16579 | TEST_F(HttpNetworkTransactionTest, ThrottlingBasic) { |
| 16580 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16581 | std::unique_ptr<HttpNetworkSession> session( |
| 16582 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16583 | |
| 16584 | // Send a simple request and make sure it goes through. |
| 16585 | HttpRequestInfo request; |
| 16586 | request.method = "GET"; |
| 16587 | request.url = GURL("http://www.example.org/"); |
| 16588 | |
| 16589 | MockWrite data_writes[] = { |
| 16590 | MockWrite("GET / HTTP/1.1\r\n" |
| 16591 | "Host: www.example.org\r\n" |
| 16592 | "Connection: keep-alive\r\n\r\n"), |
| 16593 | }; |
| 16594 | MockRead data_reads[] = { |
| 16595 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16596 | MockRead(SYNCHRONOUS, OK), |
| 16597 | }; |
| 16598 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16599 | arraysize(data_writes)); |
| 16600 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16601 | |
| 16602 | // Start a request that will be throttled at start; confirm it |
| 16603 | // doesn't complete. |
| 16604 | throttler->set_throttle_new_requests(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16605 | auto trans = |
| 16606 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16607 | |
| 16608 | TestCompletionCallback callback; |
| 16609 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16610 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16611 | |
| 16612 | base::RunLoop().RunUntilIdle(); |
| 16613 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 16614 | EXPECT_FALSE(callback.have_result()); |
| 16615 | |
| 16616 | // Confirm the request goes on to complete when unthrottled. |
| 16617 | throttler->UnthrottleAllRequests(); |
| 16618 | base::RunLoop().RunUntilIdle(); |
| 16619 | ASSERT_TRUE(callback.have_result()); |
| 16620 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 16621 | } |
| 16622 | |
| 16623 | // Destroy a request while it's throttled. |
| 16624 | TEST_F(HttpNetworkTransactionTest, ThrottlingDestruction) { |
| 16625 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16626 | std::unique_ptr<HttpNetworkSession> session( |
| 16627 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16628 | |
| 16629 | // Send a simple request and make sure it goes through. |
| 16630 | HttpRequestInfo request; |
| 16631 | request.method = "GET"; |
| 16632 | request.url = GURL("http://www.example.org/"); |
| 16633 | |
| 16634 | MockWrite data_writes[] = { |
| 16635 | MockWrite("GET / HTTP/1.1\r\n" |
| 16636 | "Host: www.example.org\r\n" |
| 16637 | "Connection: keep-alive\r\n\r\n"), |
| 16638 | }; |
| 16639 | MockRead data_reads[] = { |
| 16640 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16641 | MockRead(SYNCHRONOUS, OK), |
| 16642 | }; |
| 16643 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16644 | arraysize(data_writes)); |
| 16645 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16646 | |
| 16647 | // Start a request that will be throttled at start; confirm it |
| 16648 | // doesn't complete. |
| 16649 | throttler->set_throttle_new_requests(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16650 | auto trans = |
| 16651 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16652 | |
| 16653 | TestCompletionCallback callback; |
| 16654 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16655 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16656 | |
| 16657 | base::RunLoop().RunUntilIdle(); |
| 16658 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 16659 | EXPECT_FALSE(callback.have_result()); |
| 16660 | |
| 16661 | EXPECT_EQ(1u, throttler->num_outstanding_requests()); |
| 16662 | trans.reset(); |
| 16663 | EXPECT_EQ(0u, throttler->num_outstanding_requests()); |
| 16664 | } |
| 16665 | |
| 16666 | // Confirm the throttler receives SetPriority calls. |
| 16667 | TEST_F(HttpNetworkTransactionTest, ThrottlingPrioritySet) { |
| 16668 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16669 | std::unique_ptr<HttpNetworkSession> session( |
| 16670 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16671 | |
| 16672 | // Send a simple request and make sure it goes through. |
| 16673 | HttpRequestInfo request; |
| 16674 | request.method = "GET"; |
| 16675 | request.url = GURL("http://www.example.org/"); |
| 16676 | |
| 16677 | MockWrite data_writes[] = { |
| 16678 | MockWrite("GET / HTTP/1.1\r\n" |
| 16679 | "Host: www.example.org\r\n" |
| 16680 | "Connection: keep-alive\r\n\r\n"), |
| 16681 | }; |
| 16682 | MockRead data_reads[] = { |
| 16683 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16684 | MockRead(SYNCHRONOUS, OK), |
| 16685 | }; |
| 16686 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16687 | arraysize(data_writes)); |
| 16688 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16689 | |
| 16690 | throttler->set_throttle_new_requests(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16691 | auto trans = base::MakeUnique<HttpNetworkTransaction>(IDLE, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16692 | // Start the transaction to associate a throttle with it. |
| 16693 | TestCompletionCallback callback; |
| 16694 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16695 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16696 | |
| 16697 | EXPECT_EQ(0, throttler->num_set_priority_calls()); |
| 16698 | trans->SetPriority(LOW); |
| 16699 | EXPECT_EQ(1, throttler->num_set_priority_calls()); |
| 16700 | EXPECT_EQ(LOW, throttler->last_priority_set()); |
| 16701 | |
| 16702 | throttler->UnthrottleAllRequests(); |
| 16703 | base::RunLoop().RunUntilIdle(); |
| 16704 | ASSERT_TRUE(callback.have_result()); |
| 16705 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 16706 | } |
| 16707 | |
| 16708 | // Confirm that unthrottling from a SetPriority call by the |
| 16709 | // throttler works properly. |
| 16710 | TEST_F(HttpNetworkTransactionTest, ThrottlingPrioritySetUnthrottle) { |
| 16711 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16712 | std::unique_ptr<HttpNetworkSession> session( |
| 16713 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16714 | |
| 16715 | // Send a simple request and make sure it goes through. |
| 16716 | HttpRequestInfo request; |
| 16717 | request.method = "GET"; |
| 16718 | request.url = GURL("http://www.example.org/"); |
| 16719 | |
| 16720 | MockWrite data_writes[] = { |
| 16721 | MockWrite("GET / HTTP/1.1\r\n" |
| 16722 | "Host: www.example.org\r\n" |
| 16723 | "Connection: keep-alive\r\n\r\n"), |
| 16724 | }; |
| 16725 | MockRead data_reads[] = { |
| 16726 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16727 | MockRead(SYNCHRONOUS, OK), |
| 16728 | }; |
| 16729 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16730 | arraysize(data_writes)); |
| 16731 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16732 | |
| 16733 | StaticSocketDataProvider reads1(data_reads, arraysize(data_reads), |
| 16734 | data_writes, arraysize(data_writes)); |
| 16735 | session_deps_.socket_factory->AddSocketDataProvider(&reads1); |
| 16736 | |
| 16737 | // Start a request that will be throttled at start; confirm it |
| 16738 | // doesn't complete. |
| 16739 | throttler->set_throttle_new_requests(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16740 | auto trans = |
| 16741 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16742 | |
| 16743 | TestCompletionCallback callback; |
| 16744 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16745 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16746 | |
| 16747 | base::RunLoop().RunUntilIdle(); |
| 16748 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 16749 | EXPECT_FALSE(callback.have_result()); |
| 16750 | |
| 16751 | // Create a new request, call SetPriority on it to unthrottle, |
| 16752 | // and make sure that allows the original request to complete. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16753 | auto trans1 = base::MakeUnique<HttpNetworkTransaction>(LOW, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16754 | throttler->set_priority_change_closure( |
| 16755 | base::Bind(&TestNetworkStreamThrottler::UnthrottleAllRequests, |
| 16756 | base::Unretained(throttler))); |
| 16757 | |
| 16758 | // Start the transaction to associate a throttle with it. |
| 16759 | TestCompletionCallback callback1; |
| 16760 | rv = trans1->Start(&request, callback1.callback(), NetLogWithSource()); |
| 16761 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16762 | |
| 16763 | trans1->SetPriority(IDLE); |
| 16764 | |
| 16765 | base::RunLoop().RunUntilIdle(); |
| 16766 | ASSERT_TRUE(callback.have_result()); |
| 16767 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 16768 | ASSERT_TRUE(callback1.have_result()); |
| 16769 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 16770 | } |
| 16771 | |
| 16772 | // Transaction will be destroyed when the unique_ptr goes out of scope. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16773 | void DestroyTransaction(std::unique_ptr<HttpNetworkTransaction> transaction) {} |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16774 | |
| 16775 | // Confirm that destroying a transaction from a SetPriority call by the |
| 16776 | // throttler works properly. |
| 16777 | TEST_F(HttpNetworkTransactionTest, ThrottlingPrioritySetDestroy) { |
| 16778 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16779 | std::unique_ptr<HttpNetworkSession> session( |
| 16780 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16781 | |
| 16782 | // Send a simple request and make sure it goes through. |
| 16783 | HttpRequestInfo request; |
| 16784 | request.method = "GET"; |
| 16785 | request.url = GURL("http://www.example.org/"); |
| 16786 | |
| 16787 | MockWrite data_writes[] = { |
| 16788 | MockWrite("GET / HTTP/1.1\r\n" |
| 16789 | "Host: www.example.org\r\n" |
| 16790 | "Connection: keep-alive\r\n\r\n"), |
| 16791 | }; |
| 16792 | MockRead data_reads[] = { |
| 16793 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16794 | MockRead(SYNCHRONOUS, OK), |
| 16795 | }; |
| 16796 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16797 | arraysize(data_writes)); |
| 16798 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16799 | |
| 16800 | StaticSocketDataProvider reads1(data_reads, arraysize(data_reads), |
| 16801 | data_writes, arraysize(data_writes)); |
| 16802 | session_deps_.socket_factory->AddSocketDataProvider(&reads1); |
| 16803 | |
| 16804 | // Start a request that will be throttled at start; confirm it |
| 16805 | // doesn't complete. |
| 16806 | throttler->set_throttle_new_requests(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16807 | auto trans = |
| 16808 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16809 | |
| 16810 | TestCompletionCallback callback; |
| 16811 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16812 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16813 | |
| 16814 | base::RunLoop().RunUntilIdle(); |
| 16815 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 16816 | EXPECT_FALSE(callback.have_result()); |
| 16817 | |
| 16818 | // Arrange for the set priority call on the above transaction to delete |
| 16819 | // the transaction. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16820 | HttpNetworkTransaction* trans_ptr(trans.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16821 | throttler->set_priority_change_closure( |
| 16822 | base::Bind(&DestroyTransaction, base::Passed(&trans))); |
| 16823 | |
| 16824 | // Call it and check results (partially a "doesn't crash" test). |
| 16825 | trans_ptr->SetPriority(IDLE); |
| 16826 | trans_ptr = nullptr; // No longer a valid pointer. |
| 16827 | |
| 16828 | base::RunLoop().RunUntilIdle(); |
| 16829 | ASSERT_FALSE(callback.have_result()); |
| 16830 | } |
| 16831 | |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16832 | #if !defined(OS_IOS) |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16833 | TEST_F(HttpNetworkTransactionTest, TokenBindingSpdy) { |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16834 | const std::string https_url = "https://www.example.com"; |
| 16835 | HttpRequestInfo request; |
| 16836 | request.url = GURL(https_url); |
| 16837 | request.method = "GET"; |
| 16838 | |
| 16839 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 16840 | ssl.token_binding_negotiated = true; |
| 16841 | ssl.token_binding_key_param = TB_PARAM_ECDSAP256; |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16842 | ssl.next_proto = kProtoHTTP2; |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16843 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16844 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16845 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16846 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 16847 | MockRead reads[] = {CreateMockRead(resp), CreateMockRead(body), |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16848 | MockRead(ASYNC, ERR_IO_PENDING)}; |
| 16849 | StaticSocketDataProvider data(reads, arraysize(reads), nullptr, 0); |
| 16850 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16851 | session_deps_.channel_id_service = |
| 16852 | base::MakeUnique<ChannelIDService>(new DefaultChannelIDStore(nullptr)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16853 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16854 | |
| 16855 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 16856 | TestCompletionCallback callback; |
| 16857 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16858 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
fdoray | f33fede | 2017-05-11 21:18:10 | [diff] [blame] | 16859 | |
| 16860 | NetTestSuite::GetScopedTaskEnvironment()->RunUntilIdle(); |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16861 | |
| 16862 | EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); |
| 16863 | HttpRequestHeaders headers; |
| 16864 | ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); |
| 16865 | EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); |
| 16866 | } |
| 16867 | #endif // !defined(OS_IOS) |
| 16868 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 16869 | void CheckContentEncodingMatching(SpdySessionDependencies* session_deps, |
| 16870 | const std::string& accept_encoding, |
| 16871 | const std::string& content_encoding, |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 16872 | const std::string& location, |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 16873 | bool should_match) { |
| 16874 | HttpRequestInfo request; |
| 16875 | request.method = "GET"; |
| 16876 | request.url = GURL("http://www.foo.com/"); |
| 16877 | request.extra_headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, |
| 16878 | accept_encoding); |
| 16879 | |
| 16880 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps)); |
| 16881 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 16882 | // Send headers successfully, but get an error while sending the body. |
| 16883 | MockWrite data_writes[] = { |
| 16884 | MockWrite("GET / HTTP/1.1\r\n" |
| 16885 | "Host: www.foo.com\r\n" |
| 16886 | "Connection: keep-alive\r\n" |
| 16887 | "Accept-Encoding: "), |
| 16888 | MockWrite(accept_encoding.data()), MockWrite("\r\n\r\n"), |
| 16889 | }; |
| 16890 | |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 16891 | std::string response_code = "200 OK"; |
| 16892 | std::string extra; |
| 16893 | if (!location.empty()) { |
| 16894 | response_code = "301 Redirect\r\nLocation: "; |
| 16895 | response_code.append(location); |
| 16896 | } |
| 16897 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 16898 | MockRead data_reads[] = { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 16899 | MockRead("HTTP/1.0 "), |
| 16900 | MockRead(response_code.data()), |
| 16901 | MockRead("\r\nContent-Encoding: "), |
| 16902 | MockRead(content_encoding.data()), |
| 16903 | MockRead("\r\n\r\n"), |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 16904 | MockRead(SYNCHRONOUS, OK), |
| 16905 | }; |
| 16906 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16907 | arraysize(data_writes)); |
| 16908 | session_deps->socket_factory->AddSocketDataProvider(&data); |
| 16909 | |
| 16910 | TestCompletionCallback callback; |
| 16911 | |
| 16912 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 16913 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16914 | |
| 16915 | rv = callback.WaitForResult(); |
| 16916 | if (should_match) { |
| 16917 | EXPECT_THAT(rv, IsOk()); |
| 16918 | } else { |
| 16919 | EXPECT_THAT(rv, IsError(ERR_CONTENT_DECODING_FAILED)); |
| 16920 | } |
| 16921 | } |
| 16922 | |
| 16923 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding1) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 16924 | CheckContentEncodingMatching(&session_deps_, "gzip,sdch", "br", "", false); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 16925 | } |
| 16926 | |
| 16927 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding2) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 16928 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "", "", |
| 16929 | true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 16930 | } |
| 16931 | |
| 16932 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding3) { |
| 16933 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 16934 | "", false); |
| 16935 | } |
| 16936 | |
| 16937 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding4) { |
| 16938 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
| 16939 | "www.foo.com/other", true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 16940 | } |
| 16941 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 16942 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsSync) { |
| 16943 | ProxyConfig proxy_config; |
| 16944 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 16945 | proxy_config.set_pac_mandatory(true); |
| 16946 | MockAsyncProxyResolver resolver; |
| 16947 | session_deps_.proxy_service.reset(new ProxyService( |
| 16948 | base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), |
| 16949 | base::WrapUnique(new FailingProxyResolverFactory), nullptr)); |
| 16950 | |
| 16951 | HttpRequestInfo request; |
| 16952 | request.method = "GET"; |
| 16953 | request.url = GURL("http://www.example.org/"); |
| 16954 | |
| 16955 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 16956 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 16957 | |
| 16958 | TestCompletionCallback callback; |
| 16959 | |
| 16960 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 16961 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16962 | EXPECT_THAT(callback.WaitForResult(), |
| 16963 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 16964 | } |
| 16965 | |
| 16966 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsAsync) { |
| 16967 | ProxyConfig proxy_config; |
| 16968 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 16969 | proxy_config.set_pac_mandatory(true); |
| 16970 | MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 16971 | new MockAsyncProxyResolverFactory(false); |
| 16972 | MockAsyncProxyResolver resolver; |
| 16973 | session_deps_.proxy_service.reset( |
| 16974 | new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), |
| 16975 | base::WrapUnique(proxy_resolver_factory), nullptr)); |
| 16976 | HttpRequestInfo request; |
| 16977 | request.method = "GET"; |
| 16978 | request.url = GURL("http://www.example.org/"); |
| 16979 | |
| 16980 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 16981 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 16982 | |
| 16983 | TestCompletionCallback callback; |
| 16984 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 16985 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16986 | |
| 16987 | proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder( |
| 16988 | ERR_FAILED, &resolver); |
| 16989 | EXPECT_THAT(callback.WaitForResult(), |
| 16990 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 16991 | } |
| 16992 | |
| 16993 | TEST_F(HttpNetworkTransactionTest, NoSupportedProxies) { |
| 16994 | session_deps_.proxy_service = |
| 16995 | ProxyService::CreateFixedFromPacResult("QUIC myproxy.org:443"); |
| 16996 | session_deps_.enable_quic = false; |
| 16997 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 16998 | |
| 16999 | HttpRequestInfo request; |
| 17000 | request.method = "GET"; |
| 17001 | request.url = GURL("http://www.example.org/"); |
| 17002 | |
| 17003 | TestCompletionCallback callback; |
| 17004 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17005 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17006 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17007 | |
| 17008 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_NO_SUPPORTED_PROXIES)); |
| 17009 | } |
| 17010 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 17011 | } // namespace net |