[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 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1682 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionNotConnectedOnWrite) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1683 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1684 | KeepAliveConnectionResendRequestTest(&write_failure, NULL); |
| 1685 | } |
| 1686 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1687 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionReset) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1688 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1689 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1690 | } |
| 1691 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1692 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1693 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1694 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1695 | } |
| 1696 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1697 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1698 | // if the socket was a reused keep alive socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1699 | TEST_F(HttpNetworkTransactionTest, KeepAlive408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1700 | MockRead read_failure(SYNCHRONOUS, |
| 1701 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1702 | "Connection: Keep-Alive\r\n" |
| 1703 | "Content-Length: 6\r\n\r\n" |
| 1704 | "Pickle"); |
| 1705 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1706 | } |
| 1707 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1708 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorNotConnectedOnWrite) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1709 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1710 | PreconnectErrorResendRequestTest(&write_failure, NULL, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1711 | } |
| 1712 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1713 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorReset) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1714 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1715 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1716 | } |
| 1717 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1718 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorEOF) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1719 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1720 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1721 | } |
| 1722 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1723 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1724 | MockRead read_failure(ASYNC, OK); // EOF |
| 1725 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1726 | } |
| 1727 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1728 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1729 | // if the socket was a preconnected (UNUSED_IDLE) socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1730 | TEST_F(HttpNetworkTransactionTest, RetryOnIdle408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1731 | MockRead read_failure(SYNCHRONOUS, |
| 1732 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1733 | "Connection: Keep-Alive\r\n" |
| 1734 | "Content-Length: 6\r\n\r\n" |
| 1735 | "Pickle"); |
| 1736 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1737 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1738 | } |
| 1739 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1740 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorNotConnectedOnWrite) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1741 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
| 1742 | PreconnectErrorResendRequestTest(&write_failure, NULL, true); |
| 1743 | } |
| 1744 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1745 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorReset) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1746 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
| 1747 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1748 | } |
| 1749 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1750 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1751 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
| 1752 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1753 | } |
| 1754 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1755 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1756 | MockRead read_failure(ASYNC, OK); // EOF |
| 1757 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1758 | } |
| 1759 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1760 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1761 | HttpRequestInfo request; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1762 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1763 | request.url = GURL("http://www.example.org/"); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1764 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1765 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1766 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1767 | |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1768 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1769 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1770 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1771 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1772 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1773 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1774 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1775 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1776 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1777 | TestCompletionCallback callback; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1778 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1779 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1780 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1781 | |
| 1782 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1783 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 1784 | |
| 1785 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1786 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 1787 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1788 | } |
| 1789 | |
| 1790 | // What do various browsers do when the server closes a non-keepalive |
| 1791 | // connection without sending any response header or body? |
| 1792 | // |
| 1793 | // IE7: error page |
| 1794 | // Safari 3.1.2 (Windows): error page |
| 1795 | // Firefox 3.0.1: blank page |
| 1796 | // Opera 9.52: after five attempts, blank page |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1797 | // Us with WinHTTP: error page (ERR_INVALID_RESPONSE) |
| 1798 | // Us: error page (EMPTY_RESPONSE) |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1799 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionEOF) { |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1800 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1801 | MockRead(SYNCHRONOUS, OK), // EOF |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1802 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1803 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1804 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1805 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1806 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1807 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1808 | EXPECT_THAT(out.rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1809 | } |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1810 | |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1811 | // Next 2 cases (KeepAliveEarlyClose and KeepAliveEarlyClose2) are regression |
| 1812 | // tests. There was a bug causing HttpNetworkTransaction to hang in the |
| 1813 | // destructor in such situations. |
| 1814 | // See http://crbug.com/154712 and http://crbug.com/156609. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1815 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1816 | HttpRequestInfo request; |
| 1817 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1818 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1819 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1820 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 1821 | auto trans = |
| 1822 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1823 | |
| 1824 | MockRead data_reads[] = { |
| 1825 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1826 | MockRead("Connection: keep-alive\r\n"), |
| 1827 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1828 | MockRead("hello"), |
| 1829 | MockRead(SYNCHRONOUS, 0), |
| 1830 | }; |
| 1831 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1832 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1833 | |
| 1834 | TestCompletionCallback callback; |
| 1835 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1836 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1837 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1838 | |
| 1839 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1840 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1841 | |
| 1842 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1843 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1844 | if (rv == ERR_IO_PENDING) |
| 1845 | rv = callback.WaitForResult(); |
| 1846 | EXPECT_EQ(5, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1847 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1848 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1849 | |
| 1850 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 1851 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1852 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1853 | } |
| 1854 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1855 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose2) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1856 | HttpRequestInfo request; |
| 1857 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1858 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1859 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1860 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 1861 | auto trans = |
| 1862 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1863 | |
| 1864 | MockRead data_reads[] = { |
| 1865 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1866 | MockRead("Connection: keep-alive\r\n"), |
| 1867 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1868 | MockRead(SYNCHRONOUS, 0), |
| 1869 | }; |
| 1870 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1871 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1872 | |
| 1873 | TestCompletionCallback callback; |
| 1874 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1875 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1876 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1877 | |
| 1878 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1879 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1880 | |
| 1881 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1882 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1883 | if (rv == ERR_IO_PENDING) |
| 1884 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1885 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1886 | |
| 1887 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 1888 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1889 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1890 | } |
| 1891 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1892 | // Test that we correctly reuse a keep-alive connection after not explicitly |
| 1893 | // reading the body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1894 | TEST_F(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) { |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1895 | HttpRequestInfo request; |
| 1896 | request.method = "GET"; |
| 1897 | request.url = GURL("http://www.foo.com/"); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1898 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1899 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1900 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1901 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1902 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1903 | const char* request_data = |
| 1904 | "GET / HTTP/1.1\r\n" |
| 1905 | "Host: www.foo.com\r\n" |
| 1906 | "Connection: keep-alive\r\n\r\n"; |
| 1907 | MockWrite data_writes[] = { |
| 1908 | MockWrite(ASYNC, 0, request_data), MockWrite(ASYNC, 2, request_data), |
| 1909 | MockWrite(ASYNC, 4, request_data), MockWrite(ASYNC, 6, request_data), |
| 1910 | MockWrite(ASYNC, 8, request_data), MockWrite(ASYNC, 10, request_data), |
| 1911 | MockWrite(ASYNC, 12, request_data), MockWrite(ASYNC, 14, request_data), |
| 1912 | MockWrite(ASYNC, 17, request_data), MockWrite(ASYNC, 20, request_data), |
| 1913 | }; |
| 1914 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1915 | // Note that because all these reads happen in the same |
| 1916 | // StaticSocketDataProvider, it shows that the same socket is being reused for |
| 1917 | // all transactions. |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1918 | MockRead data_reads[] = { |
| 1919 | MockRead(ASYNC, 1, "HTTP/1.1 204 No Content\r\n\r\n"), |
| 1920 | MockRead(ASYNC, 3, "HTTP/1.1 205 Reset Content\r\n\r\n"), |
| 1921 | MockRead(ASYNC, 5, "HTTP/1.1 304 Not Modified\r\n\r\n"), |
| 1922 | MockRead(ASYNC, 7, |
| 1923 | "HTTP/1.1 302 Found\r\n" |
| 1924 | "Content-Length: 0\r\n\r\n"), |
| 1925 | MockRead(ASYNC, 9, |
| 1926 | "HTTP/1.1 302 Found\r\n" |
| 1927 | "Content-Length: 5\r\n\r\n" |
| 1928 | "hello"), |
| 1929 | MockRead(ASYNC, 11, |
| 1930 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 1931 | "Content-Length: 0\r\n\r\n"), |
| 1932 | MockRead(ASYNC, 13, |
| 1933 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 1934 | "Content-Length: 5\r\n\r\n" |
| 1935 | "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1936 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1937 | // In the next two rounds, IsConnectedAndIdle returns false, due to |
| 1938 | // the set_busy_before_sync_reads(true) call, while the |
| 1939 | // HttpNetworkTransaction is being shut down, but the socket is still |
| 1940 | // reuseable. See http://crbug.com/544255. |
| 1941 | MockRead(ASYNC, 15, |
| 1942 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 1943 | "Content-Length: 5\r\n\r\n"), |
| 1944 | MockRead(SYNCHRONOUS, 16, "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1945 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1946 | MockRead(ASYNC, 18, |
| 1947 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 1948 | "Content-Length: 5\r\n\r\n" |
| 1949 | "he"), |
| 1950 | MockRead(SYNCHRONOUS, 19, "llo"), |
| 1951 | |
| 1952 | // The body of the final request is actually read. |
| 1953 | MockRead(ASYNC, 21, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1954 | MockRead(ASYNC, 22, "hello"), |
| 1955 | }; |
| 1956 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 1957 | arraysize(data_writes)); |
| 1958 | data.set_busy_before_sync_reads(true); |
| 1959 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1960 | |
| 1961 | const int kNumUnreadBodies = arraysize(data_writes) - 1; |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1962 | std::string response_lines[kNumUnreadBodies]; |
| 1963 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 1964 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1965 | for (size_t i = 0; i < kNumUnreadBodies; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1966 | TestCompletionCallback callback; |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1967 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 1968 | auto trans = base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
| 1969 | session.get()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1970 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1971 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1972 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1973 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1974 | LoadTimingInfo load_timing_info; |
| 1975 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 1976 | if (i == 0) { |
| 1977 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1978 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1979 | } else { |
| 1980 | TestLoadTimingReused(load_timing_info); |
| 1981 | EXPECT_EQ(first_socket_log_id, load_timing_info.socket_log_id); |
| 1982 | } |
| 1983 | |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1984 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1985 | ASSERT_TRUE(response); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1986 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1987 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1988 | response_lines[i] = response->headers->GetStatusLine(); |
| 1989 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1990 | // Delete the transaction without reading the response bodies. Then spin |
| 1991 | // the message loop, so the response bodies are drained. |
| 1992 | trans.reset(); |
| 1993 | base::RunLoop().RunUntilIdle(); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1994 | } |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1995 | |
| 1996 | const char* const kStatusLines[] = { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1997 | "HTTP/1.1 204 No Content", |
| 1998 | "HTTP/1.1 205 Reset Content", |
| 1999 | "HTTP/1.1 304 Not Modified", |
| 2000 | "HTTP/1.1 302 Found", |
| 2001 | "HTTP/1.1 302 Found", |
| 2002 | "HTTP/1.1 301 Moved Permanently", |
| 2003 | "HTTP/1.1 301 Moved Permanently", |
| 2004 | "HTTP/1.1 200 Hunky-Dory", |
| 2005 | "HTTP/1.1 200 Hunky-Dory", |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2006 | }; |
| 2007 | |
mostynb | 91e0da98 | 2015-01-20 19:17:27 | [diff] [blame] | 2008 | static_assert(kNumUnreadBodies == arraysize(kStatusLines), |
| 2009 | "forgot to update kStatusLines"); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2010 | |
| 2011 | for (int i = 0; i < kNumUnreadBodies; ++i) |
| 2012 | EXPECT_EQ(kStatusLines[i], response_lines[i]); |
| 2013 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2014 | TestCompletionCallback callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2015 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2016 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2017 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2018 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2019 | ASSERT_TRUE(response); |
| 2020 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2021 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 2022 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2023 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2024 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2025 | EXPECT_EQ("hello", response_data); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2026 | } |
| 2027 | |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2028 | // Sockets that receive extra data after a response is complete should not be |
| 2029 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2030 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData1) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2031 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2032 | MockWrite data_writes1[] = { |
| 2033 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 2034 | "Host: www.borked.com\r\n" |
| 2035 | "Connection: keep-alive\r\n\r\n"), |
| 2036 | }; |
| 2037 | |
| 2038 | MockRead data_reads1[] = { |
| 2039 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2040 | "Connection: keep-alive\r\n" |
| 2041 | "Content-Length: 22\r\n\r\n" |
| 2042 | "This server is borked."), |
| 2043 | }; |
| 2044 | |
| 2045 | MockWrite data_writes2[] = { |
| 2046 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2047 | "Host: www.borked.com\r\n" |
| 2048 | "Connection: keep-alive\r\n\r\n"), |
| 2049 | }; |
| 2050 | |
| 2051 | MockRead data_reads2[] = { |
| 2052 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2053 | "Content-Length: 3\r\n\r\n" |
| 2054 | "foo"), |
| 2055 | }; |
| 2056 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2057 | data_writes1, arraysize(data_writes1)); |
| 2058 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2059 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2060 | data_writes2, arraysize(data_writes2)); |
| 2061 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2062 | |
| 2063 | TestCompletionCallback callback; |
| 2064 | HttpRequestInfo request1; |
| 2065 | request1.method = "HEAD"; |
| 2066 | request1.url = GURL("http://www.borked.com/"); |
| 2067 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2068 | auto trans1 = |
| 2069 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2070 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2071 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2072 | |
| 2073 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2074 | ASSERT_TRUE(response1); |
| 2075 | ASSERT_TRUE(response1->headers); |
| 2076 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2077 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2078 | |
| 2079 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2080 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2081 | EXPECT_EQ("", response_data1); |
| 2082 | // Deleting the transaction attempts to release the socket back into the |
| 2083 | // socket pool. |
| 2084 | trans1.reset(); |
| 2085 | |
| 2086 | HttpRequestInfo request2; |
| 2087 | request2.method = "GET"; |
| 2088 | request2.url = GURL("http://www.borked.com/foo"); |
| 2089 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2090 | auto trans2 = |
| 2091 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2092 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2093 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2094 | |
| 2095 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2096 | ASSERT_TRUE(response2); |
| 2097 | ASSERT_TRUE(response2->headers); |
| 2098 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2099 | |
| 2100 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2101 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2102 | EXPECT_EQ("foo", response_data2); |
| 2103 | } |
| 2104 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2105 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData2) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2106 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2107 | MockWrite data_writes1[] = { |
| 2108 | MockWrite("GET / HTTP/1.1\r\n" |
| 2109 | "Host: www.borked.com\r\n" |
| 2110 | "Connection: keep-alive\r\n\r\n"), |
| 2111 | }; |
| 2112 | |
| 2113 | MockRead data_reads1[] = { |
| 2114 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2115 | "Connection: keep-alive\r\n" |
| 2116 | "Content-Length: 22\r\n\r\n" |
| 2117 | "This server is borked." |
| 2118 | "Bonus data!"), |
| 2119 | }; |
| 2120 | |
| 2121 | MockWrite data_writes2[] = { |
| 2122 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2123 | "Host: www.borked.com\r\n" |
| 2124 | "Connection: keep-alive\r\n\r\n"), |
| 2125 | }; |
| 2126 | |
| 2127 | MockRead data_reads2[] = { |
| 2128 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2129 | "Content-Length: 3\r\n\r\n" |
| 2130 | "foo"), |
| 2131 | }; |
| 2132 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2133 | data_writes1, arraysize(data_writes1)); |
| 2134 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2135 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2136 | data_writes2, arraysize(data_writes2)); |
| 2137 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2138 | |
| 2139 | TestCompletionCallback callback; |
| 2140 | HttpRequestInfo request1; |
| 2141 | request1.method = "GET"; |
| 2142 | request1.url = GURL("http://www.borked.com/"); |
| 2143 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2144 | auto trans1 = |
| 2145 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2146 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2147 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2148 | |
| 2149 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2150 | ASSERT_TRUE(response1); |
| 2151 | ASSERT_TRUE(response1->headers); |
| 2152 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2153 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2154 | |
| 2155 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2156 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2157 | EXPECT_EQ("This server is borked.", response_data1); |
| 2158 | // Deleting the transaction attempts to release the socket back into the |
| 2159 | // socket pool. |
| 2160 | trans1.reset(); |
| 2161 | |
| 2162 | HttpRequestInfo request2; |
| 2163 | request2.method = "GET"; |
| 2164 | request2.url = GURL("http://www.borked.com/foo"); |
| 2165 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2166 | auto trans2 = |
| 2167 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2168 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2169 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2170 | |
| 2171 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2172 | ASSERT_TRUE(response2); |
| 2173 | ASSERT_TRUE(response2->headers); |
| 2174 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2175 | |
| 2176 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2177 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2178 | EXPECT_EQ("foo", response_data2); |
| 2179 | } |
| 2180 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2181 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData3) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2182 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2183 | MockWrite data_writes1[] = { |
| 2184 | MockWrite("GET / HTTP/1.1\r\n" |
| 2185 | "Host: www.borked.com\r\n" |
| 2186 | "Connection: keep-alive\r\n\r\n"), |
| 2187 | }; |
| 2188 | |
| 2189 | MockRead data_reads1[] = { |
| 2190 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2191 | "Connection: keep-alive\r\n" |
| 2192 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2193 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2194 | MockRead("0\r\n\r\nBonus data!"), |
| 2195 | }; |
| 2196 | |
| 2197 | MockWrite data_writes2[] = { |
| 2198 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2199 | "Host: www.borked.com\r\n" |
| 2200 | "Connection: keep-alive\r\n\r\n"), |
| 2201 | }; |
| 2202 | |
| 2203 | MockRead data_reads2[] = { |
| 2204 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2205 | "Content-Length: 3\r\n\r\n" |
| 2206 | "foo"), |
| 2207 | }; |
| 2208 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2209 | data_writes1, arraysize(data_writes1)); |
| 2210 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2211 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2212 | data_writes2, arraysize(data_writes2)); |
| 2213 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2214 | |
| 2215 | TestCompletionCallback callback; |
| 2216 | HttpRequestInfo request1; |
| 2217 | request1.method = "GET"; |
| 2218 | request1.url = GURL("http://www.borked.com/"); |
| 2219 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2220 | auto trans1 = |
| 2221 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2222 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2223 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2224 | |
| 2225 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2226 | ASSERT_TRUE(response1); |
| 2227 | ASSERT_TRUE(response1->headers); |
| 2228 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2229 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2230 | |
| 2231 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2232 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2233 | EXPECT_EQ("This server is borked.", response_data1); |
| 2234 | // Deleting the transaction attempts to release the socket back into the |
| 2235 | // socket pool. |
| 2236 | trans1.reset(); |
| 2237 | |
| 2238 | HttpRequestInfo request2; |
| 2239 | request2.method = "GET"; |
| 2240 | request2.url = GURL("http://www.borked.com/foo"); |
| 2241 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2242 | auto trans2 = |
| 2243 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2244 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2245 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2246 | |
| 2247 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2248 | ASSERT_TRUE(response2); |
| 2249 | ASSERT_TRUE(response2->headers); |
| 2250 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2251 | |
| 2252 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2253 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2254 | EXPECT_EQ("foo", response_data2); |
| 2255 | } |
| 2256 | |
| 2257 | // This is a little different from the others - it tests the case that the |
| 2258 | // HttpStreamParser doesn't know if there's extra data on a socket or not when |
| 2259 | // the HttpNetworkTransaction is torn down, because the response body hasn't |
| 2260 | // been read from yet, but the request goes through the HttpResponseBodyDrainer. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2261 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData4) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2262 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2263 | MockWrite data_writes1[] = { |
| 2264 | MockWrite("GET / HTTP/1.1\r\n" |
| 2265 | "Host: www.borked.com\r\n" |
| 2266 | "Connection: keep-alive\r\n\r\n"), |
| 2267 | }; |
| 2268 | |
| 2269 | MockRead data_reads1[] = { |
| 2270 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2271 | "Connection: keep-alive\r\n" |
| 2272 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2273 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2274 | MockRead("0\r\n\r\nBonus data!"), |
| 2275 | }; |
| 2276 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2277 | data_writes1, arraysize(data_writes1)); |
| 2278 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2279 | |
| 2280 | TestCompletionCallback callback; |
| 2281 | HttpRequestInfo request1; |
| 2282 | request1.method = "GET"; |
| 2283 | request1.url = GURL("http://www.borked.com/"); |
| 2284 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2285 | auto trans = |
| 2286 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 2287 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2288 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2289 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2290 | const HttpResponseInfo* response1 = trans->GetResponseInfo(); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2291 | ASSERT_TRUE(response1); |
| 2292 | ASSERT_TRUE(response1->headers); |
| 2293 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2294 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2295 | |
| 2296 | // Deleting the transaction creates an HttpResponseBodyDrainer to read the |
| 2297 | // response body. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2298 | trans.reset(); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2299 | |
| 2300 | // Let the HttpResponseBodyDrainer drain the socket. It should determine the |
| 2301 | // socket can't be reused, rather than returning it to the socket pool. |
| 2302 | base::RunLoop().RunUntilIdle(); |
| 2303 | |
| 2304 | // There should be no idle sockets in the pool. |
| 2305 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2306 | } |
| 2307 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2308 | // Test the request-challenge-retry sequence for basic auth. |
| 2309 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2310 | TEST_F(HttpNetworkTransactionTest, BasicAuth) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2311 | HttpRequestInfo request; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2312 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2313 | request.url = GURL("http://www.example.org/"); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2314 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2315 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2316 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2317 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2318 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2319 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2320 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2321 | MockWrite( |
| 2322 | "GET / HTTP/1.1\r\n" |
| 2323 | "Host: www.example.org\r\n" |
| 2324 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2325 | }; |
| 2326 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2327 | MockRead data_reads1[] = { |
| 2328 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2329 | // Give a couple authenticate options (only the middle one is actually |
| 2330 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 2331 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2332 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2333 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2334 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2335 | // Large content-length -- won't matter, as connection will be reset. |
| 2336 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2337 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2338 | }; |
| 2339 | |
| 2340 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2341 | // be issuing -- the final header line contains the credentials. |
| 2342 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2343 | MockWrite( |
| 2344 | "GET / HTTP/1.1\r\n" |
| 2345 | "Host: www.example.org\r\n" |
| 2346 | "Connection: keep-alive\r\n" |
| 2347 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2348 | }; |
| 2349 | |
| 2350 | // Lastly, the server responds with the actual content. |
| 2351 | MockRead data_reads2[] = { |
| 2352 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2353 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2354 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2355 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2356 | }; |
| 2357 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2358 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2359 | data_writes1, arraysize(data_writes1)); |
| 2360 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2361 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2362 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2363 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2364 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2365 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2366 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2367 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2368 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2369 | |
| 2370 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2371 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2372 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2373 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2374 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2375 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2376 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2377 | int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2378 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2379 | int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2380 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2381 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2382 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2383 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2384 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2385 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2386 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2387 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2388 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2389 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2390 | |
| 2391 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2392 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2393 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2394 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2395 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2396 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2397 | // The load timing after restart should have a new socket ID, and times after |
| 2398 | // those of the first load timing. |
| 2399 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2400 | load_timing_info2.connect_timing.connect_start); |
| 2401 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2402 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2403 | int64_t writes_size2 = CountWriteBytes(data_writes2, arraysize(data_writes2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2404 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2405 | int64_t reads_size2 = CountReadBytes(data_reads2, arraysize(data_reads2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2406 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2407 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2408 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2409 | ASSERT_TRUE(response); |
| 2410 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2411 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2412 | } |
| 2413 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2414 | // Test the request-challenge-retry sequence for basic auth. |
| 2415 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2416 | TEST_F(HttpNetworkTransactionTest, BasicAuthWithAddressChange) { |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2417 | HttpRequestInfo request; |
| 2418 | request.method = "GET"; |
| 2419 | request.url = GURL("http://www.example.org/"); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2420 | |
| 2421 | TestNetLog log; |
| 2422 | MockHostResolver* resolver = new MockHostResolver(); |
| 2423 | session_deps_.net_log = &log; |
| 2424 | session_deps_.host_resolver.reset(resolver); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2425 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2426 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2427 | |
| 2428 | resolver->rules()->ClearRules(); |
| 2429 | resolver->rules()->AddRule("www.example.org", "127.0.0.1"); |
| 2430 | |
| 2431 | MockWrite data_writes1[] = { |
| 2432 | MockWrite("GET / HTTP/1.1\r\n" |
| 2433 | "Host: www.example.org\r\n" |
| 2434 | "Connection: keep-alive\r\n\r\n"), |
| 2435 | }; |
| 2436 | |
| 2437 | MockRead data_reads1[] = { |
| 2438 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2439 | // Give a couple authenticate options (only the middle one is actually |
| 2440 | // supported). |
| 2441 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 2442 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2443 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2444 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2445 | // Large content-length -- won't matter, as connection will be reset. |
| 2446 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 2447 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 2448 | }; |
| 2449 | |
| 2450 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2451 | // be issuing -- the final header line contains the credentials. |
| 2452 | MockWrite data_writes2[] = { |
| 2453 | MockWrite("GET / HTTP/1.1\r\n" |
| 2454 | "Host: www.example.org\r\n" |
| 2455 | "Connection: keep-alive\r\n" |
| 2456 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2457 | }; |
| 2458 | |
| 2459 | // Lastly, the server responds with the actual content. |
| 2460 | MockRead data_reads2[] = { |
| 2461 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2462 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2463 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, OK), |
| 2464 | }; |
| 2465 | |
| 2466 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2467 | data_writes1, arraysize(data_writes1)); |
| 2468 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2469 | data_writes2, arraysize(data_writes2)); |
| 2470 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2471 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2472 | |
| 2473 | TestCompletionCallback callback1; |
| 2474 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2475 | EXPECT_EQ(OK, callback1.GetResult(trans.Start(&request, callback1.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2476 | NetLogWithSource()))); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2477 | |
| 2478 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2479 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2480 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2481 | |
| 2482 | int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2483 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2484 | int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2485 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2486 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2487 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2488 | ASSERT_TRUE(response); |
| 2489 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 2490 | |
| 2491 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2492 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2493 | ASSERT_FALSE(endpoint.address().empty()); |
| 2494 | EXPECT_EQ("127.0.0.1:80", endpoint.ToString()); |
| 2495 | |
| 2496 | resolver->rules()->ClearRules(); |
| 2497 | resolver->rules()->AddRule("www.example.org", "127.0.0.2"); |
| 2498 | |
| 2499 | TestCompletionCallback callback2; |
| 2500 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2501 | EXPECT_EQ(OK, callback2.GetResult(trans.RestartWithAuth( |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2502 | AuthCredentials(kFoo, kBar), callback2.callback()))); |
| 2503 | |
| 2504 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2505 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2506 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2507 | // The load timing after restart should have a new socket ID, and times after |
| 2508 | // those of the first load timing. |
| 2509 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2510 | load_timing_info2.connect_timing.connect_start); |
| 2511 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2512 | |
| 2513 | int64_t writes_size2 = CountWriteBytes(data_writes2, arraysize(data_writes2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2514 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2515 | int64_t reads_size2 = CountReadBytes(data_reads2, arraysize(data_reads2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2516 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2517 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2518 | response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2519 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2520 | EXPECT_FALSE(response->auth_challenge); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2521 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 2522 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2523 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2524 | ASSERT_FALSE(endpoint.address().empty()); |
| 2525 | EXPECT_EQ("127.0.0.2:80", endpoint.ToString()); |
| 2526 | } |
| 2527 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2528 | TEST_F(HttpNetworkTransactionTest, DoNotSendAuth) { |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2529 | HttpRequestInfo request; |
| 2530 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2531 | request.url = GURL("http://www.example.org/"); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2532 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2533 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2534 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2535 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2536 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2537 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2538 | MockWrite( |
| 2539 | "GET / HTTP/1.1\r\n" |
| 2540 | "Host: www.example.org\r\n" |
| 2541 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2542 | }; |
| 2543 | |
| 2544 | MockRead data_reads[] = { |
| 2545 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2546 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2547 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2548 | // Large content-length -- won't matter, as connection will be reset. |
| 2549 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2550 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2551 | }; |
| 2552 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2553 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 2554 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2555 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2556 | TestCompletionCallback callback; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2557 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2558 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2559 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2560 | |
| 2561 | rv = callback.WaitForResult(); |
| 2562 | EXPECT_EQ(0, rv); |
| 2563 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2564 | int64_t writes_size = CountWriteBytes(data_writes, arraysize(data_writes)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2565 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2566 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2567 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2568 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2569 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2570 | ASSERT_TRUE(response); |
| 2571 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2572 | } |
| 2573 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2574 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2575 | // connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2576 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAlive) { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2577 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 2578 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 2579 | // reused. See http://crbug.com/544255. |
| 2580 | for (int i = 0; i < 2; ++i) { |
| 2581 | HttpRequestInfo request; |
| 2582 | request.method = "GET"; |
| 2583 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2584 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2585 | TestNetLog log; |
| 2586 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2587 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2588 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2589 | MockWrite data_writes[] = { |
| 2590 | MockWrite(ASYNC, 0, |
| 2591 | "GET / HTTP/1.1\r\n" |
| 2592 | "Host: www.example.org\r\n" |
| 2593 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2594 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2595 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2596 | // be issuing -- the final header line contains the credentials. |
| 2597 | MockWrite(ASYNC, 6, |
| 2598 | "GET / HTTP/1.1\r\n" |
| 2599 | "Host: www.example.org\r\n" |
| 2600 | "Connection: keep-alive\r\n" |
| 2601 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2602 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2603 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2604 | MockRead data_reads[] = { |
| 2605 | MockRead(ASYNC, 1, "HTTP/1.1 401 Unauthorized\r\n"), |
| 2606 | MockRead(ASYNC, 2, "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2607 | MockRead(ASYNC, 3, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2608 | MockRead(ASYNC, 4, "Content-Length: 14\r\n\r\n"), |
| 2609 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 5, "Unauthorized\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2610 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2611 | // Lastly, the server responds with the actual content. |
| 2612 | MockRead(ASYNC, 7, "HTTP/1.1 200 OK\r\n"), |
| 2613 | MockRead(ASYNC, 8, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2614 | MockRead(ASYNC, 9, "Content-Length: 5\r\n\r\n"), |
| 2615 | MockRead(ASYNC, 10, "Hello"), |
| 2616 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2617 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2618 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 2619 | arraysize(data_writes)); |
| 2620 | data.set_busy_before_sync_reads(true); |
| 2621 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2622 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2623 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2624 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2625 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2626 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2627 | ASSERT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2628 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2629 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2630 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2631 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2632 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2633 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2634 | ASSERT_TRUE(response); |
| 2635 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2636 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2637 | TestCompletionCallback callback2; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2638 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2639 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 2640 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2641 | ASSERT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2642 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2643 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2644 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2645 | TestLoadTimingReused(load_timing_info2); |
| 2646 | // The load timing after restart should have the same socket ID, and times |
| 2647 | // those of the first load timing. |
| 2648 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2649 | load_timing_info2.send_start); |
| 2650 | 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] | 2651 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2652 | response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2653 | ASSERT_TRUE(response); |
| 2654 | EXPECT_FALSE(response->auth_challenge); |
| 2655 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2656 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2657 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2658 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2659 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2660 | int64_t writes_size = CountWriteBytes(data_writes, arraysize(data_writes)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2661 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2662 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2663 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2664 | } |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2665 | } |
| 2666 | |
| 2667 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2668 | // connection and with no response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2669 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2670 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2671 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2672 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2673 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2674 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2675 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2676 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2677 | MockWrite("GET / HTTP/1.1\r\n" |
| 2678 | "Host: www.example.org\r\n" |
| 2679 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2680 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2681 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2682 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2683 | MockWrite("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"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2687 | }; |
| 2688 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2689 | MockRead data_reads1[] = { |
| 2690 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2691 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2692 | MockRead("Content-Length: 0\r\n\r\n"), // No response body. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2693 | |
| 2694 | // Lastly, the server responds with the actual content. |
| 2695 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2696 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2697 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2698 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2699 | }; |
| 2700 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2701 | // An incorrect reconnect would cause this to be read. |
| 2702 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2703 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2704 | }; |
| 2705 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2706 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2707 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2708 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2709 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2710 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2711 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2712 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2713 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2714 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2715 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2716 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2717 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2718 | |
| 2719 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2720 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2721 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2722 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2723 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2724 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2725 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2726 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2727 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2728 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2729 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2730 | |
| 2731 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2732 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2733 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2734 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2735 | ASSERT_TRUE(response); |
| 2736 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2737 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2738 | } |
| 2739 | |
| 2740 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2741 | // connection and with a large response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2742 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2743 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2744 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2745 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2746 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2747 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2748 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2749 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2750 | MockWrite("GET / HTTP/1.1\r\n" |
| 2751 | "Host: www.example.org\r\n" |
| 2752 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2753 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2754 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2755 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2756 | MockWrite("GET / HTTP/1.1\r\n" |
| 2757 | "Host: www.example.org\r\n" |
| 2758 | "Connection: keep-alive\r\n" |
| 2759 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2760 | }; |
| 2761 | |
| 2762 | // Respond with 5 kb of response body. |
| 2763 | std::string large_body_string("Unauthorized"); |
| 2764 | large_body_string.append(5 * 1024, ' '); |
| 2765 | large_body_string.append("\r\n"); |
| 2766 | |
| 2767 | MockRead data_reads1[] = { |
| 2768 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2769 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2770 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2771 | // 5134 = 12 + 5 * 1024 + 2 |
| 2772 | MockRead("Content-Length: 5134\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2773 | MockRead(ASYNC, large_body_string.data(), large_body_string.size()), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2774 | |
| 2775 | // Lastly, the server responds with the actual content. |
| 2776 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2777 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2778 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2779 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2780 | }; |
| 2781 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2782 | // An incorrect reconnect would cause this to be read. |
| 2783 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2784 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2785 | }; |
| 2786 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2787 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2788 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2789 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2790 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2791 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2792 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2793 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2794 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2795 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2796 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2797 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2798 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2799 | |
| 2800 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2801 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2802 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2803 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2804 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2805 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2806 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2807 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2808 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2809 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2810 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2811 | |
| 2812 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2813 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2814 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2815 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2816 | ASSERT_TRUE(response); |
| 2817 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2818 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2819 | } |
| 2820 | |
| 2821 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2822 | // connection, but the server gets impatient and closes the connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2823 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) { |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2824 | HttpRequestInfo request; |
| 2825 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2826 | request.url = GURL("http://www.example.org/"); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2827 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2828 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2829 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2830 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2831 | MockWrite( |
| 2832 | "GET / HTTP/1.1\r\n" |
| 2833 | "Host: www.example.org\r\n" |
| 2834 | "Connection: keep-alive\r\n\r\n"), |
| 2835 | // This simulates the seemingly successful write to a closed connection |
| 2836 | // if the bug is not fixed. |
| 2837 | MockWrite( |
| 2838 | "GET / HTTP/1.1\r\n" |
| 2839 | "Host: www.example.org\r\n" |
| 2840 | "Connection: keep-alive\r\n" |
| 2841 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2842 | }; |
| 2843 | |
| 2844 | MockRead data_reads1[] = { |
| 2845 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2846 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2847 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2848 | MockRead("Content-Length: 14\r\n\r\n"), |
| 2849 | // Tell MockTCPClientSocket to simulate the server closing the connection. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2850 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2851 | MockRead("Unauthorized\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2852 | MockRead(SYNCHRONOUS, OK), // The server closes the connection. |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2853 | }; |
| 2854 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2855 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2856 | // be issuing -- the final header line contains the credentials. |
| 2857 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2858 | MockWrite( |
| 2859 | "GET / HTTP/1.1\r\n" |
| 2860 | "Host: www.example.org\r\n" |
| 2861 | "Connection: keep-alive\r\n" |
| 2862 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2863 | }; |
| 2864 | |
| 2865 | // Lastly, the server responds with the actual content. |
| 2866 | MockRead data_reads2[] = { |
| 2867 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2868 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2869 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2870 | MockRead("hello"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2871 | }; |
| 2872 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2873 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2874 | data_writes1, arraysize(data_writes1)); |
| 2875 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2876 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2877 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2878 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2879 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2880 | TestCompletionCallback callback1; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2881 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2882 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2883 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2884 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2885 | |
| 2886 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2887 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2888 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2889 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2890 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2891 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2892 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2893 | TestCompletionCallback callback2; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2894 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2895 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2896 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2897 | |
| 2898 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2899 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2900 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2901 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2902 | ASSERT_TRUE(response); |
| 2903 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2904 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2905 | } |
| 2906 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2907 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 2908 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2909 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp10) { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2910 | HttpRequestInfo request; |
| 2911 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2912 | request.url = GURL("https://www.example.org/"); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2913 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2914 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2915 | |
| 2916 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 2917 | session_deps_.proxy_service = |
| 2918 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2919 | BoundTestNetLog log; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2920 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2921 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2922 | |
| 2923 | // Since we have proxy, should try to establish tunnel. |
| 2924 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2925 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 2926 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2927 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2928 | }; |
| 2929 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2930 | // The proxy responds to the connect with a 407, using a non-persistent |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2931 | // connection. |
| 2932 | MockRead data_reads1[] = { |
| 2933 | // No credentials. |
| 2934 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 2935 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2936 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2937 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2938 | // Since the first connection couldn't be reused, need to establish another |
| 2939 | // once given credentials. |
| 2940 | MockWrite data_writes2[] = { |
| 2941 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2942 | // be issuing -- the final header line contains the credentials. |
| 2943 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 2944 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2945 | "Proxy-Connection: keep-alive\r\n" |
| 2946 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2947 | |
| 2948 | MockWrite("GET / HTTP/1.1\r\n" |
| 2949 | "Host: www.example.org\r\n" |
| 2950 | "Connection: keep-alive\r\n\r\n"), |
| 2951 | }; |
| 2952 | |
| 2953 | MockRead data_reads2[] = { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2954 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 2955 | |
| 2956 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2957 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2958 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2959 | MockRead(SYNCHRONOUS, "hello"), |
| 2960 | }; |
| 2961 | |
| 2962 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2963 | data_writes1, arraysize(data_writes1)); |
| 2964 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2965 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2966 | data_writes2, arraysize(data_writes2)); |
| 2967 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2968 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 2969 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 2970 | |
| 2971 | TestCompletionCallback callback1; |
| 2972 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2973 | auto trans = |
| 2974 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2975 | |
| 2976 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2977 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2978 | |
| 2979 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2980 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 2981 | TestNetLogEntry::List entries; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2982 | log.GetEntries(&entries); |
| 2983 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 2984 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 2985 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2986 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 2987 | entries, pos, |
| 2988 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2989 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2990 | |
| 2991 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2992 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2993 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2994 | ASSERT_TRUE(response->headers); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2995 | EXPECT_EQ(407, response->headers->response_code()); |
| 2996 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 2997 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 2998 | |
| 2999 | LoadTimingInfo load_timing_info; |
| 3000 | // CONNECT requests and responses are handled at the connect job level, so |
| 3001 | // the transaction does not yet have a connection. |
| 3002 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3003 | |
| 3004 | TestCompletionCallback callback2; |
| 3005 | |
| 3006 | rv = |
| 3007 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3008 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3009 | |
| 3010 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3011 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3012 | |
| 3013 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3014 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3015 | |
| 3016 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3017 | EXPECT_EQ(200, response->headers->response_code()); |
| 3018 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 3019 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3020 | |
| 3021 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3022 | EXPECT_FALSE(response->auth_challenge); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3023 | |
| 3024 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3025 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3026 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3027 | |
| 3028 | trans.reset(); |
| 3029 | session->CloseAllConnections(); |
| 3030 | } |
| 3031 | |
| 3032 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 3033 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3034 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp11) { |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3035 | HttpRequestInfo request; |
| 3036 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3037 | request.url = GURL("https://www.example.org/"); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3038 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3039 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3040 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3041 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3042 | session_deps_.proxy_service = |
| 3043 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3044 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3045 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3046 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3047 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3048 | // Since we have proxy, should try to establish tunnel. |
| 3049 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3050 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3051 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3052 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3053 | }; |
| 3054 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3055 | // The proxy responds to the connect with a 407, using a non-persistent |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3056 | // connection. |
| 3057 | MockRead data_reads1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3058 | // No credentials. |
| 3059 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3060 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3061 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3062 | }; |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3063 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3064 | MockWrite data_writes2[] = { |
| 3065 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3066 | // be issuing -- the final header line contains the credentials. |
| 3067 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3068 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3069 | "Proxy-Connection: keep-alive\r\n" |
| 3070 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3071 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3072 | MockWrite("GET / HTTP/1.1\r\n" |
| 3073 | "Host: www.example.org\r\n" |
| 3074 | "Connection: keep-alive\r\n\r\n"), |
| 3075 | }; |
| 3076 | |
| 3077 | MockRead data_reads2[] = { |
| 3078 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3079 | |
| 3080 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3081 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3082 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3083 | MockRead(SYNCHRONOUS, "hello"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3084 | }; |
| 3085 | |
| 3086 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3087 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3088 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3089 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3090 | data_writes2, arraysize(data_writes2)); |
| 3091 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3092 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3093 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3094 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3095 | TestCompletionCallback callback1; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3096 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3097 | auto trans = |
| 3098 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3099 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3100 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3101 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3102 | |
| 3103 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3104 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3105 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3106 | log.GetEntries(&entries); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3107 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3108 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3109 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3110 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3111 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3112 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3113 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3114 | |
| 3115 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3116 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3117 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3118 | ASSERT_TRUE(response->headers); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3119 | EXPECT_EQ(407, response->headers->response_code()); |
| 3120 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3121 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3122 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3123 | LoadTimingInfo load_timing_info; |
| 3124 | // CONNECT requests and responses are handled at the connect job level, so |
| 3125 | // the transaction does not yet have a connection. |
| 3126 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3127 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3128 | TestCompletionCallback callback2; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3129 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3130 | rv = trans->RestartWithAuth( |
| 3131 | AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3132 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3133 | |
| 3134 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3135 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3136 | |
| 3137 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3138 | ASSERT_TRUE(response); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3139 | |
| 3140 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3141 | EXPECT_EQ(200, response->headers->response_code()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3142 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3143 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3144 | |
| 3145 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3146 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3147 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3148 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3149 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3150 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3151 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3152 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3153 | session->CloseAllConnections(); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3154 | } |
| 3155 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3156 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3157 | // proxy connection with HTTP/1.0 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3158 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp10) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3159 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3160 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3161 | // reused. See http://crbug.com/544255. |
| 3162 | for (int i = 0; i < 2; ++i) { |
| 3163 | HttpRequestInfo request; |
| 3164 | request.method = "GET"; |
| 3165 | request.url = GURL("https://www.example.org/"); |
| 3166 | // Ensure that proxy authentication is attempted even |
| 3167 | // when the no authentication data flag is set. |
| 3168 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3169 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3170 | // Configure against proxy server "myproxy:70". |
| 3171 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
| 3172 | BoundTestNetLog log; |
| 3173 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3174 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3175 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3176 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3177 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3178 | // Since we have proxy, should try to establish tunnel. |
| 3179 | MockWrite data_writes1[] = { |
| 3180 | MockWrite(ASYNC, 0, |
| 3181 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3182 | "Host: www.example.org:443\r\n" |
| 3183 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3184 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3185 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3186 | // be issuing -- the final header line contains the credentials. |
| 3187 | MockWrite(ASYNC, 3, |
| 3188 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3189 | "Host: www.example.org:443\r\n" |
| 3190 | "Proxy-Connection: keep-alive\r\n" |
| 3191 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3192 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3193 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3194 | // The proxy responds to the connect with a 407, using a persistent |
| 3195 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3196 | MockRead data_reads1[] = { |
| 3197 | // No credentials. |
| 3198 | MockRead(ASYNC, 1, |
| 3199 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3200 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3201 | "Proxy-Connection: keep-alive\r\n" |
| 3202 | "Content-Length: 10\r\n\r\n"), |
| 3203 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3204 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3205 | // Wrong credentials (wrong password). |
| 3206 | MockRead(ASYNC, 4, |
| 3207 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3208 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3209 | "Proxy-Connection: keep-alive\r\n" |
| 3210 | "Content-Length: 10\r\n\r\n"), |
| 3211 | // No response body because the test stops reading here. |
| 3212 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3213 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3214 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3215 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3216 | arraysize(data_writes1)); |
| 3217 | data1.set_busy_before_sync_reads(true); |
| 3218 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3219 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3220 | TestCompletionCallback callback1; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3221 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3222 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3223 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3224 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3225 | TestNetLogEntry::List entries; |
| 3226 | log.GetEntries(&entries); |
| 3227 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3228 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3229 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3230 | ExpectLogContainsSomewhere( |
| 3231 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3232 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3233 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3234 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3235 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3236 | ASSERT_TRUE(response); |
| 3237 | ASSERT_TRUE(response->headers); |
| 3238 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3239 | EXPECT_EQ(407, response->headers->response_code()); |
| 3240 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3241 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3242 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3243 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3244 | TestCompletionCallback callback2; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3245 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3246 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3247 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3248 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3249 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3250 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3251 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3252 | ASSERT_TRUE(response); |
| 3253 | ASSERT_TRUE(response->headers); |
| 3254 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3255 | EXPECT_EQ(407, response->headers->response_code()); |
| 3256 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3257 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3258 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3259 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3260 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3261 | // out of scope. |
| 3262 | session->CloseAllConnections(); |
| 3263 | } |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3264 | } |
| 3265 | |
| 3266 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3267 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3268 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp11) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3269 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3270 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3271 | // reused. See http://crbug.com/544255. |
| 3272 | for (int i = 0; i < 2; ++i) { |
| 3273 | HttpRequestInfo request; |
| 3274 | request.method = "GET"; |
| 3275 | request.url = GURL("https://www.example.org/"); |
| 3276 | // Ensure that proxy authentication is attempted even |
| 3277 | // when the no authentication data flag is set. |
| 3278 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
| 3279 | |
| 3280 | // Configure against proxy server "myproxy:70". |
| 3281 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
| 3282 | BoundTestNetLog log; |
| 3283 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3284 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3285 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3286 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3287 | |
| 3288 | // Since we have proxy, should try to establish tunnel. |
| 3289 | MockWrite data_writes1[] = { |
| 3290 | MockWrite(ASYNC, 0, |
| 3291 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3292 | "Host: www.example.org:443\r\n" |
| 3293 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3294 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3295 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3296 | // be issuing -- the final header line contains the credentials. |
| 3297 | MockWrite(ASYNC, 3, |
| 3298 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3299 | "Host: www.example.org:443\r\n" |
| 3300 | "Proxy-Connection: keep-alive\r\n" |
| 3301 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3302 | }; |
| 3303 | |
| 3304 | // The proxy responds to the connect with a 407, using a persistent |
| 3305 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3306 | MockRead data_reads1[] = { |
| 3307 | // No credentials. |
| 3308 | MockRead(ASYNC, 1, |
| 3309 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3310 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3311 | "Content-Length: 10\r\n\r\n"), |
| 3312 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
| 3313 | |
| 3314 | // Wrong credentials (wrong password). |
| 3315 | MockRead(ASYNC, 4, |
| 3316 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3317 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3318 | "Content-Length: 10\r\n\r\n"), |
| 3319 | // No response body because the test stops reading here. |
| 3320 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3321 | }; |
| 3322 | |
| 3323 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3324 | arraysize(data_writes1)); |
| 3325 | data1.set_busy_before_sync_reads(true); |
| 3326 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3327 | |
| 3328 | TestCompletionCallback callback1; |
| 3329 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3330 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3331 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3332 | |
| 3333 | TestNetLogEntry::List entries; |
| 3334 | log.GetEntries(&entries); |
| 3335 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3336 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3337 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3338 | ExpectLogContainsSomewhere( |
| 3339 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3340 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3341 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3342 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3343 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3344 | ASSERT_TRUE(response); |
| 3345 | ASSERT_TRUE(response->headers); |
| 3346 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3347 | EXPECT_EQ(407, response->headers->response_code()); |
| 3348 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3349 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3350 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3351 | |
| 3352 | TestCompletionCallback callback2; |
| 3353 | |
| 3354 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3355 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3356 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3357 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3358 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3359 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3360 | ASSERT_TRUE(response); |
| 3361 | ASSERT_TRUE(response->headers); |
| 3362 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3363 | EXPECT_EQ(407, response->headers->response_code()); |
| 3364 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3365 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3366 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3367 | |
| 3368 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3369 | // out of scope. |
| 3370 | session->CloseAllConnections(); |
| 3371 | } |
| 3372 | } |
| 3373 | |
| 3374 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3375 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel, in |
| 3376 | // the case the server sends extra data on the original socket, so it can't be |
| 3377 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3378 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveExtraData) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3379 | HttpRequestInfo request; |
| 3380 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3381 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3382 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3383 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3384 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3385 | // Configure against proxy server "myproxy:70". |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3386 | session_deps_.proxy_service = |
| 3387 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3388 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3389 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3390 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3391 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3392 | // Since we have proxy, should try to establish tunnel. |
| 3393 | MockWrite data_writes1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3394 | MockWrite(ASYNC, 0, |
| 3395 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3396 | "Host: www.example.org:443\r\n" |
| 3397 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3398 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3399 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3400 | // The proxy responds to the connect with a 407, using a persistent, but sends |
| 3401 | // extra data, so the socket cannot be reused. |
| 3402 | MockRead data_reads1[] = { |
| 3403 | // No credentials. |
| 3404 | MockRead(ASYNC, 1, |
| 3405 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3406 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3407 | "Content-Length: 10\r\n\r\n"), |
| 3408 | MockRead(SYNCHRONOUS, 2, "0123456789"), |
| 3409 | MockRead(SYNCHRONOUS, 3, "I'm broken!"), |
| 3410 | }; |
| 3411 | |
| 3412 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3413 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3414 | // be issuing -- the final header line contains the credentials. |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3415 | MockWrite(ASYNC, 0, |
| 3416 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3417 | "Host: www.example.org:443\r\n" |
| 3418 | "Proxy-Connection: keep-alive\r\n" |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3419 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3420 | |
| 3421 | MockWrite(ASYNC, 2, |
| 3422 | "GET / HTTP/1.1\r\n" |
| 3423 | "Host: www.example.org\r\n" |
| 3424 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3425 | }; |
| 3426 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3427 | MockRead data_reads2[] = { |
| 3428 | MockRead(ASYNC, 1, "HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3429 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3430 | MockRead(ASYNC, 3, |
| 3431 | "HTTP/1.1 200 OK\r\n" |
| 3432 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 3433 | "Content-Length: 5\r\n\r\n"), |
| 3434 | // No response body because the test stops reading here. |
| 3435 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 4), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3436 | }; |
| 3437 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3438 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3439 | arraysize(data_writes1)); |
| 3440 | data1.set_busy_before_sync_reads(true); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3441 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3442 | SequencedSocketData data2(data_reads2, arraysize(data_reads2), data_writes2, |
| 3443 | arraysize(data_writes2)); |
| 3444 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3445 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3446 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3447 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3448 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3449 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3450 | auto trans = |
| 3451 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3452 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3453 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3454 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3455 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3456 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3457 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3458 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3459 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3460 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3461 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3462 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3463 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3464 | NetLogEventPhase::NONE); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3465 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3466 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3467 | ASSERT_TRUE(response); |
| 3468 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3469 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3470 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3471 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3472 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3473 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3474 | LoadTimingInfo load_timing_info; |
| 3475 | // CONNECT requests and responses are handled at the connect job level, so |
| 3476 | // the transaction does not yet have a connection. |
| 3477 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3478 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3479 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3480 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3481 | rv = |
| 3482 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3483 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3484 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3485 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3486 | EXPECT_EQ(200, response->headers->response_code()); |
| 3487 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3488 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 3489 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3490 | // The password prompt info should not be set. |
| 3491 | EXPECT_FALSE(response->auth_challenge); |
| 3492 | |
| 3493 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3494 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3495 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3496 | |
| 3497 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3498 | session->CloseAllConnections(); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3499 | } |
| 3500 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3501 | // Test the case a proxy closes a socket while the challenge body is being |
| 3502 | // drained. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3503 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHangupDuringBody) { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3504 | HttpRequestInfo request; |
| 3505 | request.method = "GET"; |
| 3506 | request.url = GURL("https://www.example.org/"); |
| 3507 | // Ensure that proxy authentication is attempted even |
| 3508 | // when the no authentication data flag is set. |
| 3509 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
| 3510 | |
| 3511 | // Configure against proxy server "myproxy:70". |
| 3512 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3513 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3514 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3515 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3516 | |
| 3517 | // Since we have proxy, should try to establish tunnel. |
| 3518 | MockWrite data_writes1[] = { |
| 3519 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3520 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3521 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3522 | }; |
| 3523 | |
| 3524 | // The proxy responds to the connect with a 407, using a persistent |
| 3525 | // connection. |
| 3526 | MockRead data_reads1[] = { |
| 3527 | // No credentials. |
| 3528 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3529 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3530 | MockRead("Content-Length: 10\r\n\r\n"), MockRead("spam!"), |
| 3531 | // Server hands up in the middle of the body. |
| 3532 | MockRead(ASYNC, ERR_CONNECTION_CLOSED), |
| 3533 | }; |
| 3534 | |
| 3535 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3536 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3537 | // be issuing -- the final header line contains the credentials. |
| 3538 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3539 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3540 | "Proxy-Connection: keep-alive\r\n" |
| 3541 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3542 | |
| 3543 | MockWrite("GET / HTTP/1.1\r\n" |
| 3544 | "Host: www.example.org\r\n" |
| 3545 | "Connection: keep-alive\r\n\r\n"), |
| 3546 | }; |
| 3547 | |
| 3548 | MockRead data_reads2[] = { |
| 3549 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3550 | |
| 3551 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3552 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3553 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3554 | MockRead(SYNCHRONOUS, "hello"), |
| 3555 | }; |
| 3556 | |
| 3557 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3558 | data_writes1, arraysize(data_writes1)); |
| 3559 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3560 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3561 | data_writes2, arraysize(data_writes2)); |
| 3562 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3563 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3564 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3565 | |
| 3566 | TestCompletionCallback callback; |
| 3567 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3568 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3569 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3570 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3571 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3572 | ASSERT_TRUE(response); |
| 3573 | ASSERT_TRUE(response->headers); |
| 3574 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3575 | EXPECT_EQ(407, response->headers->response_code()); |
| 3576 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3577 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3578 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3579 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3580 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3581 | response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3582 | ASSERT_TRUE(response); |
| 3583 | ASSERT_TRUE(response->headers); |
| 3584 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3585 | EXPECT_EQ(200, response->headers->response_code()); |
| 3586 | std::string body; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3587 | EXPECT_THAT(ReadTransaction(&trans, &body), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3588 | EXPECT_EQ("hello", body); |
| 3589 | } |
| 3590 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3591 | // Test that we don't read the response body when we fail to establish a tunnel, |
| 3592 | // even if the user cancels the proxy's auth attempt. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3593 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3594 | HttpRequestInfo request; |
| 3595 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3596 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3597 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3598 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3599 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3600 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3601 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3602 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3603 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3604 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3605 | // Since we have proxy, should try to establish tunnel. |
| 3606 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3607 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3608 | "Host: www.example.org:443\r\n" |
| 3609 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3610 | }; |
| 3611 | |
| 3612 | // The proxy responds to the connect with a 407. |
| 3613 | MockRead data_reads[] = { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3614 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3615 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3616 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3617 | MockRead("0123456789"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3618 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3619 | }; |
| 3620 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 3621 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 3622 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3623 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3624 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3625 | TestCompletionCallback callback; |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3626 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3627 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3628 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3629 | |
| 3630 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3631 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3632 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3633 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3634 | ASSERT_TRUE(response); |
| 3635 | ASSERT_TRUE(response->headers); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3636 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3637 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3638 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3639 | |
| 3640 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3641 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3642 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 3643 | |
| 3644 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3645 | session->CloseAllConnections(); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3646 | } |
| 3647 | |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3648 | // Test that we don't pass extraneous headers from the proxy's response to the |
| 3649 | // caller when the proxy responds to CONNECT with 407. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3650 | TEST_F(HttpNetworkTransactionTest, SanitizeProxyAuthHeaders) { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3651 | HttpRequestInfo request; |
| 3652 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3653 | request.url = GURL("https://www.example.org/"); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3654 | |
| 3655 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3656 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3657 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3658 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3659 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3660 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3661 | |
| 3662 | // Since we have proxy, should try to establish tunnel. |
| 3663 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3664 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3665 | "Host: www.example.org:443\r\n" |
| 3666 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3667 | }; |
| 3668 | |
| 3669 | // The proxy responds to the connect with a 407. |
| 3670 | MockRead data_reads[] = { |
| 3671 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3672 | MockRead("X-Foo: bar\r\n"), |
| 3673 | MockRead("Set-Cookie: foo=bar\r\n"), |
| 3674 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3675 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3676 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3677 | }; |
| 3678 | |
| 3679 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 3680 | arraysize(data_writes)); |
| 3681 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 3682 | |
| 3683 | TestCompletionCallback callback; |
| 3684 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3685 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3686 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3687 | |
| 3688 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3689 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3690 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3691 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3692 | ASSERT_TRUE(response); |
| 3693 | ASSERT_TRUE(response->headers); |
| 3694 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3695 | EXPECT_EQ(407, response->headers->response_code()); |
| 3696 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3697 | EXPECT_FALSE(response->headers->HasHeader("X-Foo")); |
| 3698 | EXPECT_FALSE(response->headers->HasHeader("Set-Cookie")); |
| 3699 | |
| 3700 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3701 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3702 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3703 | |
| 3704 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
| 3705 | session->CloseAllConnections(); |
| 3706 | } |
| 3707 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3708 | // Test when a server (non-proxy) returns a 407 (proxy-authenticate). |
| 3709 | // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3710 | TEST_F(HttpNetworkTransactionTest, UnexpectedProxyAuth) { |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3711 | HttpRequestInfo request; |
| 3712 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3713 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3714 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3715 | // We are using a DIRECT connection (i.e. no proxy) for this session. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3716 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3717 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3718 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3719 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3720 | MockWrite( |
| 3721 | "GET / HTTP/1.1\r\n" |
| 3722 | "Host: www.example.org\r\n" |
| 3723 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3724 | }; |
| 3725 | |
| 3726 | MockRead data_reads1[] = { |
| 3727 | MockRead("HTTP/1.0 407 Proxy Auth required\r\n"), |
| 3728 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3729 | // Large content-length -- won't matter, as connection will be reset. |
| 3730 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3731 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3732 | }; |
| 3733 | |
| 3734 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3735 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3736 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3737 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3738 | TestCompletionCallback callback; |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3739 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3740 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3741 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3742 | |
| 3743 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3744 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3745 | } |
| 3746 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3747 | // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) |
| 3748 | // through a non-authenticating proxy. The request should fail with |
| 3749 | // ERR_UNEXPECTED_PROXY_AUTH. |
| 3750 | // Note that it is impossible to detect if an HTTP server returns a 407 through |
| 3751 | // a non-authenticating proxy - there is nothing to indicate whether the |
| 3752 | // response came from the proxy or the server, so it is treated as if the proxy |
| 3753 | // issued the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3754 | TEST_F(HttpNetworkTransactionTest, HttpsServerRequestsProxyAuthThroughProxy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3755 | HttpRequestInfo request; |
| 3756 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3757 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3758 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3759 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3760 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3761 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3762 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3763 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3764 | // Since we have proxy, should try to establish tunnel. |
| 3765 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3766 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3767 | "Host: www.example.org:443\r\n" |
| 3768 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3769 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3770 | MockWrite("GET / HTTP/1.1\r\n" |
| 3771 | "Host: www.example.org\r\n" |
| 3772 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3773 | }; |
| 3774 | |
| 3775 | MockRead data_reads1[] = { |
| 3776 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3777 | |
| 3778 | MockRead("HTTP/1.1 407 Unauthorized\r\n"), |
| 3779 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3780 | MockRead("\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3781 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3782 | }; |
| 3783 | |
| 3784 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3785 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3786 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3787 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3788 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3789 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3790 | TestCompletionCallback callback1; |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3791 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3792 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3793 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3794 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3795 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3796 | |
| 3797 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3798 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3799 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3800 | log.GetEntries(&entries); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3801 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3802 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3803 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3804 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3805 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3806 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3807 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3808 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3809 | |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3810 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 3811 | // that uses non-persistent connections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3812 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3813 | AuthAllowsDefaultCredentialsTunnelConnectionClose) { |
| 3814 | HttpRequestInfo request; |
| 3815 | request.method = "GET"; |
| 3816 | request.url = GURL("https://www.example.org/"); |
| 3817 | |
| 3818 | // Configure against proxy server "myproxy:70". |
| 3819 | session_deps_.proxy_service = |
| 3820 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 3821 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3822 | auto auth_handler_factory = base::MakeUnique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3823 | auth_handler_factory->set_do_init_from_challenge(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3824 | auto mock_handler = base::MakeUnique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3825 | mock_handler->set_allows_default_credentials(true); |
| 3826 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3827 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 3828 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3829 | |
| 3830 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 3831 | NetLog net_log; |
| 3832 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3833 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3834 | |
| 3835 | // Since we have proxy, should try to establish tunnel. |
| 3836 | MockWrite data_writes1[] = { |
| 3837 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3838 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3839 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3840 | }; |
| 3841 | |
| 3842 | // The proxy responds to the connect with a 407, using a non-persistent |
| 3843 | // connection. |
| 3844 | MockRead data_reads1[] = { |
| 3845 | // No credentials. |
| 3846 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3847 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 3848 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3849 | }; |
| 3850 | |
| 3851 | // Since the first connection couldn't be reused, need to establish another |
| 3852 | // once given credentials. |
| 3853 | MockWrite data_writes2[] = { |
| 3854 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3855 | // be issuing -- the final header line contains the credentials. |
| 3856 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3857 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3858 | "Proxy-Connection: keep-alive\r\n" |
| 3859 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3860 | |
| 3861 | MockWrite("GET / HTTP/1.1\r\n" |
| 3862 | "Host: www.example.org\r\n" |
| 3863 | "Connection: keep-alive\r\n\r\n"), |
| 3864 | }; |
| 3865 | |
| 3866 | MockRead data_reads2[] = { |
| 3867 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3868 | |
| 3869 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3870 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3871 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3872 | MockRead(SYNCHRONOUS, "hello"), |
| 3873 | }; |
| 3874 | |
| 3875 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3876 | data_writes1, arraysize(data_writes1)); |
| 3877 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3878 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3879 | data_writes2, arraysize(data_writes2)); |
| 3880 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3881 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3882 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3883 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3884 | auto trans = |
| 3885 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3886 | |
| 3887 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3888 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3889 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3890 | |
| 3891 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3892 | ASSERT_TRUE(response); |
| 3893 | ASSERT_TRUE(response->headers); |
| 3894 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
| 3895 | EXPECT_EQ(407, response->headers->response_code()); |
| 3896 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3897 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3898 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3899 | |
| 3900 | LoadTimingInfo load_timing_info; |
| 3901 | // CONNECT requests and responses are handled at the connect job level, so |
| 3902 | // the transaction does not yet have a connection. |
| 3903 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3904 | |
| 3905 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3906 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3907 | response = trans->GetResponseInfo(); |
| 3908 | ASSERT_TRUE(response); |
| 3909 | ASSERT_TRUE(response->headers); |
| 3910 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3911 | EXPECT_EQ(200, response->headers->response_code()); |
| 3912 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 3913 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3914 | |
| 3915 | // The password prompt info should not be set. |
| 3916 | EXPECT_FALSE(response->auth_challenge); |
| 3917 | |
| 3918 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3919 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3920 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3921 | |
| 3922 | trans.reset(); |
| 3923 | session->CloseAllConnections(); |
| 3924 | } |
| 3925 | |
| 3926 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 3927 | // that hangs up when credentials are initially sent. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3928 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3929 | AuthAllowsDefaultCredentialsTunnelServerClosesConnection) { |
| 3930 | HttpRequestInfo request; |
| 3931 | request.method = "GET"; |
| 3932 | request.url = GURL("https://www.example.org/"); |
| 3933 | |
| 3934 | // Configure against proxy server "myproxy:70". |
| 3935 | session_deps_.proxy_service = |
| 3936 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 3937 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3938 | auto auth_handler_factory = base::MakeUnique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3939 | auth_handler_factory->set_do_init_from_challenge(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3940 | auto mock_handler = base::MakeUnique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3941 | mock_handler->set_allows_default_credentials(true); |
| 3942 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3943 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 3944 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3945 | |
| 3946 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 3947 | NetLog net_log; |
| 3948 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3949 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3950 | |
| 3951 | // Should try to establish tunnel. |
| 3952 | MockWrite data_writes1[] = { |
| 3953 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3954 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3955 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3956 | |
| 3957 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3958 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3959 | "Proxy-Connection: keep-alive\r\n" |
| 3960 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3961 | }; |
| 3962 | |
| 3963 | // The proxy responds to the connect with a 407, using a non-persistent |
| 3964 | // connection. |
| 3965 | MockRead data_reads1[] = { |
| 3966 | // No credentials. |
| 3967 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3968 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 3969 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 3970 | }; |
| 3971 | |
| 3972 | // Since the first connection was closed, need to establish another once given |
| 3973 | // credentials. |
| 3974 | MockWrite data_writes2[] = { |
| 3975 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3976 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3977 | "Proxy-Connection: keep-alive\r\n" |
| 3978 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3979 | |
| 3980 | MockWrite("GET / HTTP/1.1\r\n" |
| 3981 | "Host: www.example.org\r\n" |
| 3982 | "Connection: keep-alive\r\n\r\n"), |
| 3983 | }; |
| 3984 | |
| 3985 | MockRead data_reads2[] = { |
| 3986 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3987 | |
| 3988 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3989 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3990 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3991 | MockRead(SYNCHRONOUS, "hello"), |
| 3992 | }; |
| 3993 | |
| 3994 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3995 | data_writes1, arraysize(data_writes1)); |
| 3996 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3997 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3998 | data_writes2, arraysize(data_writes2)); |
| 3999 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4000 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4001 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4002 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4003 | auto trans = |
| 4004 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4005 | |
| 4006 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4007 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4008 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4009 | |
| 4010 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4011 | ASSERT_TRUE(response); |
| 4012 | ASSERT_TRUE(response->headers); |
| 4013 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4014 | EXPECT_EQ(407, response->headers->response_code()); |
| 4015 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4016 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4017 | EXPECT_FALSE(response->auth_challenge); |
| 4018 | |
| 4019 | LoadTimingInfo load_timing_info; |
| 4020 | // CONNECT requests and responses are handled at the connect job level, so |
| 4021 | // the transaction does not yet have a connection. |
| 4022 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4023 | |
| 4024 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4025 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4026 | |
| 4027 | response = trans->GetResponseInfo(); |
| 4028 | ASSERT_TRUE(response); |
| 4029 | ASSERT_TRUE(response->headers); |
| 4030 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4031 | EXPECT_EQ(200, response->headers->response_code()); |
| 4032 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 4033 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4034 | |
| 4035 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4036 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4037 | |
| 4038 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4039 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4040 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4041 | |
| 4042 | trans.reset(); |
| 4043 | session->CloseAllConnections(); |
| 4044 | } |
| 4045 | |
| 4046 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4047 | // that hangs up when credentials are initially sent, and hangs up again when |
| 4048 | // they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4049 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4050 | AuthAllowsDefaultCredentialsTunnelServerClosesConnectionTwice) { |
| 4051 | HttpRequestInfo request; |
| 4052 | request.method = "GET"; |
| 4053 | request.url = GURL("https://www.example.org/"); |
| 4054 | |
| 4055 | // Configure against proxy server "myproxy:70". |
| 4056 | session_deps_.proxy_service = |
| 4057 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 4058 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4059 | auto auth_handler_factory = base::MakeUnique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4060 | auth_handler_factory->set_do_init_from_challenge(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4061 | auto mock_handler = base::MakeUnique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4062 | mock_handler->set_allows_default_credentials(true); |
| 4063 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4064 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4065 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4066 | |
| 4067 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4068 | NetLog net_log; |
| 4069 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4070 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4071 | |
| 4072 | // Should try to establish tunnel. |
| 4073 | MockWrite data_writes1[] = { |
| 4074 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4075 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4076 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4077 | |
| 4078 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4079 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4080 | "Proxy-Connection: keep-alive\r\n" |
| 4081 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4082 | }; |
| 4083 | |
| 4084 | // The proxy responds to the connect with a 407, and then hangs up after the |
| 4085 | // second request is sent. |
| 4086 | MockRead data_reads1[] = { |
| 4087 | // No credentials. |
| 4088 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4089 | MockRead("Content-Length: 0\r\n"), |
| 4090 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4091 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4092 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4093 | }; |
| 4094 | |
| 4095 | // HttpNetworkTransaction sees a reused connection that was closed with |
| 4096 | // ERR_CONNECTION_CLOSED, realized it might have been a race, so retries the |
| 4097 | // request. |
| 4098 | MockWrite data_writes2[] = { |
| 4099 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4100 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4101 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4102 | }; |
| 4103 | |
| 4104 | // The proxy, having had more than enough of us, just hangs up. |
| 4105 | MockRead data_reads2[] = { |
| 4106 | // No credentials. |
| 4107 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4108 | }; |
| 4109 | |
| 4110 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4111 | data_writes1, arraysize(data_writes1)); |
| 4112 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4113 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4114 | data_writes2, arraysize(data_writes2)); |
| 4115 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4116 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4117 | auto trans = |
| 4118 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4119 | |
| 4120 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4121 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4122 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4123 | |
| 4124 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4125 | ASSERT_TRUE(response); |
| 4126 | ASSERT_TRUE(response->headers); |
| 4127 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4128 | EXPECT_EQ(407, response->headers->response_code()); |
| 4129 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4130 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4131 | EXPECT_FALSE(response->auth_challenge); |
| 4132 | |
| 4133 | LoadTimingInfo load_timing_info; |
| 4134 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4135 | |
| 4136 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4137 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4138 | |
| 4139 | trans.reset(); |
| 4140 | session->CloseAllConnections(); |
| 4141 | } |
| 4142 | |
| 4143 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4144 | // that hangs up when credentials are initially sent, and sends a challenge |
| 4145 | // again they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4146 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4147 | AuthAllowsDefaultCredentialsTunnelServerChallengesTwice) { |
| 4148 | HttpRequestInfo request; |
| 4149 | request.method = "GET"; |
| 4150 | request.url = GURL("https://www.example.org/"); |
| 4151 | |
| 4152 | // Configure against proxy server "myproxy:70". |
| 4153 | session_deps_.proxy_service = |
| 4154 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 4155 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4156 | auto auth_handler_factory = base::MakeUnique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4157 | auth_handler_factory->set_do_init_from_challenge(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4158 | auto mock_handler = base::MakeUnique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4159 | mock_handler->set_allows_default_credentials(true); |
| 4160 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4161 | HttpAuth::AUTH_PROXY); |
| 4162 | // Add another handler for the second challenge. It supports default |
| 4163 | // credentials, but they shouldn't be used, since they were already tried. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4164 | mock_handler = base::MakeUnique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4165 | mock_handler->set_allows_default_credentials(true); |
| 4166 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4167 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4168 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4169 | |
| 4170 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4171 | NetLog net_log; |
| 4172 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4173 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4174 | |
| 4175 | // Should try to establish tunnel. |
| 4176 | MockWrite data_writes1[] = { |
| 4177 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4178 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4179 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4180 | }; |
| 4181 | |
| 4182 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4183 | // connection. |
| 4184 | MockRead data_reads1[] = { |
| 4185 | // No credentials. |
| 4186 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4187 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4188 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4189 | }; |
| 4190 | |
| 4191 | // Since the first connection was closed, need to establish another once given |
| 4192 | // credentials. |
| 4193 | MockWrite data_writes2[] = { |
| 4194 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4195 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4196 | "Proxy-Connection: keep-alive\r\n" |
| 4197 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4198 | }; |
| 4199 | |
| 4200 | MockRead data_reads2[] = { |
| 4201 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4202 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4203 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4204 | }; |
| 4205 | |
| 4206 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4207 | data_writes1, arraysize(data_writes1)); |
| 4208 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4209 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4210 | data_writes2, arraysize(data_writes2)); |
| 4211 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4212 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4213 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4214 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4215 | auto trans = |
| 4216 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4217 | |
| 4218 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4219 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4220 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4221 | |
| 4222 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4223 | ASSERT_TRUE(response); |
| 4224 | ASSERT_TRUE(response->headers); |
| 4225 | EXPECT_EQ(407, response->headers->response_code()); |
| 4226 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4227 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4228 | EXPECT_FALSE(response->auth_challenge); |
| 4229 | |
| 4230 | LoadTimingInfo load_timing_info; |
| 4231 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4232 | |
| 4233 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4234 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4235 | response = trans->GetResponseInfo(); |
| 4236 | ASSERT_TRUE(response); |
| 4237 | ASSERT_TRUE(response->headers); |
| 4238 | EXPECT_EQ(407, response->headers->response_code()); |
| 4239 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4240 | EXPECT_TRUE(response->auth_challenge); |
| 4241 | |
| 4242 | trans.reset(); |
| 4243 | session->CloseAllConnections(); |
| 4244 | } |
| 4245 | |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4246 | // A more nuanced test than GenerateAuthToken test which asserts that |
| 4247 | // ERR_INVALID_AUTH_CREDENTIALS does not cause the auth scheme to be |
| 4248 | // unnecessarily invalidated, and that if the server co-operates, the |
| 4249 | // authentication handshake can continue with the same scheme but with a |
| 4250 | // different identity. |
| 4251 | TEST_F(HttpNetworkTransactionTest, NonPermanentGenerateAuthTokenError) { |
| 4252 | HttpRequestInfo request; |
| 4253 | request.method = "GET"; |
| 4254 | request.url = GURL("http://www.example.org/"); |
| 4255 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4256 | auto auth_handler_factory = base::MakeUnique<HttpAuthHandlerMock::Factory>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4257 | auth_handler_factory->set_do_init_from_challenge(true); |
| 4258 | |
| 4259 | // First handler. Uses default credentials, but barfs at generate auth token. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4260 | auto mock_handler = base::MakeUnique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4261 | mock_handler->set_allows_default_credentials(true); |
| 4262 | mock_handler->set_allows_explicit_credentials(true); |
| 4263 | mock_handler->set_connection_based(true); |
| 4264 | mock_handler->SetGenerateExpectation(true, ERR_INVALID_AUTH_CREDENTIALS); |
| 4265 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4266 | HttpAuth::AUTH_SERVER); |
| 4267 | |
| 4268 | // Add another handler for the second challenge. It supports default |
| 4269 | // credentials, but they shouldn't be used, since they were already tried. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4270 | mock_handler = base::MakeUnique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4271 | mock_handler->set_allows_default_credentials(true); |
| 4272 | mock_handler->set_allows_explicit_credentials(true); |
| 4273 | mock_handler->set_connection_based(true); |
| 4274 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4275 | HttpAuth::AUTH_SERVER); |
| 4276 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
| 4277 | |
| 4278 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4279 | |
| 4280 | MockWrite data_writes1[] = { |
| 4281 | MockWrite("GET / HTTP/1.1\r\n" |
| 4282 | "Host: www.example.org\r\n" |
| 4283 | "Connection: keep-alive\r\n\r\n"), |
| 4284 | }; |
| 4285 | |
| 4286 | MockRead data_reads1[] = { |
| 4287 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4288 | "WWW-Authenticate: Mock\r\n" |
| 4289 | "Connection: keep-alive\r\n\r\n"), |
| 4290 | }; |
| 4291 | |
| 4292 | // Identical to data_writes1[]. The AuthHandler encounters a |
| 4293 | // ERR_INVALID_AUTH_CREDENTIALS during the GenerateAuthToken stage, so the |
| 4294 | // transaction procceds without an authorization header. |
| 4295 | MockWrite data_writes2[] = { |
| 4296 | MockWrite("GET / HTTP/1.1\r\n" |
| 4297 | "Host: www.example.org\r\n" |
| 4298 | "Connection: keep-alive\r\n\r\n"), |
| 4299 | }; |
| 4300 | |
| 4301 | MockRead data_reads2[] = { |
| 4302 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4303 | "WWW-Authenticate: Mock\r\n" |
| 4304 | "Connection: keep-alive\r\n\r\n"), |
| 4305 | }; |
| 4306 | |
| 4307 | MockWrite data_writes3[] = { |
| 4308 | MockWrite("GET / HTTP/1.1\r\n" |
| 4309 | "Host: www.example.org\r\n" |
| 4310 | "Connection: keep-alive\r\n" |
| 4311 | "Authorization: auth_token\r\n\r\n"), |
| 4312 | }; |
| 4313 | |
| 4314 | MockRead data_reads3[] = { |
| 4315 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4316 | "Content-Length: 5\r\n" |
| 4317 | "Content-Type: text/plain\r\n" |
| 4318 | "Connection: keep-alive\r\n\r\n" |
| 4319 | "Hello"), |
| 4320 | }; |
| 4321 | |
| 4322 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4323 | data_writes1, arraysize(data_writes1)); |
| 4324 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4325 | |
| 4326 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4327 | data_writes2, arraysize(data_writes2)); |
| 4328 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4329 | |
| 4330 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 4331 | data_writes3, arraysize(data_writes3)); |
| 4332 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 4333 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4334 | auto trans = |
| 4335 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4336 | |
| 4337 | TestCompletionCallback callback; |
| 4338 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 4339 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4340 | |
| 4341 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4342 | ASSERT_TRUE(response); |
| 4343 | ASSERT_TRUE(response->headers); |
| 4344 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4345 | |
| 4346 | // The following three tests assert that an authentication challenge was |
| 4347 | // received and that the stack is ready to respond to the challenge using |
| 4348 | // ambient credentials. |
| 4349 | EXPECT_EQ(401, response->headers->response_code()); |
| 4350 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4351 | EXPECT_FALSE(response->auth_challenge); |
| 4352 | |
| 4353 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4354 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4355 | response = trans->GetResponseInfo(); |
| 4356 | ASSERT_TRUE(response); |
| 4357 | ASSERT_TRUE(response->headers); |
| 4358 | |
| 4359 | // The following three tests assert that an authentication challenge was |
| 4360 | // received and that the stack needs explicit credentials before it is ready |
| 4361 | // to respond to the challenge. |
| 4362 | EXPECT_EQ(401, response->headers->response_code()); |
| 4363 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4364 | EXPECT_TRUE(response->auth_challenge); |
| 4365 | |
| 4366 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4367 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4368 | response = trans->GetResponseInfo(); |
| 4369 | ASSERT_TRUE(response); |
| 4370 | ASSERT_TRUE(response->headers); |
| 4371 | EXPECT_EQ(200, response->headers->response_code()); |
| 4372 | |
| 4373 | trans.reset(); |
| 4374 | session->CloseAllConnections(); |
| 4375 | } |
| 4376 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4377 | // Test the load timing for HTTPS requests with an HTTP proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4378 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingNoPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4379 | HttpRequestInfo request1; |
| 4380 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4381 | request1.url = GURL("https://www.example.org/1"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4382 | |
| 4383 | HttpRequestInfo request2; |
| 4384 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4385 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4386 | |
| 4387 | // Configure against proxy server "myproxy:70". |
brettw | c1213d9 | 2016-11-12 03:41:13 | [diff] [blame] | 4388 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4389 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4390 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4391 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4392 | |
| 4393 | // Since we have proxy, should try to establish tunnel. |
| 4394 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4395 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4396 | "Host: www.example.org:443\r\n" |
| 4397 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4398 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4399 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 4400 | "Host: www.example.org\r\n" |
| 4401 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4402 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4403 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 4404 | "Host: www.example.org\r\n" |
| 4405 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4406 | }; |
| 4407 | |
| 4408 | // The proxy responds to the connect with a 407, using a persistent |
| 4409 | // connection. |
| 4410 | MockRead data_reads1[] = { |
| 4411 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4412 | |
| 4413 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4414 | MockRead("Content-Length: 1\r\n\r\n"), |
| 4415 | MockRead(SYNCHRONOUS, "1"), |
| 4416 | |
| 4417 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4418 | MockRead("Content-Length: 2\r\n\r\n"), |
| 4419 | MockRead(SYNCHRONOUS, "22"), |
| 4420 | }; |
| 4421 | |
| 4422 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4423 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4424 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4425 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4426 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4427 | |
| 4428 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4429 | auto trans1 = |
| 4430 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4431 | |
| 4432 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4433 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4434 | |
| 4435 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4436 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4437 | |
| 4438 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4439 | ASSERT_TRUE(response1); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4440 | EXPECT_TRUE(response1->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4441 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4442 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 4443 | |
| 4444 | LoadTimingInfo load_timing_info1; |
| 4445 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 4446 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4447 | |
| 4448 | trans1.reset(); |
| 4449 | |
| 4450 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4451 | auto trans2 = |
| 4452 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4453 | |
| 4454 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4455 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4456 | |
| 4457 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4458 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4459 | |
| 4460 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4461 | ASSERT_TRUE(response2); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4462 | EXPECT_TRUE(response2->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4463 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4464 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 4465 | |
| 4466 | LoadTimingInfo load_timing_info2; |
| 4467 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4468 | TestLoadTimingReused(load_timing_info2); |
| 4469 | |
| 4470 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 4471 | |
| 4472 | trans2.reset(); |
| 4473 | session->CloseAllConnections(); |
| 4474 | } |
| 4475 | |
| 4476 | // 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] | 4477 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingWithPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4478 | HttpRequestInfo request1; |
| 4479 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4480 | request1.url = GURL("https://www.example.org/1"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4481 | |
| 4482 | HttpRequestInfo request2; |
| 4483 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4484 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4485 | |
| 4486 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4487 | session_deps_.proxy_service = |
| 4488 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4489 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4490 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4491 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4492 | |
| 4493 | // Since we have proxy, should try to establish tunnel. |
| 4494 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4495 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4496 | "Host: www.example.org:443\r\n" |
| 4497 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4498 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4499 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 4500 | "Host: www.example.org\r\n" |
| 4501 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4502 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4503 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 4504 | "Host: www.example.org\r\n" |
| 4505 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4506 | }; |
| 4507 | |
| 4508 | // The proxy responds to the connect with a 407, using a persistent |
| 4509 | // connection. |
| 4510 | MockRead data_reads1[] = { |
| 4511 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4512 | |
| 4513 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4514 | MockRead("Content-Length: 1\r\n\r\n"), |
| 4515 | MockRead(SYNCHRONOUS, "1"), |
| 4516 | |
| 4517 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4518 | MockRead("Content-Length: 2\r\n\r\n"), |
| 4519 | MockRead(SYNCHRONOUS, "22"), |
| 4520 | }; |
| 4521 | |
| 4522 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4523 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4524 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4525 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4526 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4527 | |
| 4528 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4529 | auto trans1 = |
| 4530 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4531 | |
| 4532 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4533 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4534 | |
| 4535 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4536 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4537 | |
| 4538 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4539 | ASSERT_TRUE(response1); |
| 4540 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4541 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 4542 | |
| 4543 | LoadTimingInfo load_timing_info1; |
| 4544 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 4545 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 4546 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4547 | |
| 4548 | trans1.reset(); |
| 4549 | |
| 4550 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4551 | auto trans2 = |
| 4552 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4553 | |
| 4554 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4555 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4556 | |
| 4557 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4558 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4559 | |
| 4560 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4561 | ASSERT_TRUE(response2); |
| 4562 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4563 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 4564 | |
| 4565 | LoadTimingInfo load_timing_info2; |
| 4566 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4567 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 4568 | |
| 4569 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 4570 | |
| 4571 | trans2.reset(); |
| 4572 | session->CloseAllConnections(); |
| 4573 | } |
| 4574 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4575 | // Test a simple get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4576 | TEST_F(HttpNetworkTransactionTest, HttpsProxyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4577 | HttpRequestInfo request; |
| 4578 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4579 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4580 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4581 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4582 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4583 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4584 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4585 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4586 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4587 | // Since we have proxy, should use full url |
| 4588 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4589 | MockWrite( |
| 4590 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 4591 | "Host: www.example.org\r\n" |
| 4592 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4593 | }; |
| 4594 | |
| 4595 | MockRead data_reads1[] = { |
| 4596 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4597 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4598 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4599 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4600 | }; |
| 4601 | |
| 4602 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4603 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4604 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4605 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4606 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4607 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4608 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4609 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4610 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4611 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4612 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4613 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4614 | |
| 4615 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4616 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4617 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4618 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4619 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4620 | TestLoadTimingNotReused(load_timing_info, |
| 4621 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4622 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4623 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4624 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4625 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4626 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4627 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4628 | EXPECT_EQ(200, response->headers->response_code()); |
| 4629 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 4630 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4631 | |
| 4632 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4633 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4634 | } |
| 4635 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4636 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4637 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4638 | HttpRequestInfo request; |
| 4639 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4640 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4641 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4642 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4643 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4644 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4645 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4646 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4647 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4648 | // fetch http://www.example.org/ via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4649 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 4650 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4651 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4652 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4653 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4654 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4655 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4656 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4657 | }; |
| 4658 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4659 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4660 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4661 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4662 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4663 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4664 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4665 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4666 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4667 | TestCompletionCallback callback1; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4668 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4669 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4670 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4671 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4672 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4673 | |
| 4674 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4675 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4676 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4677 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4678 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4679 | TestLoadTimingNotReused(load_timing_info, |
| 4680 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4681 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4682 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4683 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4684 | EXPECT_TRUE(response->proxy_server.is_https()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4685 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4686 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4687 | |
| 4688 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4689 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 4690 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4691 | } |
| 4692 | |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4693 | // Verifies that a session which races and wins against the owning transaction |
| 4694 | // (completing prior to host resolution), doesn't fail the transaction. |
| 4695 | // Regression test for crbug.com/334413. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4696 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithSessionRace) { |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4697 | HttpRequestInfo request; |
| 4698 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4699 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4700 | |
| 4701 | // Configure SPDY proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4702 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4703 | BoundTestNetLog log; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4704 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4705 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4706 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4707 | // Fetch http://www.example.org/ through the SPDY proxy. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4708 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 4709 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4710 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4711 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4712 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4713 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4714 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4715 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4716 | }; |
| 4717 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4718 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4719 | arraysize(spdy_writes)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4720 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 4721 | |
| 4722 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4723 | ssl.next_proto = kProtoHTTP2; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4724 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4725 | |
| 4726 | TestCompletionCallback callback1; |
| 4727 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4728 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4729 | |
| 4730 | // Stall the hostname resolution begun by the transaction. |
| 4731 | session_deps_.host_resolver->set_synchronous_mode(false); |
| 4732 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 4733 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4734 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4735 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4736 | |
| 4737 | // Race a session to the proxy, which completes first. |
| 4738 | session_deps_.host_resolver->set_ondemand_mode(false); |
| 4739 | SpdySessionKey key( |
| 4740 | HostPortPair("proxy", 70), ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
| 4741 | base::WeakPtr<SpdySession> spdy_session = |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4742 | CreateSecureSpdySession(session.get(), key, log.bound()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4743 | |
| 4744 | // Unstall the resolution begun by the transaction. |
| 4745 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 4746 | session_deps_.host_resolver->ResolveAllPending(); |
| 4747 | |
| 4748 | EXPECT_FALSE(callback1.have_result()); |
| 4749 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4750 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4751 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4752 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4753 | ASSERT_TRUE(response); |
| 4754 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4755 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4756 | |
| 4757 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4758 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4759 | EXPECT_EQ(kUploadData, response_data); |
| 4760 | } |
| 4761 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4762 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4763 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4764 | HttpRequestInfo request; |
| 4765 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4766 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4767 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4768 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4769 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4770 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4771 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4772 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4773 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4774 | // The first request will be a bare GET, the second request will be a |
| 4775 | // GET with a Proxy-Authorization header. |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 4776 | spdy_util_.set_default_url(request.url); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4777 | SpdySerializedFrame req_get( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4778 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, false)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4779 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4780 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4781 | "proxy-authorization", "Basic Zm9vOmJhcg==" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4782 | }; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4783 | SpdySerializedFrame req_get_authorization(spdy_util_.ConstructSpdyGet( |
| 4784 | kExtraAuthorizationHeaders, arraysize(kExtraAuthorizationHeaders) / 2, 3, |
| 4785 | LOWEST, false)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4786 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4787 | CreateMockWrite(req_get, 0), CreateMockWrite(req_get_authorization, 3), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4788 | }; |
| 4789 | |
| 4790 | // The first response is a 407 proxy authentication challenge, and the second |
| 4791 | // response will be a 200 response since the second request includes a valid |
| 4792 | // Authorization header. |
| 4793 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4794 | "proxy-authenticate", "Basic realm=\"MyRealm1\"" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4795 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4796 | SpdySerializedFrame resp_authentication(spdy_util_.ConstructSpdyReplyError( |
bnc | c9f762a | 2016-12-06 20:38:23 | [diff] [blame] | 4797 | "407", kExtraAuthenticationHeaders, |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4798 | arraysize(kExtraAuthenticationHeaders) / 2, 1)); |
| 4799 | SpdySerializedFrame body_authentication( |
| 4800 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4801 | SpdySerializedFrame resp_data(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4802 | SpdySerializedFrame body_data(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4803 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4804 | CreateMockRead(resp_authentication, 1), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 4805 | CreateMockRead(body_authentication, 2, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4806 | CreateMockRead(resp_data, 4), |
| 4807 | CreateMockRead(body_data, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4808 | MockRead(ASYNC, 0, 6), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4809 | }; |
| 4810 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4811 | SequencedSocketData data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4812 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4813 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4814 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4815 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4816 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4817 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4818 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4819 | TestCompletionCallback callback1; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4820 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4821 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4822 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4823 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4824 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4825 | |
| 4826 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4827 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4828 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4829 | const HttpResponseInfo* const response = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4830 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4831 | ASSERT_TRUE(response); |
| 4832 | ASSERT_TRUE(response->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4833 | EXPECT_EQ(407, response->headers->response_code()); |
| 4834 | EXPECT_TRUE(response->was_fetched_via_spdy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 4835 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4836 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4837 | TestCompletionCallback callback2; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4838 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4839 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4840 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4841 | |
| 4842 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4843 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4844 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4845 | const HttpResponseInfo* const response_restart = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4846 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4847 | ASSERT_TRUE(response_restart); |
| 4848 | ASSERT_TRUE(response_restart->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4849 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 4850 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4851 | EXPECT_FALSE(response_restart->auth_challenge); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4852 | } |
| 4853 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4854 | // Test a SPDY CONNECT through an HTTPS Proxy to an HTTPS (non-SPDY) Server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4855 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4856 | HttpRequestInfo request; |
| 4857 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4858 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4859 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4860 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4861 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4862 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4863 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4864 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4865 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4866 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4867 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4868 | // CONNECT to www.example.org:443 via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4869 | SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4870 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 4871 | // fetch https://www.example.org/ via HTTP |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4872 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4873 | const char get[] = |
| 4874 | "GET / HTTP/1.1\r\n" |
| 4875 | "Host: www.example.org\r\n" |
| 4876 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4877 | SpdySerializedFrame wrapped_get( |
| 4878 | spdy_util_.ConstructSpdyDataFrame(1, get, strlen(get), false)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4879 | SpdySerializedFrame conn_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4880 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 4881 | "Content-Length: 10\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4882 | SpdySerializedFrame wrapped_get_resp( |
| 4883 | spdy_util_.ConstructSpdyDataFrame(1, resp, strlen(resp), false)); |
| 4884 | SpdySerializedFrame wrapped_body( |
| 4885 | spdy_util_.ConstructSpdyDataFrame(1, "1234567890", 10, false)); |
| 4886 | SpdySerializedFrame window_update( |
| 4887 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4888 | |
| 4889 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4890 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 4891 | CreateMockWrite(window_update, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4892 | }; |
| 4893 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4894 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4895 | CreateMockRead(conn_resp, 1, ASYNC), |
| 4896 | CreateMockRead(wrapped_get_resp, 3, ASYNC), |
| 4897 | CreateMockRead(wrapped_body, 4, ASYNC), |
| 4898 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4899 | MockRead(ASYNC, 0, 7), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4900 | }; |
| 4901 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4902 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4903 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4904 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4905 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4906 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4907 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4908 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4909 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4910 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4911 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4912 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4913 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4914 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4915 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4916 | |
| 4917 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4918 | ASSERT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4919 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4920 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4921 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4922 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4923 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4924 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4925 | ASSERT_TRUE(response); |
| 4926 | ASSERT_TRUE(response->headers); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4927 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4928 | |
| 4929 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4930 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4931 | EXPECT_EQ("1234567890", response_data); |
| 4932 | } |
| 4933 | |
| 4934 | // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4935 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) { |
| 4936 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4937 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4938 | HttpRequestInfo request; |
| 4939 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4940 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4941 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4942 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4943 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4944 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4945 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4946 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4947 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4948 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4949 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4950 | // CONNECT to www.example.org:443 via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4951 | SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4952 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 4953 | // fetch https://www.example.org/ via SPDY |
| 4954 | const char kMyUrl[] = "https://www.example.org/"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4955 | SpdySerializedFrame get( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4956 | spdy_util_wrapped.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4957 | SpdySerializedFrame wrapped_get(spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4958 | SpdySerializedFrame conn_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4959 | SpdySerializedFrame get_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4960 | spdy_util_wrapped.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4961 | SpdySerializedFrame wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4962 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4963 | SpdySerializedFrame body(spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 4964 | SpdySerializedFrame wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4965 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4966 | SpdySerializedFrame window_update_get_resp( |
| 4967 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
| 4968 | SpdySerializedFrame window_update_body( |
| 4969 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4970 | |
| 4971 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4972 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 4973 | CreateMockWrite(window_update_get_resp, 6), |
| 4974 | CreateMockWrite(window_update_body, 7), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4975 | }; |
| 4976 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4977 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4978 | CreateMockRead(conn_resp, 1, ASYNC), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4979 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4980 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 4981 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4982 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4983 | }; |
| 4984 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4985 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4986 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4987 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4988 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4989 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4990 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4991 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4992 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4993 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4994 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4995 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4996 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4997 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4998 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4999 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5000 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5001 | // Allow the SpdyProxyClientSocket's write callback to complete. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 5002 | base::RunLoop().RunUntilIdle(); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5003 | // Now allow the read of the response to complete. |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 5004 | spdy_data.Resume(); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5005 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5006 | EXPECT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5007 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5008 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5009 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5010 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5011 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5012 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5013 | ASSERT_TRUE(response); |
| 5014 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5015 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5016 | |
| 5017 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5018 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5019 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5020 | } |
| 5021 | |
| 5022 | // Test a SPDY CONNECT failure through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5023 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5024 | HttpRequestInfo request; |
| 5025 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5026 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5027 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5028 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5029 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5030 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5031 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5032 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5033 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5034 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5035 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5036 | // CONNECT to www.example.org:443 via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5037 | SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5038 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5039 | SpdySerializedFrame get( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 5040 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5041 | |
| 5042 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5043 | CreateMockWrite(connect, 0), CreateMockWrite(get, 2), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5044 | }; |
| 5045 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5046 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError(1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5047 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5048 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5049 | CreateMockRead(resp, 1, ASYNC), MockRead(ASYNC, 0, 3), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5050 | }; |
| 5051 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5052 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5053 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5054 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5055 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5056 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5057 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5058 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5059 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5060 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5061 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5062 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5063 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5064 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5065 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5066 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5067 | |
| 5068 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5069 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5070 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 5071 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5072 | } |
| 5073 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5074 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 5075 | // HTTPS Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5076 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5077 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) { |
| 5078 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5079 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5080 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5081 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5082 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5083 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5084 | |
| 5085 | HttpRequestInfo request1; |
| 5086 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5087 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5088 | request1.load_flags = 0; |
| 5089 | |
| 5090 | HttpRequestInfo request2; |
| 5091 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5092 | request2.url = GURL("https://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5093 | request2.load_flags = 0; |
| 5094 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5095 | // CONNECT to www.example.org:443 via SPDY. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5096 | SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5097 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5098 | SpdySerializedFrame conn_resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5099 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5100 | // Fetch https://www.example.org/ via HTTP. |
| 5101 | const char get1[] = |
| 5102 | "GET / HTTP/1.1\r\n" |
| 5103 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5104 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5105 | SpdySerializedFrame wrapped_get1( |
| 5106 | spdy_util_.ConstructSpdyDataFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5107 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 5108 | "Content-Length: 1\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5109 | SpdySerializedFrame wrapped_get_resp1( |
| 5110 | spdy_util_.ConstructSpdyDataFrame(1, resp1, strlen(resp1), false)); |
| 5111 | SpdySerializedFrame wrapped_body1( |
| 5112 | spdy_util_.ConstructSpdyDataFrame(1, "1", 1, false)); |
| 5113 | SpdySerializedFrame window_update( |
| 5114 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5115 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5116 | // CONNECT to mail.example.org:443 via SPDY. |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 5117 | SpdyHeaderBlock connect2_block; |
| 5118 | connect2_block[spdy_util_.GetMethodKey()] = "CONNECT"; |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 5119 | connect2_block[spdy_util_.GetHostKey()] = "mail.example.org:443"; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5120 | SpdySerializedFrame connect2(spdy_util_.ConstructSpdyHeaders( |
| 5121 | 3, std::move(connect2_block), LOWEST, false)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 5122 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5123 | SpdySerializedFrame conn_resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5124 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5125 | // Fetch https://mail.example.org/ via HTTP. |
| 5126 | const char get2[] = |
| 5127 | "GET / HTTP/1.1\r\n" |
| 5128 | "Host: mail.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5129 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5130 | SpdySerializedFrame wrapped_get2( |
| 5131 | spdy_util_.ConstructSpdyDataFrame(3, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5132 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 5133 | "Content-Length: 2\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5134 | SpdySerializedFrame wrapped_get_resp2( |
| 5135 | spdy_util_.ConstructSpdyDataFrame(3, resp2, strlen(resp2), false)); |
| 5136 | SpdySerializedFrame wrapped_body2( |
| 5137 | spdy_util_.ConstructSpdyDataFrame(3, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5138 | |
| 5139 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5140 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 5141 | CreateMockWrite(connect2, 5), CreateMockWrite(wrapped_get2, 7), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5142 | }; |
| 5143 | |
| 5144 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5145 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 5146 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
| 5147 | CreateMockRead(wrapped_body1, 4, ASYNC), |
| 5148 | CreateMockRead(conn_resp2, 6, ASYNC), |
| 5149 | CreateMockRead(wrapped_get_resp2, 8, ASYNC), |
| 5150 | CreateMockRead(wrapped_body2, 9, ASYNC), |
| 5151 | MockRead(ASYNC, 0, 10), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5152 | }; |
| 5153 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5154 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5155 | arraysize(spdy_writes)); |
| 5156 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5157 | |
| 5158 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5159 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5160 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5161 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5162 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5163 | SSLSocketDataProvider ssl3(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5164 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5165 | |
| 5166 | TestCompletionCallback callback; |
| 5167 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5168 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5169 | int rv = trans.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5170 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5171 | |
| 5172 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5173 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5174 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5175 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5176 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5177 | ASSERT_TRUE(response); |
| 5178 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5179 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5180 | |
| 5181 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5182 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5183 | rv = trans.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5184 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5185 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5186 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5187 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5188 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5189 | |
| 5190 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5191 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5192 | // Even though the SPDY connection is reused, a new tunnelled connection has |
| 5193 | // to be created, so the socket's load timing looks like a fresh connection. |
| 5194 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5195 | |
| 5196 | // The requests should have different IDs, since they each are using their own |
| 5197 | // separate stream. |
| 5198 | EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5199 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5200 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5201 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5202 | } |
| 5203 | |
| 5204 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 5205 | // HTTPS Proxy to the same server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5206 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5207 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) { |
| 5208 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5209 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5210 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5211 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5212 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5213 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5214 | |
| 5215 | HttpRequestInfo request1; |
| 5216 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5217 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5218 | request1.load_flags = 0; |
| 5219 | |
| 5220 | HttpRequestInfo request2; |
| 5221 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5222 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5223 | request2.load_flags = 0; |
| 5224 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5225 | // CONNECT to www.example.org:443 via SPDY. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5226 | SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5227 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5228 | SpdySerializedFrame conn_resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5229 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5230 | // Fetch https://www.example.org/ via HTTP. |
| 5231 | const char get1[] = |
| 5232 | "GET / HTTP/1.1\r\n" |
| 5233 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5234 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5235 | SpdySerializedFrame wrapped_get1( |
| 5236 | spdy_util_.ConstructSpdyDataFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5237 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 5238 | "Content-Length: 1\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5239 | SpdySerializedFrame wrapped_get_resp1( |
| 5240 | spdy_util_.ConstructSpdyDataFrame(1, resp1, strlen(resp1), false)); |
| 5241 | SpdySerializedFrame wrapped_body1( |
| 5242 | spdy_util_.ConstructSpdyDataFrame(1, "1", 1, false)); |
| 5243 | SpdySerializedFrame window_update( |
| 5244 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5245 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5246 | // Fetch https://www.example.org/2 via HTTP. |
| 5247 | const char get2[] = |
| 5248 | "GET /2 HTTP/1.1\r\n" |
| 5249 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5250 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5251 | SpdySerializedFrame wrapped_get2( |
| 5252 | spdy_util_.ConstructSpdyDataFrame(1, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5253 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 5254 | "Content-Length: 2\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5255 | SpdySerializedFrame wrapped_get_resp2( |
| 5256 | spdy_util_.ConstructSpdyDataFrame(1, resp2, strlen(resp2), false)); |
| 5257 | SpdySerializedFrame wrapped_body2( |
| 5258 | spdy_util_.ConstructSpdyDataFrame(1, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5259 | |
| 5260 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5261 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 5262 | CreateMockWrite(wrapped_get2, 5), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5263 | }; |
| 5264 | |
| 5265 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5266 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 5267 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5268 | CreateMockRead(wrapped_body1, 4, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5269 | CreateMockRead(wrapped_get_resp2, 6, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5270 | CreateMockRead(wrapped_body2, 7, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5271 | MockRead(ASYNC, 0, 8), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5272 | }; |
| 5273 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5274 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5275 | arraysize(spdy_writes)); |
| 5276 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5277 | |
| 5278 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5279 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5280 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5281 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5282 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5283 | |
| 5284 | TestCompletionCallback callback; |
| 5285 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5286 | auto trans = |
| 5287 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5288 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5289 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5290 | |
| 5291 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5292 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5293 | |
| 5294 | LoadTimingInfo load_timing_info; |
| 5295 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5296 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5297 | |
| 5298 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5299 | ASSERT_TRUE(response); |
| 5300 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5301 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5302 | |
| 5303 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5304 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5305 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5306 | trans.reset(); |
| 5307 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5308 | auto trans2 = |
| 5309 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5310 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5311 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5312 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5313 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5314 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5315 | |
| 5316 | LoadTimingInfo load_timing_info2; |
| 5317 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 5318 | TestLoadTimingReused(load_timing_info2); |
| 5319 | |
| 5320 | // The requests should have the same ID. |
| 5321 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5322 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5323 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5324 | } |
| 5325 | |
| 5326 | // Test load timing in the case of of two HTTP requests through a SPDY HTTPS |
| 5327 | // Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5328 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyLoadTimingTwoHttpRequests) { |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5329 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5330 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5331 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5332 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5333 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5334 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5335 | |
| 5336 | HttpRequestInfo request1; |
| 5337 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5338 | request1.url = GURL("http://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5339 | request1.load_flags = 0; |
| 5340 | |
| 5341 | HttpRequestInfo request2; |
| 5342 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5343 | request2.url = GURL("http://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5344 | request2.load_flags = 0; |
| 5345 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5346 | // http://www.example.org/ |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 5347 | SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5348 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5349 | SpdySerializedFrame get1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5350 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
| 5351 | SpdySerializedFrame get_resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5352 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, "1", 1, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5353 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5354 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5355 | // http://mail.example.org/ |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 5356 | SpdyHeaderBlock headers2( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5357 | spdy_util_.ConstructGetHeaderBlockForProxy("http://mail.example.org/")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5358 | SpdySerializedFrame get2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5359 | spdy_util_.ConstructSpdyHeaders(3, std::move(headers2), LOWEST, true)); |
| 5360 | SpdySerializedFrame get_resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5361 | SpdySerializedFrame body2( |
| 5362 | spdy_util_.ConstructSpdyDataFrame(3, "22", 2, true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5363 | |
| 5364 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5365 | CreateMockWrite(get1, 0), CreateMockWrite(get2, 3), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5366 | }; |
| 5367 | |
| 5368 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5369 | CreateMockRead(get_resp1, 1, ASYNC), |
| 5370 | CreateMockRead(body1, 2, ASYNC), |
| 5371 | CreateMockRead(get_resp2, 4, ASYNC), |
| 5372 | CreateMockRead(body2, 5, ASYNC), |
| 5373 | MockRead(ASYNC, 0, 6), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5374 | }; |
| 5375 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5376 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5377 | arraysize(spdy_writes)); |
| 5378 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5379 | |
| 5380 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5381 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5382 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5383 | |
| 5384 | TestCompletionCallback callback; |
| 5385 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5386 | auto trans = |
| 5387 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5388 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5389 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5390 | |
| 5391 | LoadTimingInfo load_timing_info; |
| 5392 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5393 | TestLoadTimingNotReused(load_timing_info, |
| 5394 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5395 | |
| 5396 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5397 | ASSERT_TRUE(response); |
| 5398 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5399 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5400 | |
| 5401 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5402 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5403 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 5404 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5405 | // Delete the first request, so the second one can reuse the socket. |
| 5406 | trans.reset(); |
| 5407 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5408 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5409 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5410 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5411 | |
| 5412 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5413 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5414 | TestLoadTimingReused(load_timing_info2); |
| 5415 | |
| 5416 | // The requests should have the same ID. |
| 5417 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5418 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5419 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5420 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5421 | } |
| 5422 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5423 | // Test the challenge-response-retry sequence through an HTTPS Proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5424 | TEST_F(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5425 | HttpRequestInfo request; |
| 5426 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5427 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5428 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5429 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5430 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5431 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5432 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5433 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5434 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5435 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5436 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5437 | // Since we have proxy, should use full url |
| 5438 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5439 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 5440 | "Host: www.example.org\r\n" |
| 5441 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5442 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5443 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5444 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5445 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 5446 | "Host: www.example.org\r\n" |
| 5447 | "Proxy-Connection: keep-alive\r\n" |
| 5448 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5449 | }; |
| 5450 | |
| 5451 | // The proxy responds to the GET with a 407, using a persistent |
| 5452 | // connection. |
| 5453 | MockRead data_reads1[] = { |
| 5454 | // No credentials. |
| 5455 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 5456 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5457 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 5458 | MockRead("Content-Length: 0\r\n\r\n"), |
| 5459 | |
| 5460 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5461 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5462 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5463 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5464 | }; |
| 5465 | |
| 5466 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5467 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5468 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5469 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5470 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5471 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5472 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5473 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5474 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5475 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5476 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5477 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5478 | |
| 5479 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5480 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5481 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5482 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5483 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5484 | TestLoadTimingNotReused(load_timing_info, |
| 5485 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5486 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5487 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5488 | ASSERT_TRUE(response); |
| 5489 | ASSERT_TRUE(response->headers); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5490 | EXPECT_EQ(407, response->headers->response_code()); |
| 5491 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 5492 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5493 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5494 | TestCompletionCallback callback2; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5495 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5496 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5497 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5498 | |
| 5499 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5500 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5501 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5502 | load_timing_info = LoadTimingInfo(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5503 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5504 | // Retrying with HTTP AUTH is considered to be reusing a socket. |
| 5505 | TestLoadTimingReused(load_timing_info); |
| 5506 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5507 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5508 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5509 | |
| 5510 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 5511 | EXPECT_EQ(200, response->headers->response_code()); |
| 5512 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5513 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5514 | |
| 5515 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5516 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5517 | } |
| 5518 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5519 | void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5520 | const MockRead& status, int expected_status) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5521 | HttpRequestInfo request; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5522 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5523 | request.url = GURL("https://www.example.org/"); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5524 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5525 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5526 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5527 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5528 | |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5529 | // Since we have proxy, should try to establish tunnel. |
| 5530 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5531 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5532 | "Host: www.example.org:443\r\n" |
| 5533 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5534 | }; |
| 5535 | |
| 5536 | MockRead data_reads[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 5537 | status, MockRead("Content-Length: 10\r\n\r\n"), |
| 5538 | // No response body because the test stops reading here. |
| 5539 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5540 | }; |
| 5541 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5542 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 5543 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5544 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5545 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5546 | TestCompletionCallback callback; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5547 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5548 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5549 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5550 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5551 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5552 | |
| 5553 | rv = callback.WaitForResult(); |
| 5554 | EXPECT_EQ(expected_status, rv); |
| 5555 | } |
| 5556 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5557 | void HttpNetworkTransactionTest::ConnectStatusHelper( |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5558 | const MockRead& status) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5559 | ConnectStatusHelperWithExpectedStatus( |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5560 | status, ERR_TUNNEL_CONNECTION_FAILED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5561 | } |
| 5562 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5563 | TEST_F(HttpNetworkTransactionTest, ConnectStatus100) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5564 | ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n")); |
| 5565 | } |
| 5566 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5567 | TEST_F(HttpNetworkTransactionTest, ConnectStatus101) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5568 | ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n")); |
| 5569 | } |
| 5570 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5571 | TEST_F(HttpNetworkTransactionTest, ConnectStatus201) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5572 | ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n")); |
| 5573 | } |
| 5574 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5575 | TEST_F(HttpNetworkTransactionTest, ConnectStatus202) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5576 | ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n")); |
| 5577 | } |
| 5578 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5579 | TEST_F(HttpNetworkTransactionTest, ConnectStatus203) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5580 | ConnectStatusHelper( |
| 5581 | MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n")); |
| 5582 | } |
| 5583 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5584 | TEST_F(HttpNetworkTransactionTest, ConnectStatus204) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5585 | ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n")); |
| 5586 | } |
| 5587 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5588 | TEST_F(HttpNetworkTransactionTest, ConnectStatus205) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5589 | ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n")); |
| 5590 | } |
| 5591 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5592 | TEST_F(HttpNetworkTransactionTest, ConnectStatus206) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5593 | ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n")); |
| 5594 | } |
| 5595 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5596 | TEST_F(HttpNetworkTransactionTest, ConnectStatus300) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5597 | ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n")); |
| 5598 | } |
| 5599 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5600 | TEST_F(HttpNetworkTransactionTest, ConnectStatus301) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5601 | ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n")); |
| 5602 | } |
| 5603 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5604 | TEST_F(HttpNetworkTransactionTest, ConnectStatus302) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5605 | ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n")); |
| 5606 | } |
| 5607 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5608 | TEST_F(HttpNetworkTransactionTest, ConnectStatus303) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5609 | ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n")); |
| 5610 | } |
| 5611 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5612 | TEST_F(HttpNetworkTransactionTest, ConnectStatus304) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5613 | ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n")); |
| 5614 | } |
| 5615 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5616 | TEST_F(HttpNetworkTransactionTest, ConnectStatus305) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5617 | ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n")); |
| 5618 | } |
| 5619 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5620 | TEST_F(HttpNetworkTransactionTest, ConnectStatus306) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5621 | ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n")); |
| 5622 | } |
| 5623 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5624 | TEST_F(HttpNetworkTransactionTest, ConnectStatus307) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5625 | ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n")); |
| 5626 | } |
| 5627 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5628 | TEST_F(HttpNetworkTransactionTest, ConnectStatus308) { |
[email protected] | 0a17aab3 | 2014-04-24 03:32:37 | [diff] [blame] | 5629 | ConnectStatusHelper(MockRead("HTTP/1.1 308 Permanent Redirect\r\n")); |
| 5630 | } |
| 5631 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5632 | TEST_F(HttpNetworkTransactionTest, ConnectStatus400) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5633 | ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n")); |
| 5634 | } |
| 5635 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5636 | TEST_F(HttpNetworkTransactionTest, ConnectStatus401) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5637 | ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n")); |
| 5638 | } |
| 5639 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5640 | TEST_F(HttpNetworkTransactionTest, ConnectStatus402) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5641 | ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n")); |
| 5642 | } |
| 5643 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5644 | TEST_F(HttpNetworkTransactionTest, ConnectStatus403) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5645 | ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n")); |
| 5646 | } |
| 5647 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5648 | TEST_F(HttpNetworkTransactionTest, ConnectStatus404) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5649 | ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n")); |
| 5650 | } |
| 5651 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5652 | TEST_F(HttpNetworkTransactionTest, ConnectStatus405) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5653 | ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n")); |
| 5654 | } |
| 5655 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5656 | TEST_F(HttpNetworkTransactionTest, ConnectStatus406) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5657 | ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n")); |
| 5658 | } |
| 5659 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5660 | TEST_F(HttpNetworkTransactionTest, ConnectStatus407) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5661 | ConnectStatusHelperWithExpectedStatus( |
| 5662 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
[email protected] | a7ea883 | 2010-07-12 17:54:54 | [diff] [blame] | 5663 | ERR_PROXY_AUTH_UNSUPPORTED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5664 | } |
| 5665 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5666 | TEST_F(HttpNetworkTransactionTest, ConnectStatus408) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5667 | ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n")); |
| 5668 | } |
| 5669 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5670 | TEST_F(HttpNetworkTransactionTest, ConnectStatus409) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5671 | ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n")); |
| 5672 | } |
| 5673 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5674 | TEST_F(HttpNetworkTransactionTest, ConnectStatus410) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5675 | ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n")); |
| 5676 | } |
| 5677 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5678 | TEST_F(HttpNetworkTransactionTest, ConnectStatus411) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5679 | ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n")); |
| 5680 | } |
| 5681 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5682 | TEST_F(HttpNetworkTransactionTest, ConnectStatus412) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5683 | ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n")); |
| 5684 | } |
| 5685 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5686 | TEST_F(HttpNetworkTransactionTest, ConnectStatus413) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5687 | ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n")); |
| 5688 | } |
| 5689 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5690 | TEST_F(HttpNetworkTransactionTest, ConnectStatus414) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5691 | ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n")); |
| 5692 | } |
| 5693 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5694 | TEST_F(HttpNetworkTransactionTest, ConnectStatus415) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5695 | ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n")); |
| 5696 | } |
| 5697 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5698 | TEST_F(HttpNetworkTransactionTest, ConnectStatus416) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5699 | ConnectStatusHelper( |
| 5700 | MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n")); |
| 5701 | } |
| 5702 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5703 | TEST_F(HttpNetworkTransactionTest, ConnectStatus417) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5704 | ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n")); |
| 5705 | } |
| 5706 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5707 | TEST_F(HttpNetworkTransactionTest, ConnectStatus500) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5708 | ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n")); |
| 5709 | } |
| 5710 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5711 | TEST_F(HttpNetworkTransactionTest, ConnectStatus501) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5712 | ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n")); |
| 5713 | } |
| 5714 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5715 | TEST_F(HttpNetworkTransactionTest, ConnectStatus502) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5716 | ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n")); |
| 5717 | } |
| 5718 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5719 | TEST_F(HttpNetworkTransactionTest, ConnectStatus503) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5720 | ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n")); |
| 5721 | } |
| 5722 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5723 | TEST_F(HttpNetworkTransactionTest, ConnectStatus504) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5724 | ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n")); |
| 5725 | } |
| 5726 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5727 | TEST_F(HttpNetworkTransactionTest, ConnectStatus505) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5728 | ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); |
| 5729 | } |
| 5730 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5731 | // Test the flow when both the proxy server AND origin server require |
| 5732 | // authentication. Again, this uses basic auth for both since that is |
| 5733 | // the simplest to mock. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5734 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5735 | HttpRequestInfo request; |
| 5736 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5737 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5738 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5739 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5740 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5741 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 5742 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5743 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5744 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5745 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5746 | MockWrite( |
| 5747 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5748 | "Host: www.example.org\r\n" |
| 5749 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5750 | }; |
| 5751 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5752 | MockRead data_reads1[] = { |
| 5753 | MockRead("HTTP/1.0 407 Unauthorized\r\n"), |
| 5754 | // Give a couple authenticate options (only the middle one is actually |
| 5755 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 5756 | MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5757 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5758 | MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 5759 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5760 | // Large content-length -- won't matter, as connection will be reset. |
| 5761 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5762 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5763 | }; |
| 5764 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5765 | // After calling trans.RestartWithAuth() the first time, this is the |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5766 | // request we should be issuing -- the final header line contains the |
| 5767 | // proxy's credentials. |
| 5768 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5769 | MockWrite( |
| 5770 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5771 | "Host: www.example.org\r\n" |
| 5772 | "Proxy-Connection: keep-alive\r\n" |
| 5773 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5774 | }; |
| 5775 | |
| 5776 | // Now the proxy server lets the request pass through to origin server. |
| 5777 | // The origin server responds with a 401. |
| 5778 | MockRead data_reads2[] = { |
| 5779 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5780 | // Note: We are using the same realm-name as the proxy server. This is |
| 5781 | // completely valid, as realms are unique across hosts. |
| 5782 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5783 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5784 | MockRead("Content-Length: 2000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5785 | MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5786 | }; |
| 5787 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5788 | // After calling trans.RestartWithAuth() the second time, we should send |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5789 | // the credentials for both the proxy and origin server. |
| 5790 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5791 | MockWrite( |
| 5792 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5793 | "Host: www.example.org\r\n" |
| 5794 | "Proxy-Connection: keep-alive\r\n" |
| 5795 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 5796 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5797 | }; |
| 5798 | |
| 5799 | // Lastly we get the desired content. |
| 5800 | MockRead data_reads3[] = { |
| 5801 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5802 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5803 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5804 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5805 | }; |
| 5806 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5807 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5808 | data_writes1, arraysize(data_writes1)); |
| 5809 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5810 | data_writes2, arraysize(data_writes2)); |
| 5811 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 5812 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5813 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5814 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 5815 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5816 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5817 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5818 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5819 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5820 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5821 | |
| 5822 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5823 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5824 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5825 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5826 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5827 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5828 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5829 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5830 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5831 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5832 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5833 | |
| 5834 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5835 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5836 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5837 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5838 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5839 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5840 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5841 | TestCompletionCallback callback3; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5842 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5843 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 5844 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5845 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5846 | |
| 5847 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5848 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5849 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5850 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5851 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5852 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5853 | } |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5854 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 5855 | // For the NTLM implementation using SSPI, we skip the NTLM tests since we |
| 5856 | // can't hook into its internals to cause it to generate predictable NTLM |
| 5857 | // authorization headers. |
| 5858 | #if defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5859 | // The NTLM authentication unit tests were generated by capturing the HTTP |
| 5860 | // requests and responses using Fiddler 2 and inspecting the generated random |
| 5861 | // bytes in the debugger. |
| 5862 | |
| 5863 | // Enter the correct password and authenticate successfully. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5864 | TEST_F(HttpNetworkTransactionTest, NTLMAuth1) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5865 | HttpRequestInfo request; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5866 | request.method = "GET"; |
| 5867 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5868 | |
| 5869 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 5870 | // to other auth schemes. |
| 5871 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5872 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5873 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom1, |
| 5874 | MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5875 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5876 | |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5877 | MockWrite data_writes1[] = { |
| 5878 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5879 | "Host: 172.22.68.17\r\n" |
| 5880 | "Connection: keep-alive\r\n\r\n"), |
| 5881 | }; |
| 5882 | |
| 5883 | MockRead data_reads1[] = { |
| 5884 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 5885 | // Negotiate and NTLM are often requested together. However, we only want |
| 5886 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 5887 | // the header that requests Negotiate for this test. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5888 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 5889 | MockRead("Connection: close\r\n"), |
| 5890 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5891 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5892 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5893 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5894 | }; |
| 5895 | |
| 5896 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5897 | // After restarting with a null identity, this is the |
| 5898 | // request we should be issuing -- the final header line contains a Type |
| 5899 | // 1 message. |
| 5900 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5901 | "Host: 172.22.68.17\r\n" |
| 5902 | "Connection: keep-alive\r\n" |
| 5903 | "Authorization: NTLM " |
| 5904 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5905 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5906 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 5907 | // (the credentials for the origin server). The second request continues |
| 5908 | // on the same connection. |
| 5909 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5910 | "Host: 172.22.68.17\r\n" |
| 5911 | "Connection: keep-alive\r\n" |
| 5912 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 5913 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 5914 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBVKW" |
| 5915 | "Yma5xzVAAAAAAAAAAAAAAAAAAAAACH+gWcm+YsP9Tqb9zCR3WAeZZX" |
| 5916 | "ahlhx5I=\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5917 | }; |
| 5918 | |
| 5919 | MockRead data_reads2[] = { |
| 5920 | // The origin server responds with a Type 2 message. |
| 5921 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 5922 | MockRead("WWW-Authenticate: NTLM " |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5923 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCjGpMpPGlYKkAAAAAAAAAALo" |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5924 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 5925 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 5926 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 5927 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 5928 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 5929 | "BtAAAAAAA=\r\n"), |
| 5930 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5931 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5932 | MockRead("You are not authorized to view this page\r\n"), |
| 5933 | |
| 5934 | // Lastly we get the desired content. |
| 5935 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5936 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 5937 | MockRead("Content-Length: 13\r\n\r\n"), |
| 5938 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5939 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5940 | }; |
| 5941 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5942 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5943 | data_writes1, arraysize(data_writes1)); |
| 5944 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5945 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5946 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5947 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5948 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5949 | TestCompletionCallback callback1; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5950 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5951 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5952 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5953 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5954 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5955 | |
| 5956 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5957 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5958 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5959 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5960 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5961 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5962 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5963 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5964 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5965 | TestCompletionCallback callback2; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5966 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5967 | rv = trans.RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
| 5968 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5969 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5970 | |
| 5971 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5972 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5973 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5974 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5975 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5976 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5977 | ASSERT_TRUE(response); |
| 5978 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5979 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5980 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5981 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5982 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5983 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5984 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5985 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5986 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5987 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5988 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5989 | ASSERT_TRUE(response); |
| 5990 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5991 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 5992 | } |
| 5993 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5994 | // Enter a wrong password, and then the correct one. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5995 | TEST_F(HttpNetworkTransactionTest, NTLMAuth2) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5996 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5997 | request.method = "GET"; |
| 5998 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5999 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6000 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom2, |
| 6001 | MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6002 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6003 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6004 | MockWrite data_writes1[] = { |
| 6005 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6006 | "Host: 172.22.68.17\r\n" |
| 6007 | "Connection: keep-alive\r\n\r\n"), |
| 6008 | }; |
| 6009 | |
| 6010 | MockRead data_reads1[] = { |
| 6011 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 6012 | // Negotiate and NTLM are often requested together. However, we only want |
| 6013 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 6014 | // the header that requests Negotiate for this test. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6015 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 6016 | MockRead("Connection: close\r\n"), |
| 6017 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6018 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6019 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6020 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6021 | }; |
| 6022 | |
| 6023 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6024 | // After restarting with a null identity, this is the |
| 6025 | // request we should be issuing -- the final header line contains a Type |
| 6026 | // 1 message. |
| 6027 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6028 | "Host: 172.22.68.17\r\n" |
| 6029 | "Connection: keep-alive\r\n" |
| 6030 | "Authorization: NTLM " |
| 6031 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6032 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6033 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 6034 | // (the credentials for the origin server). The second request continues |
| 6035 | // on the same connection. |
| 6036 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6037 | "Host: 172.22.68.17\r\n" |
| 6038 | "Connection: keep-alive\r\n" |
| 6039 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 6040 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 6041 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwCWeY" |
| 6042 | "XnSZNwoQAAAAAAAAAAAAAAAAAAAADLa34/phTTKzNTWdub+uyFleOj" |
| 6043 | "4Ww7b7E=\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6044 | }; |
| 6045 | |
| 6046 | MockRead data_reads2[] = { |
| 6047 | // The origin server responds with a Type 2 message. |
| 6048 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 6049 | MockRead("WWW-Authenticate: NTLM " |
| 6050 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCbVWUZezVGpAAAAAAAAAAALo" |
| 6051 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 6052 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 6053 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 6054 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 6055 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 6056 | "BtAAAAAAA=\r\n"), |
| 6057 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6058 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6059 | MockRead("You are not authorized to view this page\r\n"), |
| 6060 | |
| 6061 | // Wrong password. |
| 6062 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6063 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 6064 | MockRead("Connection: close\r\n"), |
| 6065 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6066 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6067 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6068 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6069 | }; |
| 6070 | |
| 6071 | MockWrite data_writes3[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6072 | // After restarting with a null identity, this is the |
| 6073 | // request we should be issuing -- the final header line contains a Type |
| 6074 | // 1 message. |
| 6075 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6076 | "Host: 172.22.68.17\r\n" |
| 6077 | "Connection: keep-alive\r\n" |
| 6078 | "Authorization: NTLM " |
| 6079 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6080 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6081 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 6082 | // (the credentials for the origin server). The second request continues |
| 6083 | // on the same connection. |
| 6084 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6085 | "Host: 172.22.68.17\r\n" |
| 6086 | "Connection: keep-alive\r\n" |
| 6087 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 6088 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 6089 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBO54" |
| 6090 | "dFMVvTHwAAAAAAAAAAAAAAAAAAAACS7sT6Uzw7L0L//WUqlIaVWpbI" |
| 6091 | "+4MUm7c=\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6092 | }; |
| 6093 | |
| 6094 | MockRead data_reads3[] = { |
| 6095 | // The origin server responds with a Type 2 message. |
| 6096 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 6097 | MockRead("WWW-Authenticate: NTLM " |
| 6098 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCL24VN8dgOR8AAAAAAAAAALo" |
| 6099 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 6100 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 6101 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 6102 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 6103 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 6104 | "BtAAAAAAA=\r\n"), |
| 6105 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6106 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6107 | MockRead("You are not authorized to view this page\r\n"), |
| 6108 | |
| 6109 | // Lastly we get the desired content. |
| 6110 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6111 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 6112 | MockRead("Content-Length: 13\r\n\r\n"), |
| 6113 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6114 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6115 | }; |
| 6116 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6117 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6118 | data_writes1, arraysize(data_writes1)); |
| 6119 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6120 | data_writes2, arraysize(data_writes2)); |
| 6121 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6122 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6123 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6124 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6125 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6126 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6127 | TestCompletionCallback callback1; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6128 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6129 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6130 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6131 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6132 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6133 | |
| 6134 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6135 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6136 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6137 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6138 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6139 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6140 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6141 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6142 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6143 | TestCompletionCallback callback2; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6144 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6145 | // Enter the wrong password. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6146 | rv = trans.RestartWithAuth(AuthCredentials(kTestingNTLM, kWrongPassword), |
| 6147 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6148 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6149 | |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6150 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6151 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6152 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6153 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6154 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6155 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6156 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6157 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6158 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6159 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6160 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6161 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6162 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6163 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6164 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6165 | TestCompletionCallback callback4; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6166 | |
| 6167 | // Now enter the right password. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6168 | rv = trans.RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
| 6169 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6170 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6171 | |
| 6172 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6173 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6174 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6175 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6176 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6177 | TestCompletionCallback callback5; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6178 | |
| 6179 | // One more roundtrip |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6180 | rv = trans.RestartWithAuth(AuthCredentials(), callback5.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6181 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6182 | |
| 6183 | rv = callback5.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6184 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6185 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6186 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6187 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6188 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 6189 | } |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6190 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6191 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6192 | // Test reading a server response which has only headers, and no body. |
| 6193 | // After some maximum number of bytes is consumed, the transaction should |
| 6194 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6195 | TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6196 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6197 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6198 | request.url = GURL("http://www.example.org/"); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6199 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6200 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6201 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6202 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 6203 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 6204 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 6205 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6206 | |
| 6207 | MockRead data_reads[] = { |
| 6208 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6209 | MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6210 | MockRead("\r\nBODY"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6211 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6212 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6213 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6214 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6215 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6216 | TestCompletionCallback callback; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6217 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6218 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6219 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6220 | |
| 6221 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6222 | EXPECT_THAT(rv, IsError(ERR_RESPONSE_HEADERS_TOO_BIG)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6223 | } |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6224 | |
| 6225 | // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 6226 | // establish tunnel. |
| 6227 | // http://code.google.com/p/chromium/issues/detail?id=3772 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6228 | TEST_F(HttpNetworkTransactionTest, DontRecycleTransportSocketForSSLTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6229 | HttpRequestInfo request; |
| 6230 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6231 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6232 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6233 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 6234 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 6235 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6236 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6237 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6238 | auto trans = |
| 6239 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6240 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6241 | // Since we have proxy, should try to establish tunnel. |
| 6242 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 6243 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6244 | "Host: www.example.org:443\r\n" |
| 6245 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6246 | }; |
| 6247 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 6248 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6249 | // connection. Usually a proxy would return 501 (not implemented), |
| 6250 | // or 200 (tunnel established). |
| 6251 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 6252 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 6253 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6254 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6255 | }; |
| 6256 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6257 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6258 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6259 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6260 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6261 | TestCompletionCallback callback1; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6262 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6263 | int rv = trans->Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6264 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6265 | |
| 6266 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6267 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6268 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6269 | // Empty the current queue. This is necessary because idle sockets are |
| 6270 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6271 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6272 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6273 | // We now check to make sure the TCPClientSocket was not added back to |
| 6274 | // the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6275 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6276 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6277 | base::RunLoop().RunUntilIdle(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6278 | // Make sure that the socket didn't get recycled after calling the destructor. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6279 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6280 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6281 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6282 | // Make sure that we recycle a socket after reading all of the response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6283 | TEST_F(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6284 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6285 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6286 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6287 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6288 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6289 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6290 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6291 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6292 | MockRead data_reads[] = { |
| 6293 | // A part of the response body is received with the response headers. |
| 6294 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 6295 | // The rest of the response body is received in two parts. |
| 6296 | MockRead("lo"), |
| 6297 | MockRead(" world"), |
| 6298 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6299 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6300 | }; |
| 6301 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6302 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6303 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6304 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6305 | TestCompletionCallback callback; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6306 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6307 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6308 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6309 | |
| 6310 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6311 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6312 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6313 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6314 | ASSERT_TRUE(response); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6315 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6316 | EXPECT_TRUE(response->headers); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6317 | std::string status_line = response->headers->GetStatusLine(); |
| 6318 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 6319 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6320 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6321 | |
| 6322 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6323 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6324 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6325 | EXPECT_EQ("hello world", response_data); |
| 6326 | |
| 6327 | // Empty the current queue. This is necessary because idle sockets are |
| 6328 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6329 | base::RunLoop().RunUntilIdle(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6330 | |
| 6331 | // 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] | 6332 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6333 | } |
| 6334 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6335 | // Make sure that we recycle a SSL socket after reading all of the response |
| 6336 | // body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6337 | TEST_F(HttpNetworkTransactionTest, RecycleSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6338 | HttpRequestInfo request; |
| 6339 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6340 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6341 | |
| 6342 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6343 | MockWrite( |
| 6344 | "GET / HTTP/1.1\r\n" |
| 6345 | "Host: www.example.org\r\n" |
| 6346 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6347 | }; |
| 6348 | |
| 6349 | MockRead data_reads[] = { |
| 6350 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6351 | MockRead("Content-Length: 11\r\n\r\n"), |
| 6352 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6353 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6354 | }; |
| 6355 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6356 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6357 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6358 | |
| 6359 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6360 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6361 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6362 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6363 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6364 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6365 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6366 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6367 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6368 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6369 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6370 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6371 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6372 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6373 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6374 | ASSERT_TRUE(response); |
| 6375 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6376 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6377 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6378 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6379 | |
| 6380 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6381 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6382 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6383 | EXPECT_EQ("hello world", response_data); |
| 6384 | |
| 6385 | // Empty the current queue. This is necessary because idle sockets are |
| 6386 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6387 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6388 | |
| 6389 | // 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] | 6390 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6391 | } |
| 6392 | |
| 6393 | // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it |
| 6394 | // from the pool and make sure that we recover okay. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6395 | TEST_F(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6396 | HttpRequestInfo request; |
| 6397 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6398 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6399 | |
| 6400 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6401 | MockWrite( |
| 6402 | "GET / HTTP/1.1\r\n" |
| 6403 | "Host: www.example.org\r\n" |
| 6404 | "Connection: keep-alive\r\n\r\n"), |
| 6405 | MockWrite( |
| 6406 | "GET / HTTP/1.1\r\n" |
| 6407 | "Host: www.example.org\r\n" |
| 6408 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6409 | }; |
| 6410 | |
| 6411 | MockRead data_reads[] = { |
mmenke | 911ee022 | 2015-12-04 03:58:42 | [diff] [blame] | 6412 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 6413 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6414 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6415 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6416 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6417 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6418 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6419 | |
| 6420 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6421 | data_writes, arraysize(data_writes)); |
| 6422 | StaticSocketDataProvider data2(data_reads, arraysize(data_reads), |
| 6423 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6424 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6425 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6426 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6427 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6428 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6429 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6430 | auto trans = |
| 6431 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6432 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6433 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6434 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6435 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6436 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6437 | |
| 6438 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6439 | ASSERT_TRUE(response); |
| 6440 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6441 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6442 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6443 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6444 | |
| 6445 | std::string response_data; |
| 6446 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6447 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6448 | EXPECT_EQ("hello world", response_data); |
| 6449 | |
| 6450 | // Empty the current queue. This is necessary because idle sockets are |
| 6451 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6452 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6453 | |
| 6454 | // 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] | 6455 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6456 | |
| 6457 | // Now start the second transaction, which should reuse the previous socket. |
| 6458 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6459 | trans = |
| 6460 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6461 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6462 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6463 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6464 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6465 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6466 | |
| 6467 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6468 | ASSERT_TRUE(response); |
| 6469 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6470 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6471 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6472 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6473 | |
| 6474 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6475 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6476 | EXPECT_EQ("hello world", response_data); |
| 6477 | |
| 6478 | // Empty the current queue. This is necessary because idle sockets are |
| 6479 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6480 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6481 | |
| 6482 | // 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] | 6483 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6484 | } |
| 6485 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6486 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 6487 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6488 | TEST_F(HttpNetworkTransactionTest, FlushSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6489 | HttpRequestInfo request; |
| 6490 | request.method = "GET"; |
| 6491 | request.url = GURL("http://www.example.org/"); |
| 6492 | request.load_flags = 0; |
| 6493 | |
| 6494 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6495 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6496 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6497 | |
| 6498 | MockRead data_reads[] = { |
| 6499 | // A part of the response body is received with the response headers. |
| 6500 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 6501 | // The rest of the response body is received in two parts. |
| 6502 | MockRead("lo"), MockRead(" world"), |
| 6503 | MockRead("junk"), // Should not be read!! |
| 6504 | MockRead(SYNCHRONOUS, OK), |
| 6505 | }; |
| 6506 | |
| 6507 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 6508 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6509 | |
| 6510 | TestCompletionCallback callback; |
| 6511 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6512 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6513 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6514 | |
| 6515 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6516 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6517 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6518 | ASSERT_TRUE(response); |
| 6519 | EXPECT_TRUE(response->headers); |
| 6520 | std::string status_line = response->headers->GetStatusLine(); |
| 6521 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 6522 | |
| 6523 | // Make memory critical notification and ensure the transaction still has been |
| 6524 | // operating right. |
| 6525 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 6526 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 6527 | base::RunLoop().RunUntilIdle(); |
| 6528 | |
| 6529 | // Socket should not be flushed as long as it is not idle. |
| 6530 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 6531 | |
| 6532 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6533 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6534 | EXPECT_THAT(rv, IsOk()); |
| 6535 | EXPECT_EQ("hello world", response_data); |
| 6536 | |
| 6537 | // Empty the current queue. This is necessary because idle sockets are |
| 6538 | // added to the connection pool asynchronously with a PostTask. |
| 6539 | base::RunLoop().RunUntilIdle(); |
| 6540 | |
| 6541 | // We now check to make sure the socket was added back to the pool. |
| 6542 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 6543 | |
| 6544 | // Idle sockets should be flushed now. |
| 6545 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 6546 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 6547 | base::RunLoop().RunUntilIdle(); |
| 6548 | |
| 6549 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 6550 | } |
| 6551 | |
| 6552 | // Grab an SSL socket, use it, and put it back into the pool. Then, make |
| 6553 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6554 | TEST_F(HttpNetworkTransactionTest, FlushSSLSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6555 | HttpRequestInfo request; |
| 6556 | request.method = "GET"; |
| 6557 | request.url = GURL("https://www.example.org/"); |
| 6558 | request.load_flags = 0; |
| 6559 | |
| 6560 | MockWrite data_writes[] = { |
| 6561 | MockWrite("GET / HTTP/1.1\r\n" |
| 6562 | "Host: www.example.org\r\n" |
| 6563 | "Connection: keep-alive\r\n\r\n"), |
| 6564 | }; |
| 6565 | |
| 6566 | MockRead data_reads[] = { |
| 6567 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 6568 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
| 6569 | |
| 6570 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6571 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6572 | |
| 6573 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 6574 | arraysize(data_writes)); |
| 6575 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6576 | |
| 6577 | TestCompletionCallback callback; |
| 6578 | |
| 6579 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6580 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6581 | |
| 6582 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6583 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6584 | |
| 6585 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6586 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6587 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6588 | ASSERT_TRUE(response); |
| 6589 | ASSERT_TRUE(response->headers); |
| 6590 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6591 | |
| 6592 | // Make memory critical notification and ensure the transaction still has been |
| 6593 | // operating right. |
| 6594 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 6595 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 6596 | base::RunLoop().RunUntilIdle(); |
| 6597 | |
| 6598 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 6599 | |
| 6600 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6601 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6602 | EXPECT_THAT(rv, IsOk()); |
| 6603 | EXPECT_EQ("hello world", response_data); |
| 6604 | |
| 6605 | // Empty the current queue. This is necessary because idle sockets are |
| 6606 | // added to the connection pool asynchronously with a PostTask. |
| 6607 | base::RunLoop().RunUntilIdle(); |
| 6608 | |
| 6609 | // We now check to make sure the socket was added back to the pool. |
| 6610 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 6611 | |
| 6612 | // Make memory notification once again and ensure idle socket is closed. |
| 6613 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 6614 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 6615 | base::RunLoop().RunUntilIdle(); |
| 6616 | |
| 6617 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 6618 | } |
| 6619 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6620 | // Make sure that we recycle a socket after a zero-length response. |
| 6621 | // http://crbug.com/9880 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6622 | TEST_F(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6623 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6624 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6625 | request.url = GURL( |
| 6626 | "http://www.example.org/csi?v=3&s=web&action=&" |
| 6627 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 6628 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 6629 | "rt=prt.2642,ol.2649,xjs.2951"); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6630 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6631 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6632 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6633 | MockRead data_reads[] = { |
| 6634 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 6635 | "Content-Length: 0\r\n" |
| 6636 | "Content-Type: text/html\r\n\r\n"), |
| 6637 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6638 | MockRead(SYNCHRONOUS, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6639 | }; |
| 6640 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6641 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6642 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6643 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 6644 | // Transaction must be created after the MockReads, so it's destroyed before |
| 6645 | // them. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6646 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 6647 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6648 | TestCompletionCallback callback; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6649 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6650 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6651 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6652 | |
| 6653 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6654 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6655 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6656 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6657 | ASSERT_TRUE(response); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6658 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6659 | EXPECT_TRUE(response->headers); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6660 | std::string status_line = response->headers->GetStatusLine(); |
| 6661 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 6662 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6663 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6664 | |
| 6665 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6666 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6667 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6668 | EXPECT_EQ("", response_data); |
| 6669 | |
| 6670 | // Empty the current queue. This is necessary because idle sockets are |
| 6671 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6672 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6673 | |
| 6674 | // 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] | 6675 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6676 | } |
| 6677 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6678 | TEST_F(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6679 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 6680 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 6681 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 6682 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 6683 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6684 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6685 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 6686 | // after use. |
| 6687 | request[0].method = "GET"; |
| 6688 | request[0].url = GURL("http://www.google.com/"); |
| 6689 | request[0].load_flags = 0; |
| 6690 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 6691 | // transaction 1. The first attempts fails when writing the POST data. |
| 6692 | // This causes the transaction to retry with a new socket. The second |
| 6693 | // attempt succeeds. |
| 6694 | request[1].method = "POST"; |
| 6695 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 6696 | request[1].upload_data_stream = &upload_data_stream; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6697 | request[1].load_flags = 0; |
| 6698 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6699 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6700 | |
| 6701 | // The first socket is used for transaction 1 and the first attempt of |
| 6702 | // transaction 2. |
| 6703 | |
| 6704 | // The response of transaction 1. |
| 6705 | MockRead data_reads1[] = { |
| 6706 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 6707 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6708 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6709 | }; |
| 6710 | // The mock write results of transaction 1 and the first attempt of |
| 6711 | // transaction 2. |
| 6712 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6713 | MockWrite(SYNCHRONOUS, 64), // GET |
| 6714 | MockWrite(SYNCHRONOUS, 93), // POST |
| 6715 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6716 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6717 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6718 | data_writes1, arraysize(data_writes1)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6719 | |
| 6720 | // The second socket is used for the second attempt of transaction 2. |
| 6721 | |
| 6722 | // The response of transaction 2. |
| 6723 | MockRead data_reads2[] = { |
| 6724 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 6725 | MockRead("welcome"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6726 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6727 | }; |
| 6728 | // The mock write results of the second attempt of transaction 2. |
| 6729 | MockWrite data_writes2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6730 | MockWrite(SYNCHRONOUS, 93), // POST |
| 6731 | MockWrite(SYNCHRONOUS, 3), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6732 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6733 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6734 | data_writes2, arraysize(data_writes2)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6735 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6736 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6737 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6738 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 6739 | const char* const kExpectedResponseData[] = { |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6740 | "hello world", "welcome" |
| 6741 | }; |
| 6742 | |
| 6743 | for (int i = 0; i < 2; ++i) { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6744 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6745 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6746 | TestCompletionCallback callback; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6747 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6748 | int rv = trans.Start(&request[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6749 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6750 | |
| 6751 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6752 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6753 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6754 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6755 | ASSERT_TRUE(response); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6756 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6757 | EXPECT_TRUE(response->headers); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6758 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6759 | |
| 6760 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6761 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6762 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6763 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 6764 | } |
| 6765 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6766 | |
| 6767 | // Test the request-challenge-retry sequence for basic auth when there is |
| 6768 | // 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] | 6769 | // it fails the identity from the URL is used to answer the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6770 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6771 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6772 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6773 | request.url = GURL("http://foo:b@[email protected]/"); |
[email protected] | 7b08ba6 | 2012-02-10 20:19:41 | [diff] [blame] | 6774 | request.load_flags = LOAD_NORMAL; |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 6775 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6776 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6777 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6778 | |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 6779 | // The password contains an escaped character -- for this test to pass it |
| 6780 | // will need to be unescaped by HttpNetworkTransaction. |
| 6781 | EXPECT_EQ("b%40r", request.url.password()); |
| 6782 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6783 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6784 | MockWrite( |
| 6785 | "GET / HTTP/1.1\r\n" |
| 6786 | "Host: www.example.org\r\n" |
| 6787 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6788 | }; |
| 6789 | |
| 6790 | MockRead data_reads1[] = { |
| 6791 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6792 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6793 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6794 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6795 | }; |
| 6796 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6797 | // After the challenge above, the transaction will be restarted using the |
| 6798 | // identity from the url (foo, b@r) to answer the challenge. |
| 6799 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6800 | MockWrite( |
| 6801 | "GET / HTTP/1.1\r\n" |
| 6802 | "Host: www.example.org\r\n" |
| 6803 | "Connection: keep-alive\r\n" |
| 6804 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6805 | }; |
| 6806 | |
| 6807 | MockRead data_reads2[] = { |
| 6808 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6809 | MockRead("Content-Length: 100\r\n\r\n"), |
| 6810 | MockRead(SYNCHRONOUS, OK), |
| 6811 | }; |
| 6812 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6813 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6814 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6815 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6816 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6817 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6818 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6819 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6820 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6821 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6822 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6823 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6824 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6825 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6826 | |
| 6827 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6828 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6829 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6830 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6831 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6832 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6833 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6834 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6835 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6836 | |
| 6837 | // There is no challenge info, since the identity in URL worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6838 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6839 | |
| 6840 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6841 | |
| 6842 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6843 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6844 | } |
| 6845 | |
| 6846 | // Test the request-challenge-retry sequence for basic auth when there is an |
| 6847 | // incorrect identity in the URL. The identity from the URL should be used only |
| 6848 | // once. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6849 | TEST_F(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6850 | HttpRequestInfo request; |
| 6851 | request.method = "GET"; |
| 6852 | // Note: the URL has a username:password in it. The password "baz" is |
| 6853 | // wrong (should be "bar"). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6854 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6855 | |
| 6856 | request.load_flags = LOAD_NORMAL; |
| 6857 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6858 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6859 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6860 | |
| 6861 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6862 | MockWrite( |
| 6863 | "GET / HTTP/1.1\r\n" |
| 6864 | "Host: www.example.org\r\n" |
| 6865 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6866 | }; |
| 6867 | |
| 6868 | MockRead data_reads1[] = { |
| 6869 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6870 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6871 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6872 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 6873 | }; |
| 6874 | |
| 6875 | // After the challenge above, the transaction will be restarted using the |
| 6876 | // identity from the url (foo, baz) to answer the challenge. |
| 6877 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6878 | MockWrite( |
| 6879 | "GET / HTTP/1.1\r\n" |
| 6880 | "Host: www.example.org\r\n" |
| 6881 | "Connection: keep-alive\r\n" |
| 6882 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6883 | }; |
| 6884 | |
| 6885 | MockRead data_reads2[] = { |
| 6886 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6887 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6888 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6889 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 6890 | }; |
| 6891 | |
| 6892 | // After the challenge above, the transaction will be restarted using the |
| 6893 | // identity supplied by the user (foo, bar) to answer the challenge. |
| 6894 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6895 | MockWrite( |
| 6896 | "GET / HTTP/1.1\r\n" |
| 6897 | "Host: www.example.org\r\n" |
| 6898 | "Connection: keep-alive\r\n" |
| 6899 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6900 | }; |
| 6901 | |
| 6902 | MockRead data_reads3[] = { |
| 6903 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6904 | MockRead("Content-Length: 100\r\n\r\n"), |
| 6905 | MockRead(SYNCHRONOUS, OK), |
| 6906 | }; |
| 6907 | |
| 6908 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6909 | data_writes1, arraysize(data_writes1)); |
| 6910 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6911 | data_writes2, arraysize(data_writes2)); |
| 6912 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6913 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6914 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6915 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6916 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6917 | |
| 6918 | TestCompletionCallback callback1; |
| 6919 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6920 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6921 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6922 | |
| 6923 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6924 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6925 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6926 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6927 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6928 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6929 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6930 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6931 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6932 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6933 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6934 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6935 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6936 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 6937 | |
| 6938 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6939 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6940 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6941 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6942 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6943 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6944 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6945 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6946 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6947 | |
| 6948 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6949 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6950 | |
| 6951 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6952 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6953 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6954 | base::RunLoop().RunUntilIdle(); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6955 | } |
| 6956 | |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6957 | |
| 6958 | // Test the request-challenge-retry sequence for basic auth when there is a |
| 6959 | // correct identity in the URL, but its use is being suppressed. The identity |
| 6960 | // from the URL should never be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6961 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURLSuppressed) { |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6962 | HttpRequestInfo request; |
| 6963 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6964 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6965 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
| 6966 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6967 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6968 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6969 | |
| 6970 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6971 | MockWrite( |
| 6972 | "GET / HTTP/1.1\r\n" |
| 6973 | "Host: www.example.org\r\n" |
| 6974 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6975 | }; |
| 6976 | |
| 6977 | MockRead data_reads1[] = { |
| 6978 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6979 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6980 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6981 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 6982 | }; |
| 6983 | |
| 6984 | // After the challenge above, the transaction will be restarted using the |
| 6985 | // identity supplied by the user, not the one in the URL, to answer the |
| 6986 | // challenge. |
| 6987 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6988 | MockWrite( |
| 6989 | "GET / HTTP/1.1\r\n" |
| 6990 | "Host: www.example.org\r\n" |
| 6991 | "Connection: keep-alive\r\n" |
| 6992 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6993 | }; |
| 6994 | |
| 6995 | MockRead data_reads3[] = { |
| 6996 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6997 | MockRead("Content-Length: 100\r\n\r\n"), |
| 6998 | MockRead(SYNCHRONOUS, OK), |
| 6999 | }; |
| 7000 | |
| 7001 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7002 | data_writes1, arraysize(data_writes1)); |
| 7003 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 7004 | data_writes3, arraysize(data_writes3)); |
| 7005 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7006 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 7007 | |
| 7008 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7009 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7010 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7011 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7012 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7013 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7014 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7015 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7016 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7017 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 7018 | |
| 7019 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7020 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7021 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7022 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7023 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7024 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7025 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7026 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7027 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7028 | |
| 7029 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7030 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7031 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7032 | |
| 7033 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7034 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7035 | } |
| 7036 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7037 | // Test that previously tried username/passwords for a realm get re-used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7038 | TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7039 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7040 | |
| 7041 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 7042 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7043 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7044 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7045 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7046 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7047 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7048 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7049 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7050 | MockWrite( |
| 7051 | "GET /x/y/z HTTP/1.1\r\n" |
| 7052 | "Host: www.example.org\r\n" |
| 7053 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7054 | }; |
| 7055 | |
| 7056 | MockRead data_reads1[] = { |
| 7057 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7058 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7059 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7060 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7061 | }; |
| 7062 | |
| 7063 | // Resend with authorization (username=foo, password=bar) |
| 7064 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7065 | MockWrite( |
| 7066 | "GET /x/y/z HTTP/1.1\r\n" |
| 7067 | "Host: www.example.org\r\n" |
| 7068 | "Connection: keep-alive\r\n" |
| 7069 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7070 | }; |
| 7071 | |
| 7072 | // Sever accepts the authorization. |
| 7073 | MockRead data_reads2[] = { |
| 7074 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7075 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7076 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7077 | }; |
| 7078 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7079 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7080 | data_writes1, arraysize(data_writes1)); |
| 7081 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7082 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7083 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7084 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7085 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7086 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7087 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7088 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7089 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7090 | |
| 7091 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7092 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7093 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7094 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7095 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7096 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7097 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7098 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7099 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7100 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 7101 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7102 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7103 | |
| 7104 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7105 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7106 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7107 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7108 | ASSERT_TRUE(response); |
| 7109 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7110 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7111 | } |
| 7112 | |
| 7113 | // ------------------------------------------------------------------------ |
| 7114 | |
| 7115 | // Transaction 2: authenticate (foo2, bar2) on MyRealm2 |
| 7116 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7117 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7118 | request.method = "GET"; |
| 7119 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 7120 | // protection space as MyRealm1. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7121 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7122 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7123 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7124 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7125 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7126 | MockWrite( |
| 7127 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 7128 | "Host: www.example.org\r\n" |
| 7129 | "Connection: keep-alive\r\n" |
| 7130 | // Send preemptive authorization for MyRealm1 |
| 7131 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7132 | }; |
| 7133 | |
| 7134 | // The server didn't like the preemptive authorization, and |
| 7135 | // challenges us for a different realm (MyRealm2). |
| 7136 | MockRead data_reads1[] = { |
| 7137 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7138 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 7139 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7140 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7141 | }; |
| 7142 | |
| 7143 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 7144 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7145 | MockWrite( |
| 7146 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 7147 | "Host: www.example.org\r\n" |
| 7148 | "Connection: keep-alive\r\n" |
| 7149 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7150 | }; |
| 7151 | |
| 7152 | // Sever accepts the authorization. |
| 7153 | MockRead data_reads2[] = { |
| 7154 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7155 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7156 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7157 | }; |
| 7158 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7159 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7160 | data_writes1, arraysize(data_writes1)); |
| 7161 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7162 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7163 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7164 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7165 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7166 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7167 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7168 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7169 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7170 | |
| 7171 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7172 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7173 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7174 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7175 | ASSERT_TRUE(response); |
| 7176 | ASSERT_TRUE(response->auth_challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7177 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 7178 | EXPECT_EQ("http://www.example.org", |
| 7179 | response->auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7180 | EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 7181 | EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); |
[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(kFoo2, kBar2), |
| 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 3: Resend a request in MyRealm's protection space -- |
| 7201 | // succeed with preemptive authorization. |
| 7202 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7203 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7204 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7205 | request.url = GURL("http://www.example.org/x/y/z2"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7206 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7207 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7208 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7209 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7210 | MockWrite( |
| 7211 | "GET /x/y/z2 HTTP/1.1\r\n" |
| 7212 | "Host: www.example.org\r\n" |
| 7213 | "Connection: keep-alive\r\n" |
| 7214 | // The authorization for MyRealm1 gets sent preemptively |
| 7215 | // (since the url is in the same protection space) |
| 7216 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7217 | }; |
| 7218 | |
| 7219 | // Sever accepts the preemptive authorization |
| 7220 | MockRead data_reads1[] = { |
| 7221 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7222 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7223 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7224 | }; |
| 7225 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7226 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7227 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7228 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7229 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7230 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7231 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7232 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7233 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7234 | |
| 7235 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7236 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7237 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7238 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7239 | ASSERT_TRUE(response); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7240 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7241 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7242 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7243 | } |
| 7244 | |
| 7245 | // ------------------------------------------------------------------------ |
| 7246 | |
| 7247 | // Transaction 4: request another URL in MyRealm (however the |
| 7248 | // url is not known to belong to the protection space, so no pre-auth). |
| 7249 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7250 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7251 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7252 | request.url = GURL("http://www.example.org/x/1"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7253 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7254 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7255 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7256 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7257 | MockWrite( |
| 7258 | "GET /x/1 HTTP/1.1\r\n" |
| 7259 | "Host: www.example.org\r\n" |
| 7260 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7261 | }; |
| 7262 | |
| 7263 | MockRead data_reads1[] = { |
| 7264 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7265 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7266 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7267 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7268 | }; |
| 7269 | |
| 7270 | // Resend with authorization from MyRealm's cache. |
| 7271 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7272 | MockWrite( |
| 7273 | "GET /x/1 HTTP/1.1\r\n" |
| 7274 | "Host: www.example.org\r\n" |
| 7275 | "Connection: keep-alive\r\n" |
| 7276 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7277 | }; |
| 7278 | |
| 7279 | // Sever accepts the authorization. |
| 7280 | MockRead data_reads2[] = { |
| 7281 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7282 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7283 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7284 | }; |
| 7285 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7286 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7287 | data_writes1, arraysize(data_writes1)); |
| 7288 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7289 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7290 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7291 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7292 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7293 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7294 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7295 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7296 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7297 | |
| 7298 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7299 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7300 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7301 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7302 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7303 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7304 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7305 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7306 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7307 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7308 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7309 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7310 | ASSERT_TRUE(response); |
| 7311 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7312 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7313 | } |
| 7314 | |
| 7315 | // ------------------------------------------------------------------------ |
| 7316 | |
| 7317 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 7318 | // cached identity. Should invalidate and re-prompt. |
| 7319 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7320 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7321 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7322 | request.url = GURL("http://www.example.org/p/q/t"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7323 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7324 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7325 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7326 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7327 | MockWrite( |
| 7328 | "GET /p/q/t HTTP/1.1\r\n" |
| 7329 | "Host: www.example.org\r\n" |
| 7330 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7331 | }; |
| 7332 | |
| 7333 | MockRead data_reads1[] = { |
| 7334 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7335 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7336 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7337 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7338 | }; |
| 7339 | |
| 7340 | // Resend with authorization from cache for MyRealm. |
| 7341 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7342 | MockWrite( |
| 7343 | "GET /p/q/t HTTP/1.1\r\n" |
| 7344 | "Host: www.example.org\r\n" |
| 7345 | "Connection: keep-alive\r\n" |
| 7346 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7347 | }; |
| 7348 | |
| 7349 | // Sever rejects the authorization. |
| 7350 | MockRead data_reads2[] = { |
| 7351 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7352 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7353 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7354 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7355 | }; |
| 7356 | |
| 7357 | // At this point we should prompt for new credentials for MyRealm. |
| 7358 | // Restart with username=foo3, password=foo4. |
| 7359 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7360 | MockWrite( |
| 7361 | "GET /p/q/t HTTP/1.1\r\n" |
| 7362 | "Host: www.example.org\r\n" |
| 7363 | "Connection: keep-alive\r\n" |
| 7364 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7365 | }; |
| 7366 | |
| 7367 | // Sever accepts the authorization. |
| 7368 | MockRead data_reads3[] = { |
| 7369 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7370 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7371 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7372 | }; |
| 7373 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7374 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7375 | data_writes1, arraysize(data_writes1)); |
| 7376 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7377 | data_writes2, arraysize(data_writes2)); |
| 7378 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 7379 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7380 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7381 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7382 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7383 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7384 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7385 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7386 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7387 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7388 | |
| 7389 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7390 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7391 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7392 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7393 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7394 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7395 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7396 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7397 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7398 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7399 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7400 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7401 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7402 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7403 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7404 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7405 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7406 | rv = trans.RestartWithAuth(AuthCredentials(kFoo3, kBar3), |
| 7407 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7408 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7409 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7410 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7411 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7412 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7413 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7414 | ASSERT_TRUE(response); |
| 7415 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7416 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7417 | } |
| 7418 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7419 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7420 | // Tests that nonce count increments when multiple auth attempts |
| 7421 | // are started with the same nonce. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7422 | TEST_F(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { |
[email protected] | 54fea256 | 2010-11-17 14:40:44 | [diff] [blame] | 7423 | HttpAuthHandlerDigest::Factory* digest_factory = |
| 7424 | new HttpAuthHandlerDigest::Factory(); |
| 7425 | HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = |
| 7426 | new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); |
| 7427 | digest_factory->set_nonce_generator(nonce_generator); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7428 | session_deps_.http_auth_handler_factory.reset(digest_factory); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7429 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7430 | |
| 7431 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 7432 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7433 | HttpRequestInfo request; |
| 7434 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7435 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7436 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7437 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7438 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7439 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7440 | MockWrite( |
| 7441 | "GET /x/y/z HTTP/1.1\r\n" |
| 7442 | "Host: www.example.org\r\n" |
| 7443 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7444 | }; |
| 7445 | |
| 7446 | MockRead data_reads1[] = { |
| 7447 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7448 | MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " |
| 7449 | "algorithm=MD5, qop=\"auth\"\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7450 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7451 | }; |
| 7452 | |
| 7453 | // Resend with authorization (username=foo, password=bar) |
| 7454 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7455 | MockWrite( |
| 7456 | "GET /x/y/z HTTP/1.1\r\n" |
| 7457 | "Host: www.example.org\r\n" |
| 7458 | "Connection: keep-alive\r\n" |
| 7459 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 7460 | "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " |
| 7461 | "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " |
| 7462 | "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7463 | }; |
| 7464 | |
| 7465 | // Sever accepts the authorization. |
| 7466 | MockRead data_reads2[] = { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 7467 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7468 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7469 | }; |
| 7470 | |
| 7471 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7472 | data_writes1, arraysize(data_writes1)); |
| 7473 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7474 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7475 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7476 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7477 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7478 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7479 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7480 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7481 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7482 | |
| 7483 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7484 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7485 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7486 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7487 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7488 | EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge.get())); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7489 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7490 | TestCompletionCallback callback2; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7491 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7492 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 7493 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7494 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7495 | |
| 7496 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7497 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7498 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7499 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7500 | ASSERT_TRUE(response); |
| 7501 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7502 | } |
| 7503 | |
| 7504 | // ------------------------------------------------------------------------ |
| 7505 | |
| 7506 | // Transaction 2: Request another resource in digestive's protection space. |
| 7507 | // This will preemptively add an Authorization header which should have an |
| 7508 | // "nc" value of 2 (as compared to 1 in the first use. |
| 7509 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7510 | HttpRequestInfo request; |
| 7511 | request.method = "GET"; |
| 7512 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 7513 | // protection space as digest. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7514 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7515 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7516 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7517 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7518 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7519 | MockWrite( |
| 7520 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 7521 | "Host: www.example.org\r\n" |
| 7522 | "Connection: keep-alive\r\n" |
| 7523 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 7524 | "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " |
| 7525 | "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " |
| 7526 | "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7527 | }; |
| 7528 | |
| 7529 | // Sever accepts the authorization. |
| 7530 | MockRead data_reads1[] = { |
| 7531 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7532 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7533 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7534 | }; |
| 7535 | |
| 7536 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7537 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7538 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7539 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7540 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7541 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7542 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7543 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7544 | |
| 7545 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7546 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7547 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7548 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7549 | ASSERT_TRUE(response); |
| 7550 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7551 | } |
| 7552 | } |
| 7553 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7554 | // Test the ResetStateForRestart() private method. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7555 | TEST_F(HttpNetworkTransactionTest, ResetStateForRestart) { |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7556 | // Create a transaction (the dependencies aren't important). |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7557 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7558 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7559 | |
| 7560 | // Setup some state (which we expect ResetStateForRestart() will clear). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7561 | trans.read_buf_ = new IOBuffer(15); |
| 7562 | trans.read_buf_len_ = 15; |
| 7563 | trans.request_headers_.SetHeader("Authorization", "NTLM"); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7564 | |
| 7565 | // Setup state in response_ |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7566 | HttpResponseInfo* response = &trans.response_; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7567 | response->auth_challenge = new AuthChallengeInfo(); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 7568 | response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7569 | response->response_time = base::Time::Now(); |
| 7570 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7571 | |
| 7572 | { // Setup state for response_.vary_data |
| 7573 | HttpRequestInfo request; |
| 7574 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 7575 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 7576 | scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 7577 | request.extra_headers.SetHeader("Foo", "1"); |
| 7578 | request.extra_headers.SetHeader("bar", "23"); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7579 | EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7580 | } |
| 7581 | |
| 7582 | // Cause the above state to be reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7583 | trans.ResetStateForRestart(); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7584 | |
| 7585 | // Verify that the state that needed to be reset, has been reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7586 | EXPECT_FALSE(trans.read_buf_); |
| 7587 | EXPECT_EQ(0, trans.read_buf_len_); |
| 7588 | EXPECT_TRUE(trans.request_headers_.IsEmpty()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7589 | EXPECT_FALSE(response->auth_challenge); |
| 7590 | EXPECT_FALSE(response->headers); |
[email protected] | 34f4094 | 2010-10-04 00:34:04 | [diff] [blame] | 7591 | EXPECT_FALSE(response->was_cached); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 7592 | EXPECT_EQ(0U, response->ssl_info.cert_status); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7593 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7594 | } |
| 7595 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7596 | // Test HTTPS connections to a site with a bad certificate |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7597 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7598 | HttpRequestInfo request; |
| 7599 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7600 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7601 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7602 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7603 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7604 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7605 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7606 | MockWrite( |
| 7607 | "GET / HTTP/1.1\r\n" |
| 7608 | "Host: www.example.org\r\n" |
| 7609 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7610 | }; |
| 7611 | |
| 7612 | MockRead data_reads[] = { |
| 7613 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7614 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7615 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7616 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7617 | }; |
| 7618 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 7619 | StaticSocketDataProvider ssl_bad_certificate; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7620 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7621 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7622 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 7623 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7624 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7625 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 7626 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7627 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 7628 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7629 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7630 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7631 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7632 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7633 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7634 | |
| 7635 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7636 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7637 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7638 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7639 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7640 | |
| 7641 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7642 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7643 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7644 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7645 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7646 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7647 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7648 | } |
| 7649 | |
| 7650 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 7651 | // proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7652 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7653 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7654 | |
| 7655 | HttpRequestInfo request; |
| 7656 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7657 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7658 | |
| 7659 | MockWrite proxy_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7660 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7661 | "Host: www.example.org:443\r\n" |
| 7662 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7663 | }; |
| 7664 | |
| 7665 | MockRead proxy_reads[] = { |
| 7666 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7667 | MockRead(SYNCHRONOUS, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7668 | }; |
| 7669 | |
| 7670 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7671 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7672 | "Host: www.example.org:443\r\n" |
| 7673 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7674 | MockWrite("GET / HTTP/1.1\r\n" |
| 7675 | "Host: www.example.org\r\n" |
| 7676 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7677 | }; |
| 7678 | |
| 7679 | MockRead data_reads[] = { |
| 7680 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 7681 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7682 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7683 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7684 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7685 | }; |
| 7686 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7687 | StaticSocketDataProvider ssl_bad_certificate( |
| 7688 | proxy_reads, arraysize(proxy_reads), |
| 7689 | proxy_writes, arraysize(proxy_writes)); |
| 7690 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7691 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7692 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 7693 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7694 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7695 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 7696 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7697 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 7698 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7699 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7700 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7701 | |
| 7702 | for (int i = 0; i < 2; i++) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7703 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7704 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7705 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7706 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7707 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7708 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7709 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7710 | |
| 7711 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7712 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7713 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7714 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7715 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7716 | |
| 7717 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7718 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7719 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7720 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7721 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7722 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7723 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7724 | } |
| 7725 | } |
| 7726 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7727 | |
| 7728 | // Test HTTPS connections to a site, going through an HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7729 | TEST_F(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7730 | session_deps_.proxy_service = |
| 7731 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7732 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7733 | session_deps_.net_log = &net_log; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7734 | |
| 7735 | HttpRequestInfo request; |
| 7736 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7737 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7738 | |
| 7739 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7740 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7741 | "Host: www.example.org:443\r\n" |
| 7742 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7743 | MockWrite("GET / HTTP/1.1\r\n" |
| 7744 | "Host: www.example.org\r\n" |
| 7745 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7746 | }; |
| 7747 | |
| 7748 | MockRead data_reads[] = { |
| 7749 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 7750 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7751 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7752 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7753 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7754 | }; |
| 7755 | |
| 7756 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7757 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7758 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 7759 | SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7760 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7761 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7762 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 7763 | session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7764 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7765 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7766 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7767 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7768 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7769 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7770 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7771 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7772 | |
| 7773 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7774 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7775 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7776 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7777 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7778 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 7779 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7780 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 7781 | EXPECT_EQ(200, response->headers->response_code()); |
| 7782 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7783 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7784 | |
| 7785 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7786 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7787 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7788 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7789 | } |
| 7790 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7791 | // Test an HTTPS Proxy's ability to redirect a CONNECT request |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7792 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7793 | session_deps_.proxy_service = |
| 7794 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7795 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7796 | session_deps_.net_log = &net_log; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7797 | |
| 7798 | HttpRequestInfo request; |
| 7799 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7800 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7801 | |
| 7802 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7803 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7804 | "Host: www.example.org:443\r\n" |
| 7805 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7806 | }; |
| 7807 | |
| 7808 | MockRead data_reads[] = { |
| 7809 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 7810 | MockRead("Location: http://login.example.com/\r\n"), |
| 7811 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7812 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7813 | }; |
| 7814 | |
| 7815 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7816 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7817 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7818 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7819 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7820 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7821 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7822 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7823 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7824 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7825 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7826 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7827 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7828 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7829 | |
| 7830 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7831 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7832 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7833 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7834 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7835 | |
| 7836 | EXPECT_EQ(302, response->headers->response_code()); |
| 7837 | std::string url; |
| 7838 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 7839 | EXPECT_EQ("http://login.example.com/", url); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7840 | |
| 7841 | // In the case of redirects from proxies, HttpNetworkTransaction returns |
| 7842 | // timing for the proxy connection instead of the connection to the host, |
| 7843 | // and no send / receive times. |
| 7844 | // See HttpNetworkTransaction::OnHttpsProxyTunnelResponse. |
| 7845 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7846 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7847 | |
| 7848 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 7849 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7850 | |
| 7851 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 7852 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 7853 | load_timing_info.proxy_resolve_end); |
| 7854 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 7855 | load_timing_info.connect_timing.connect_start); |
| 7856 | ExpectConnectTimingHasTimes( |
| 7857 | load_timing_info.connect_timing, |
| 7858 | CONNECT_TIMING_HAS_DNS_TIMES | CONNECT_TIMING_HAS_SSL_TIMES); |
| 7859 | |
| 7860 | EXPECT_TRUE(load_timing_info.send_start.is_null()); |
| 7861 | EXPECT_TRUE(load_timing_info.send_end.is_null()); |
| 7862 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7863 | } |
| 7864 | |
| 7865 | // Test an HTTPS (SPDY) Proxy's ability to redirect a CONNECT request |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7866 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7867 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7868 | |
| 7869 | HttpRequestInfo request; |
| 7870 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7871 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7872 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7873 | SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7874 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7875 | SpdySerializedFrame goaway( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 7876 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7877 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7878 | CreateMockWrite(conn, 0, SYNCHRONOUS), |
| 7879 | CreateMockWrite(goaway, 2, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7880 | }; |
| 7881 | |
| 7882 | static const char* const kExtraHeaders[] = { |
| 7883 | "location", |
| 7884 | "http://login.example.com/", |
| 7885 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 7886 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
bnc | c9f762a | 2016-12-06 20:38:23 | [diff] [blame] | 7887 | "302", kExtraHeaders, arraysize(kExtraHeaders) / 2, 1)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7888 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7889 | CreateMockRead(resp, 1), MockRead(ASYNC, 0, 3), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7890 | }; |
| 7891 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7892 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 7893 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7894 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 7895 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7896 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7897 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7898 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7899 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7900 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7901 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7902 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7903 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7904 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7905 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7906 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7907 | |
| 7908 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7909 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7910 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7911 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7912 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7913 | |
| 7914 | EXPECT_EQ(302, response->headers->response_code()); |
| 7915 | std::string url; |
| 7916 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 7917 | EXPECT_EQ("http://login.example.com/", url); |
| 7918 | } |
| 7919 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7920 | // Test that an HTTPS proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7921 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7922 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7923 | |
| 7924 | HttpRequestInfo request; |
| 7925 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7926 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7927 | |
| 7928 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7929 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7930 | "Host: www.example.org:443\r\n" |
| 7931 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7932 | }; |
| 7933 | |
| 7934 | MockRead data_reads[] = { |
| 7935 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 7936 | MockRead("Content-Length: 23\r\n\r\n"), |
| 7937 | MockRead("The host does not exist"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7938 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7939 | }; |
| 7940 | |
| 7941 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7942 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7943 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7944 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7945 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7946 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7947 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7948 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7949 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7950 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7951 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7952 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7953 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7954 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7955 | |
| 7956 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7957 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7958 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 7959 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7960 | } |
| 7961 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7962 | // Test that a SPDY proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7963 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaSpdyProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7964 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7965 | |
| 7966 | HttpRequestInfo request; |
| 7967 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7968 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7969 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7970 | SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7971 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7972 | SpdySerializedFrame rst( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 7973 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7974 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7975 | CreateMockWrite(conn, 0), CreateMockWrite(rst, 3), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7976 | }; |
| 7977 | |
| 7978 | static const char* const kExtraHeaders[] = { |
| 7979 | "location", |
| 7980 | "http://login.example.com/", |
| 7981 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 7982 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
bnc | c9f762a | 2016-12-06 20:38:23 | [diff] [blame] | 7983 | "404", kExtraHeaders, arraysize(kExtraHeaders) / 2, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7984 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 7985 | 1, "The host does not exist", 23, true)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7986 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7987 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7988 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7989 | }; |
| 7990 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7991 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 7992 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7993 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 7994 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7995 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7996 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7997 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7998 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7999 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8000 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8001 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8002 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8003 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8004 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8005 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8006 | |
| 8007 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8008 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8009 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 8010 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8011 | } |
| 8012 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8013 | // Test the request-challenge-retry sequence for basic auth, through |
| 8014 | // a SPDY proxy over a single SPDY session. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8015 | TEST_F(HttpNetworkTransactionTest, BasicAuthSpdyProxy) { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8016 | HttpRequestInfo request; |
| 8017 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8018 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8019 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 8020 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8021 | |
| 8022 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8023 | session_deps_.proxy_service = |
| 8024 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8025 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8026 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8027 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8028 | |
| 8029 | // Since we have proxy, should try to establish tunnel. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8030 | SpdySerializedFrame req(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8031 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8032 | SpdySerializedFrame rst( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 8033 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 8034 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8035 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8036 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8037 | // be issuing -- the final header line contains the credentials. |
| 8038 | const char* const kAuthCredentials[] = { |
| 8039 | "proxy-authorization", "Basic Zm9vOmJhcg==", |
| 8040 | }; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8041 | SpdySerializedFrame connect2(spdy_util_.ConstructSpdyConnect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 8042 | kAuthCredentials, arraysize(kAuthCredentials) / 2, 3, LOWEST, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8043 | HostPortPair("www.example.org", 443))); |
| 8044 | // fetch https://www.example.org/ via HTTP |
| 8045 | const char get[] = |
| 8046 | "GET / HTTP/1.1\r\n" |
| 8047 | "Host: www.example.org\r\n" |
| 8048 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8049 | SpdySerializedFrame wrapped_get( |
| 8050 | spdy_util_.ConstructSpdyDataFrame(3, get, strlen(get), false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8051 | |
| 8052 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8053 | CreateMockWrite(req, 0, ASYNC), CreateMockWrite(rst, 2, ASYNC), |
| 8054 | CreateMockWrite(connect2, 3), CreateMockWrite(wrapped_get, 5), |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8055 | }; |
| 8056 | |
| 8057 | // The proxy responds to the connect with a 407, using a persistent |
| 8058 | // connection. |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 8059 | const char kAuthStatus[] = "407"; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8060 | const char* const kAuthChallenge[] = { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8061 | "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 8062 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8063 | SpdySerializedFrame conn_auth_resp(spdy_util_.ConstructSpdyReplyError( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8064 | kAuthStatus, kAuthChallenge, arraysize(kAuthChallenge) / 2, 1)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8065 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8066 | SpdySerializedFrame conn_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8067 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 8068 | "Content-Length: 5\r\n\r\n"; |
| 8069 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8070 | SpdySerializedFrame wrapped_get_resp( |
| 8071 | spdy_util_.ConstructSpdyDataFrame(3, resp, strlen(resp), false)); |
| 8072 | SpdySerializedFrame wrapped_body( |
| 8073 | spdy_util_.ConstructSpdyDataFrame(3, "hello", 5, false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8074 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8075 | CreateMockRead(conn_auth_resp, 1, ASYNC), |
| 8076 | CreateMockRead(conn_resp, 4, ASYNC), |
| 8077 | CreateMockRead(wrapped_get_resp, 6, ASYNC), |
| 8078 | CreateMockRead(wrapped_body, 7, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8079 | MockRead(ASYNC, OK, 8), // EOF. May or may not be read. |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8080 | }; |
| 8081 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8082 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8083 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8084 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8085 | // Negotiate SPDY to the proxy |
| 8086 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8087 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8088 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8089 | // Vanilla SSL to the server |
| 8090 | SSLSocketDataProvider server(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8091 | session_deps_.socket_factory->AddSSLSocketDataProvider(&server); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8092 | |
| 8093 | TestCompletionCallback callback1; |
| 8094 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8095 | auto trans = |
| 8096 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8097 | |
| 8098 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8099 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8100 | |
| 8101 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8102 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 8103 | TestNetLogEntry::List entries; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8104 | log.GetEntries(&entries); |
| 8105 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 8106 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 8107 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8108 | ExpectLogContainsSomewhere( |
| 8109 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 8110 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 8111 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8112 | |
| 8113 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8114 | ASSERT_TRUE(response); |
| 8115 | ASSERT_TRUE(response->headers); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8116 | EXPECT_EQ(407, response->headers->response_code()); |
| 8117 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8118 | EXPECT_TRUE(response->auth_challenge); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 8119 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8120 | |
| 8121 | TestCompletionCallback callback2; |
| 8122 | |
| 8123 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 8124 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8125 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8126 | |
| 8127 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8128 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8129 | |
| 8130 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8131 | ASSERT_TRUE(response); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8132 | |
| 8133 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8134 | EXPECT_EQ(200, response->headers->response_code()); |
| 8135 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 8136 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8137 | |
| 8138 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8139 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8140 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8141 | LoadTimingInfo load_timing_info; |
| 8142 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8143 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8144 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 8145 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8146 | trans.reset(); |
| 8147 | session->CloseAllConnections(); |
| 8148 | } |
| 8149 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8150 | // Test that an explicitly trusted SPDY proxy can push a resource from an |
| 8151 | // origin that is different from that of its associated resource. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8152 | TEST_F(HttpNetworkTransactionTest, CrossOriginSPDYProxyPush) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8153 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8154 | auto proxy_delegate = base::MakeUnique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8155 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 8156 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8157 | HttpRequestInfo request; |
| 8158 | HttpRequestInfo push_request; |
| 8159 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8160 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8161 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8162 | push_request.method = "GET"; |
| 8163 | push_request.url = GURL("http://www.another-origin.com/foo.dat"); |
| 8164 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8165 | // Configure against https proxy server "myproxy:443". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8166 | session_deps_.proxy_service = |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8167 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:443"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8168 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8169 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8170 | |
inlinechan | 894515af | 2016-12-09 02:40:10 | [diff] [blame] | 8171 | session_deps_.proxy_delegate = std::move(proxy_delegate); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8172 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8173 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8174 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8175 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 8176 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8177 | SpdySerializedFrame stream2_priority( |
| 8178 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8179 | |
| 8180 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8181 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8182 | CreateMockWrite(stream2_priority, 3, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8183 | }; |
| 8184 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8185 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8186 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8187 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8188 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8189 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8190 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 8191 | NULL, 0, 2, 1, "http://www.another-origin.com/foo.dat")); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8192 | const char kPushedData[] = "pushed"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8193 | SpdySerializedFrame stream2_body(spdy_util_.ConstructSpdyDataFrame( |
| 8194 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8195 | |
| 8196 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8197 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 8198 | CreateMockRead(stream2_syn, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8199 | CreateMockRead(stream1_body, 4, ASYNC), |
| 8200 | CreateMockRead(stream2_body, 5, ASYNC), |
| 8201 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8202 | }; |
| 8203 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8204 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8205 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8206 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8207 | // Negotiate SPDY to the proxy |
| 8208 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8209 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8210 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8211 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8212 | auto trans = |
| 8213 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8214 | TestCompletionCallback callback; |
| 8215 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8216 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8217 | |
| 8218 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8219 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8220 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8221 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8222 | auto push_trans = |
| 8223 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8224 | rv = push_trans->Start(&push_request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8225 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8226 | |
| 8227 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8228 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8229 | const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); |
| 8230 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8231 | ASSERT_TRUE(response); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8232 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8233 | |
| 8234 | EXPECT_EQ(200, response->headers->response_code()); |
| 8235 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8236 | |
| 8237 | std::string response_data; |
| 8238 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8239 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8240 | EXPECT_EQ("hello!", response_data); |
| 8241 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8242 | LoadTimingInfo load_timing_info; |
| 8243 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8244 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8245 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 8246 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8247 | // Verify the pushed stream. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8248 | EXPECT_TRUE(push_response->headers); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8249 | EXPECT_EQ(200, push_response->headers->response_code()); |
| 8250 | |
| 8251 | rv = ReadTransaction(push_trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8252 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8253 | EXPECT_EQ("pushed", response_data); |
| 8254 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8255 | LoadTimingInfo push_load_timing_info; |
| 8256 | EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); |
| 8257 | TestLoadTimingReusedWithPac(push_load_timing_info); |
| 8258 | // The transactions should share a socket ID, despite being for different |
| 8259 | // origins. |
| 8260 | EXPECT_EQ(load_timing_info.socket_log_id, |
| 8261 | push_load_timing_info.socket_log_id); |
| 8262 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8263 | trans.reset(); |
| 8264 | push_trans.reset(); |
| 8265 | session->CloseAllConnections(); |
| 8266 | } |
| 8267 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8268 | // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8269 | TEST_F(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8270 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8271 | auto proxy_delegate = base::MakeUnique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8272 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 8273 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8274 | HttpRequestInfo request; |
| 8275 | |
| 8276 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8277 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8278 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8279 | session_deps_.proxy_service = |
| 8280 | ProxyService::CreateFixed("https://myproxy:443"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8281 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8282 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8283 | |
| 8284 | // Enable cross-origin push. |
inlinechan | 894515af | 2016-12-09 02:40:10 | [diff] [blame] | 8285 | session_deps_.proxy_delegate = std::move(proxy_delegate); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8286 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8287 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8288 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8289 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 8290 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8291 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8292 | SpdySerializedFrame push_rst( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 8293 | spdy_util_.ConstructSpdyRstStream(2, ERROR_CODE_REFUSED_STREAM)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8294 | |
| 8295 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8296 | CreateMockWrite(stream1_syn, 0, ASYNC), CreateMockWrite(push_rst, 3), |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8297 | }; |
| 8298 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8299 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8300 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8301 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8302 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8303 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8304 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 8305 | NULL, 0, 2, 1, "https://www.another-origin.com/foo.dat")); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8306 | |
| 8307 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8308 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 8309 | CreateMockRead(stream2_syn, 2, ASYNC), |
| 8310 | CreateMockRead(stream1_body, 4, ASYNC), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 8311 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a hang |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8312 | }; |
| 8313 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8314 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8315 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8316 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8317 | // Negotiate SPDY to the proxy |
| 8318 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8319 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8320 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8321 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8322 | auto trans = |
| 8323 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8324 | TestCompletionCallback callback; |
| 8325 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8326 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8327 | |
| 8328 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8329 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8330 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8331 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8332 | ASSERT_TRUE(response); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8333 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8334 | |
| 8335 | EXPECT_EQ(200, response->headers->response_code()); |
| 8336 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8337 | |
| 8338 | std::string response_data; |
| 8339 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8340 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8341 | EXPECT_EQ("hello!", response_data); |
| 8342 | |
| 8343 | trans.reset(); |
| 8344 | session->CloseAllConnections(); |
| 8345 | } |
| 8346 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8347 | // Test that an explicitly trusted SPDY proxy can push same-origin HTTPS |
| 8348 | // resources. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8349 | TEST_F(HttpNetworkTransactionTest, SameOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8350 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8351 | auto proxy_delegate = base::MakeUnique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8352 | proxy_delegate->set_trusted_spdy_proxy( |
| 8353 | net::ProxyServer::FromURI("myproxy:70", net::ProxyServer::SCHEME_HTTP)); |
| 8354 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8355 | HttpRequestInfo request; |
| 8356 | |
| 8357 | request.method = "GET"; |
| 8358 | request.url = GURL("http://www.example.org/"); |
| 8359 | |
| 8360 | // Configure against https proxy server "myproxy:70". |
| 8361 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
| 8362 | BoundTestNetLog log; |
| 8363 | session_deps_.net_log = log.bound().net_log(); |
| 8364 | |
| 8365 | // Enable cross-origin push. |
inlinechan | 894515af | 2016-12-09 02:40:10 | [diff] [blame] | 8366 | session_deps_.proxy_delegate = std::move(proxy_delegate); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8367 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8368 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8369 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8370 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 8371 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8372 | SpdySerializedFrame stream2_priority( |
| 8373 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8374 | |
| 8375 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8376 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8377 | CreateMockWrite(stream2_priority, 3, ASYNC), |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8378 | }; |
| 8379 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8380 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8381 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8382 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8383 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 8384 | nullptr, 0, 2, 1, "https://myproxy:70/foo.dat")); |
| 8385 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8386 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8387 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8388 | SpdySerializedFrame stream2_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8389 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8390 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8391 | SpdySerializedFrame stream2_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8392 | |
| 8393 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8394 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 8395 | CreateMockRead(stream2_syn, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8396 | CreateMockRead(stream1_body, 4, ASYNC), |
| 8397 | CreateMockRead(stream2_body, 5, ASYNC), |
| 8398 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8399 | }; |
| 8400 | |
| 8401 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8402 | arraysize(spdy_writes)); |
| 8403 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 8404 | // Negotiate SPDY to the proxy |
| 8405 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8406 | proxy.next_proto = kProtoHTTP2; |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8407 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
| 8408 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8409 | auto trans = |
| 8410 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8411 | TestCompletionCallback callback; |
| 8412 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8413 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8414 | |
| 8415 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8416 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8417 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8418 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8419 | ASSERT_TRUE(response); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8420 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8421 | |
| 8422 | EXPECT_EQ(200, response->headers->response_code()); |
| 8423 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8424 | |
| 8425 | std::string response_data; |
| 8426 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8427 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8428 | EXPECT_EQ("hello!", response_data); |
| 8429 | |
| 8430 | trans.reset(); |
| 8431 | session->CloseAllConnections(); |
| 8432 | } |
| 8433 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8434 | // Test HTTPS connections to a site with a bad certificate, going through an |
| 8435 | // HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8436 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8437 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8438 | |
| 8439 | HttpRequestInfo request; |
| 8440 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8441 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8442 | |
| 8443 | // Attempt to fetch the URL from a server with a bad cert |
| 8444 | MockWrite bad_cert_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8445 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8446 | "Host: www.example.org:443\r\n" |
| 8447 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8448 | }; |
| 8449 | |
| 8450 | MockRead bad_cert_reads[] = { |
| 8451 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8452 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8453 | }; |
| 8454 | |
| 8455 | // Attempt to fetch the URL with a good cert |
| 8456 | MockWrite good_data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8457 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8458 | "Host: www.example.org:443\r\n" |
| 8459 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 8460 | MockWrite("GET / HTTP/1.1\r\n" |
| 8461 | "Host: www.example.org\r\n" |
| 8462 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8463 | }; |
| 8464 | |
| 8465 | MockRead good_cert_reads[] = { |
| 8466 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 8467 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8468 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8469 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8470 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8471 | }; |
| 8472 | |
| 8473 | StaticSocketDataProvider ssl_bad_certificate( |
| 8474 | bad_cert_reads, arraysize(bad_cert_reads), |
| 8475 | bad_cert_writes, arraysize(bad_cert_writes)); |
| 8476 | StaticSocketDataProvider data(good_cert_reads, arraysize(good_cert_reads), |
| 8477 | good_data_writes, arraysize(good_data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8478 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 8479 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8480 | |
| 8481 | // SSL to the proxy, then CONNECT request, then SSL with bad certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8482 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 8483 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 8484 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8485 | |
| 8486 | // SSL to the proxy, then CONNECT request, then valid SSL certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8487 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 8488 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8489 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8490 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8491 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8492 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8493 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8494 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8495 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8496 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8497 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8498 | |
| 8499 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8500 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8501 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8502 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8503 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8504 | |
| 8505 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8506 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8507 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8508 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8509 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8510 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8511 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8512 | } |
| 8513 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8514 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8515 | HttpRequestInfo request; |
| 8516 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8517 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8518 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 8519 | "Chromium Ultra Awesome X Edition"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8520 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8521 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8522 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8523 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8524 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8525 | MockWrite( |
| 8526 | "GET / HTTP/1.1\r\n" |
| 8527 | "Host: www.example.org\r\n" |
| 8528 | "Connection: keep-alive\r\n" |
| 8529 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8530 | }; |
| 8531 | |
| 8532 | // Lastly, the server responds with the actual content. |
| 8533 | MockRead data_reads[] = { |
| 8534 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8535 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8536 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8537 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8538 | }; |
| 8539 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8540 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8541 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8542 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8543 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8544 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8545 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8546 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8547 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8548 | |
| 8549 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8550 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8551 | } |
| 8552 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8553 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8554 | HttpRequestInfo request; |
| 8555 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8556 | request.url = GURL("https://www.example.org/"); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8557 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 8558 | "Chromium Ultra Awesome X Edition"); |
| 8559 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8560 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8561 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8562 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8563 | |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8564 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8565 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8566 | "Host: www.example.org:443\r\n" |
| 8567 | "Proxy-Connection: keep-alive\r\n" |
| 8568 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8569 | }; |
| 8570 | MockRead data_reads[] = { |
| 8571 | // Return an error, so the transaction stops here (this test isn't |
| 8572 | // interested in the rest). |
| 8573 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 8574 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8575 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 8576 | }; |
| 8577 | |
| 8578 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8579 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8580 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8581 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8582 | TestCompletionCallback callback; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8583 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8584 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8585 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8586 | |
| 8587 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8588 | EXPECT_THAT(rv, IsOk()); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8589 | } |
| 8590 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8591 | TEST_F(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8592 | HttpRequestInfo request; |
| 8593 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8594 | request.url = GURL("http://www.example.org/"); |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 8595 | request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 8596 | "http://the.previous.site.com/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8597 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8598 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8599 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8600 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8601 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8602 | MockWrite( |
| 8603 | "GET / HTTP/1.1\r\n" |
| 8604 | "Host: www.example.org\r\n" |
| 8605 | "Connection: keep-alive\r\n" |
| 8606 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8607 | }; |
| 8608 | |
| 8609 | // Lastly, the server responds with the actual content. |
| 8610 | MockRead data_reads[] = { |
| 8611 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8612 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8613 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8614 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8615 | }; |
| 8616 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8617 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8618 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8619 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8620 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8621 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8622 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8623 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8624 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8625 | |
| 8626 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8627 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8628 | } |
| 8629 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8630 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8631 | HttpRequestInfo request; |
| 8632 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8633 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8634 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8635 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8636 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8637 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8638 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8639 | MockWrite( |
| 8640 | "POST / HTTP/1.1\r\n" |
| 8641 | "Host: www.example.org\r\n" |
| 8642 | "Connection: keep-alive\r\n" |
| 8643 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8644 | }; |
| 8645 | |
| 8646 | // Lastly, the server responds with the actual content. |
| 8647 | MockRead data_reads[] = { |
| 8648 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8649 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8650 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8651 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8652 | }; |
| 8653 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8654 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8655 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8656 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8657 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8658 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8659 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8660 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8661 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8662 | |
| 8663 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8664 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8665 | } |
| 8666 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8667 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8668 | HttpRequestInfo request; |
| 8669 | request.method = "PUT"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8670 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8671 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8672 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8673 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8674 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8675 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8676 | MockWrite( |
| 8677 | "PUT / HTTP/1.1\r\n" |
| 8678 | "Host: www.example.org\r\n" |
| 8679 | "Connection: keep-alive\r\n" |
| 8680 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8681 | }; |
| 8682 | |
| 8683 | // Lastly, the server responds with the actual content. |
| 8684 | MockRead data_reads[] = { |
| 8685 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8686 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8687 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8688 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8689 | }; |
| 8690 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8691 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8692 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8693 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8694 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8695 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8696 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8697 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8698 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8699 | |
| 8700 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8701 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8702 | } |
| 8703 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8704 | TEST_F(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8705 | HttpRequestInfo request; |
| 8706 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8707 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8708 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8709 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8710 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8711 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8712 | MockWrite data_writes[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 8713 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 8714 | "Host: www.example.org\r\n" |
| 8715 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8716 | }; |
| 8717 | |
| 8718 | // Lastly, the server responds with the actual content. |
| 8719 | MockRead data_reads[] = { |
| 8720 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8721 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8722 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8723 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8724 | }; |
| 8725 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8726 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8727 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8728 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8729 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8730 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8731 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8732 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8733 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8734 | |
| 8735 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8736 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8737 | } |
| 8738 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8739 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8740 | HttpRequestInfo request; |
| 8741 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8742 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8743 | request.load_flags = LOAD_BYPASS_CACHE; |
| 8744 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8745 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8746 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8747 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8748 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8749 | MockWrite( |
| 8750 | "GET / HTTP/1.1\r\n" |
| 8751 | "Host: www.example.org\r\n" |
| 8752 | "Connection: keep-alive\r\n" |
| 8753 | "Pragma: no-cache\r\n" |
| 8754 | "Cache-Control: no-cache\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8755 | }; |
| 8756 | |
| 8757 | // Lastly, the server responds with the actual content. |
| 8758 | MockRead data_reads[] = { |
| 8759 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8760 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8761 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8762 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8763 | }; |
| 8764 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8765 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8766 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8767 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8768 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8769 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8770 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8771 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8772 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8773 | |
| 8774 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8775 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8776 | } |
| 8777 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8778 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlValidateCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8779 | HttpRequestInfo request; |
| 8780 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8781 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8782 | request.load_flags = LOAD_VALIDATE_CACHE; |
| 8783 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8784 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8785 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8786 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8787 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8788 | MockWrite( |
| 8789 | "GET / HTTP/1.1\r\n" |
| 8790 | "Host: www.example.org\r\n" |
| 8791 | "Connection: keep-alive\r\n" |
| 8792 | "Cache-Control: max-age=0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8793 | }; |
| 8794 | |
| 8795 | // Lastly, the server responds with the actual content. |
| 8796 | MockRead data_reads[] = { |
| 8797 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8798 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8799 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8800 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8801 | }; |
| 8802 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8803 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8804 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8805 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8806 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8807 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8808 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8809 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8810 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8811 | |
| 8812 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8813 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8814 | } |
| 8815 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8816 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8817 | HttpRequestInfo request; |
| 8818 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8819 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8820 | request.extra_headers.SetHeader("FooHeader", "Bar"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8821 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8822 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8823 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8824 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8825 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8826 | MockWrite( |
| 8827 | "GET / HTTP/1.1\r\n" |
| 8828 | "Host: www.example.org\r\n" |
| 8829 | "Connection: keep-alive\r\n" |
| 8830 | "FooHeader: Bar\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8831 | }; |
| 8832 | |
| 8833 | // Lastly, the server responds with the actual content. |
| 8834 | MockRead data_reads[] = { |
| 8835 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8836 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8837 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8838 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8839 | }; |
| 8840 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8841 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8842 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8843 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8844 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8845 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8846 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8847 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8848 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8849 | |
| 8850 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8851 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8852 | } |
| 8853 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8854 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8855 | HttpRequestInfo request; |
| 8856 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8857 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8858 | request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 8859 | request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 8860 | request.extra_headers.SetHeader("FoO", "bar"); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8861 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8862 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8863 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8864 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8865 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8866 | MockWrite( |
| 8867 | "GET / HTTP/1.1\r\n" |
| 8868 | "Host: www.example.org\r\n" |
| 8869 | "Connection: keep-alive\r\n" |
| 8870 | "referer: www.foo.com\r\n" |
| 8871 | "hEllo: Kitty\r\n" |
| 8872 | "FoO: bar\r\n\r\n"), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8873 | }; |
| 8874 | |
| 8875 | // Lastly, the server responds with the actual content. |
| 8876 | MockRead data_reads[] = { |
| 8877 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8878 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8879 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8880 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8881 | }; |
| 8882 | |
| 8883 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8884 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8885 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8886 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8887 | TestCompletionCallback callback; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8888 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8889 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8890 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8891 | |
| 8892 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8893 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8894 | } |
| 8895 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8896 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8897 | HttpRequestInfo request; |
| 8898 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8899 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8900 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8901 | session_deps_.proxy_service = |
| 8902 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8903 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8904 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8905 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8906 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8907 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8908 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8909 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 8910 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 8911 | |
| 8912 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8913 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 8914 | MockWrite( |
| 8915 | "GET / HTTP/1.1\r\n" |
| 8916 | "Host: www.example.org\r\n" |
| 8917 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8918 | |
| 8919 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8920 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8921 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8922 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8923 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8924 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8925 | }; |
| 8926 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8927 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8928 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8929 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8930 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8931 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8932 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8933 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8934 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8935 | |
| 8936 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8937 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8938 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8939 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8940 | ASSERT_TRUE(response); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8941 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 8942 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8943 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8944 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8945 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8946 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 8947 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8948 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8949 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8950 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8951 | EXPECT_EQ("Payload", response_text); |
| 8952 | } |
| 8953 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8954 | TEST_F(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8955 | HttpRequestInfo request; |
| 8956 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8957 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8958 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8959 | session_deps_.proxy_service = |
| 8960 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8961 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8962 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8963 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8964 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8965 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8966 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8967 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 8968 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 8969 | |
| 8970 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8971 | MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), |
| 8972 | arraysize(write_buffer)), |
| 8973 | MockWrite( |
| 8974 | "GET / HTTP/1.1\r\n" |
| 8975 | "Host: www.example.org\r\n" |
| 8976 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8977 | |
| 8978 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 8979 | MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), |
| 8980 | arraysize(read_buffer)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8981 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8982 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8983 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8984 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8985 | }; |
| 8986 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8987 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8988 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8989 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8990 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8991 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8992 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8993 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8994 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8995 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8996 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8997 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8998 | |
| 8999 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9000 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9001 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9002 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9003 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9004 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9005 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 9006 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9007 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9008 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9009 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9010 | |
| 9011 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9012 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9013 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9014 | EXPECT_EQ("Payload", response_text); |
| 9015 | } |
| 9016 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9017 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9018 | HttpRequestInfo request; |
| 9019 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9020 | request.url = GURL("http://www.example.org/"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9021 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9022 | session_deps_.proxy_service = |
| 9023 | ProxyService::CreateFixed("socks4://myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9024 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9025 | session_deps_.net_log = &net_log; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9026 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9027 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9028 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9029 | |
| 9030 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 9031 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 9032 | |
| 9033 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9034 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 9035 | MockWrite( |
| 9036 | "GET / HTTP/1.1\r\n" |
| 9037 | "Host: www.example.org\r\n" |
| 9038 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9039 | |
| 9040 | MockRead data_reads[] = { |
| 9041 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
| 9042 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9043 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9044 | MockRead("Payload"), |
| 9045 | MockRead(SYNCHRONOUS, OK) |
| 9046 | }; |
| 9047 | |
| 9048 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9049 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9050 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9051 | |
| 9052 | TestCompletionCallback callback; |
| 9053 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9054 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9055 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9056 | |
| 9057 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9058 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9059 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9060 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9061 | ASSERT_TRUE(response); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9062 | |
| 9063 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9064 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9065 | TestLoadTimingNotReused(load_timing_info, |
| 9066 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 9067 | |
| 9068 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9069 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9070 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9071 | EXPECT_EQ("Payload", response_text); |
| 9072 | } |
| 9073 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9074 | TEST_F(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9075 | HttpRequestInfo request; |
| 9076 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9077 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9078 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9079 | session_deps_.proxy_service = |
| 9080 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9081 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9082 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9083 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9084 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9085 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9086 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9087 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 9088 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9089 | const char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9090 | 0x05, // Version |
| 9091 | 0x01, // Command (CONNECT) |
| 9092 | 0x00, // Reserved. |
| 9093 | 0x03, // Address type (DOMAINNAME). |
| 9094 | 0x0F, // Length of domain (15) |
| 9095 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 9096 | '.', 'o', 'r', 'g', 0x00, 0x50, // 16-bit port (80) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9097 | }; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9098 | const char kSOCKS5OkResponse[] = |
| 9099 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 9100 | |
| 9101 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9102 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 9103 | MockWrite(ASYNC, kSOCKS5OkRequest, arraysize(kSOCKS5OkRequest)), |
| 9104 | MockWrite( |
| 9105 | "GET / HTTP/1.1\r\n" |
| 9106 | "Host: www.example.org\r\n" |
| 9107 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9108 | |
| 9109 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 9110 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 9111 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9112 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9113 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9114 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9115 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9116 | }; |
| 9117 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9118 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9119 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9120 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9121 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9122 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9123 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9124 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9125 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9126 | |
| 9127 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9128 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9129 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9130 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9131 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9132 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9133 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9134 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9135 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9136 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9137 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 9138 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9139 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9140 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9141 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9142 | EXPECT_EQ("Payload", response_text); |
| 9143 | } |
| 9144 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9145 | TEST_F(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9146 | HttpRequestInfo request; |
| 9147 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9148 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9149 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9150 | session_deps_.proxy_service = |
| 9151 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9152 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9153 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9154 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9155 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9156 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9157 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9158 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 9159 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9160 | const unsigned char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9161 | 0x05, // Version |
| 9162 | 0x01, // Command (CONNECT) |
| 9163 | 0x00, // Reserved. |
| 9164 | 0x03, // Address type (DOMAINNAME). |
| 9165 | 0x0F, // Length of domain (15) |
| 9166 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 9167 | '.', 'o', 'r', 'g', 0x01, 0xBB, // 16-bit port (443) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9168 | }; |
| 9169 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9170 | const char kSOCKS5OkResponse[] = |
| 9171 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 9172 | |
| 9173 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9174 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 9175 | MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
| 9176 | arraysize(kSOCKS5OkRequest)), |
| 9177 | MockWrite( |
| 9178 | "GET / HTTP/1.1\r\n" |
| 9179 | "Host: www.example.org\r\n" |
| 9180 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9181 | |
| 9182 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 9183 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 9184 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9185 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9186 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9187 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9188 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9189 | }; |
| 9190 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9191 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9192 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9193 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9194 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9195 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9196 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9197 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9198 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9199 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9200 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9201 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9202 | |
| 9203 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9204 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9205 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9206 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9207 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9208 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9209 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9210 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9211 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9212 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9213 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 9214 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9215 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9216 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9217 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9218 | EXPECT_EQ("Payload", response_text); |
| 9219 | } |
| 9220 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9221 | namespace { |
| 9222 | |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9223 | // Tests that for connection endpoints the group names are correctly set. |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9224 | |
| 9225 | struct GroupNameTest { |
| 9226 | std::string proxy_server; |
| 9227 | std::string url; |
| 9228 | std::string expected_group_name; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9229 | bool ssl; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9230 | }; |
| 9231 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9232 | std::unique_ptr<HttpNetworkSession> SetupSessionForGroupNameTests( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9233 | SpdySessionDependencies* session_deps_) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9234 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9235 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 9236 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9237 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 9238 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9239 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9240 | http_server_properties->SetAlternativeService( |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9241 | url::SchemeHostPort("https", "host.with.alternate", 443), |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 9242 | alternative_service, expiration); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9243 | |
| 9244 | return session; |
| 9245 | } |
| 9246 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9247 | int GroupNameTransactionHelper(const std::string& url, |
| 9248 | HttpNetworkSession* session) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9249 | HttpRequestInfo request; |
| 9250 | request.method = "GET"; |
| 9251 | request.url = GURL(url); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9252 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9253 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9254 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9255 | TestCompletionCallback callback; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9256 | |
| 9257 | // We do not complete this request, the dtor will clean the transaction up. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9258 | return trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9259 | } |
| 9260 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9261 | } // namespace |
| 9262 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9263 | TEST_F(HttpNetworkTransactionTest, GroupNameForDirectConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9264 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9265 | { |
| 9266 | "", // unused |
| 9267 | "http://www.example.org/direct", |
| 9268 | "www.example.org:80", |
| 9269 | false, |
| 9270 | }, |
| 9271 | { |
| 9272 | "", // unused |
| 9273 | "http://[2001:1418:13:1::25]/direct", |
| 9274 | "[2001:1418:13:1::25]:80", |
| 9275 | false, |
| 9276 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9277 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9278 | // SSL Tests |
| 9279 | { |
| 9280 | "", // unused |
| 9281 | "https://www.example.org/direct_ssl", |
| 9282 | "ssl/www.example.org:443", |
| 9283 | true, |
| 9284 | }, |
| 9285 | { |
| 9286 | "", // unused |
| 9287 | "https://[2001:1418:13:1::25]/direct", |
| 9288 | "ssl/[2001:1418:13:1::25]:443", |
| 9289 | true, |
| 9290 | }, |
| 9291 | { |
| 9292 | "", // unused |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9293 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9294 | "ssl/host.with.alternate:443", |
| 9295 | true, |
| 9296 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9297 | }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9298 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 9299 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9300 | session_deps_.proxy_service = |
| 9301 | ProxyService::CreateFixed(tests[i].proxy_server); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9302 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 9303 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9304 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9305 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9306 | CaptureGroupNameTransportSocketPool* transport_conn_pool = |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9307 | new CaptureGroupNameTransportSocketPool(nullptr, nullptr); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9308 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9309 | new CaptureGroupNameSSLSocketPool(nullptr, nullptr); |
| 9310 | auto mock_pool_manager = base::MakeUnique<MockClientSocketPoolManager>(); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 9311 | mock_pool_manager->SetTransportSocketPool(transport_conn_pool); |
| 9312 | mock_pool_manager->SetSSLSocketPool(ssl_conn_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 9313 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9314 | |
| 9315 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9316 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9317 | if (tests[i].ssl) |
| 9318 | EXPECT_EQ(tests[i].expected_group_name, |
| 9319 | ssl_conn_pool->last_group_name_received()); |
| 9320 | else |
| 9321 | EXPECT_EQ(tests[i].expected_group_name, |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9322 | transport_conn_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9323 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9324 | } |
| 9325 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9326 | TEST_F(HttpNetworkTransactionTest, GroupNameForHTTPProxyConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9327 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9328 | { |
| 9329 | "http_proxy", |
| 9330 | "http://www.example.org/http_proxy_normal", |
| 9331 | "www.example.org:80", |
| 9332 | false, |
| 9333 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9334 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9335 | // SSL Tests |
| 9336 | { |
| 9337 | "http_proxy", |
| 9338 | "https://www.example.org/http_connect_ssl", |
| 9339 | "ssl/www.example.org:443", |
| 9340 | true, |
| 9341 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 9342 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9343 | { |
| 9344 | "http_proxy", |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9345 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9346 | "ssl/host.with.alternate:443", |
| 9347 | true, |
| 9348 | }, |
[email protected] | 4549925 | 2013-01-23 17:12:56 | [diff] [blame] | 9349 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9350 | { |
| 9351 | "http_proxy", |
| 9352 | "ftp://ftp.google.com/http_proxy_normal", |
| 9353 | "ftp/ftp.google.com:21", |
| 9354 | false, |
| 9355 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9356 | }; |
| 9357 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 9358 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9359 | session_deps_.proxy_service = |
| 9360 | ProxyService::CreateFixed(tests[i].proxy_server); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9361 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 9362 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9363 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9364 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9365 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9366 | HostPortPair proxy_host("http_proxy", 80); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9367 | CaptureGroupNameHttpProxySocketPool* http_proxy_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9368 | new CaptureGroupNameHttpProxySocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9369 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9370 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9371 | auto mock_pool_manager = base::MakeUnique<MockClientSocketPoolManager>(); |
avi | adef344 | 2016-10-03 18:50:39 | [diff] [blame] | 9372 | mock_pool_manager->SetSocketPoolForHTTPProxy( |
| 9373 | proxy_host, base::WrapUnique(http_proxy_pool)); |
| 9374 | mock_pool_manager->SetSocketPoolForSSLWithProxy( |
| 9375 | proxy_host, base::WrapUnique(ssl_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 9376 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9377 | |
| 9378 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9379 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9380 | if (tests[i].ssl) |
| 9381 | EXPECT_EQ(tests[i].expected_group_name, |
| 9382 | ssl_conn_pool->last_group_name_received()); |
| 9383 | else |
| 9384 | EXPECT_EQ(tests[i].expected_group_name, |
| 9385 | http_proxy_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9386 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9387 | } |
| 9388 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9389 | TEST_F(HttpNetworkTransactionTest, GroupNameForSOCKSConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9390 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9391 | { |
| 9392 | "socks4://socks_proxy:1080", |
| 9393 | "http://www.example.org/socks4_direct", |
| 9394 | "socks4/www.example.org:80", |
| 9395 | false, |
| 9396 | }, |
| 9397 | { |
| 9398 | "socks5://socks_proxy:1080", |
| 9399 | "http://www.example.org/socks5_direct", |
| 9400 | "socks5/www.example.org:80", |
| 9401 | false, |
| 9402 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9403 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9404 | // SSL Tests |
| 9405 | { |
| 9406 | "socks4://socks_proxy:1080", |
| 9407 | "https://www.example.org/socks4_ssl", |
| 9408 | "socks4/ssl/www.example.org:443", |
| 9409 | true, |
| 9410 | }, |
| 9411 | { |
| 9412 | "socks5://socks_proxy:1080", |
| 9413 | "https://www.example.org/socks5_ssl", |
| 9414 | "socks5/ssl/www.example.org:443", |
| 9415 | true, |
| 9416 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 9417 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9418 | { |
| 9419 | "socks4://socks_proxy:1080", |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9420 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9421 | "socks4/ssl/host.with.alternate:443", |
| 9422 | true, |
| 9423 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9424 | }; |
| 9425 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 9426 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9427 | session_deps_.proxy_service = |
| 9428 | ProxyService::CreateFixed(tests[i].proxy_server); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9429 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 9430 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 9431 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9432 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9433 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9434 | HostPortPair proxy_host("socks_proxy", 1080); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9435 | CaptureGroupNameSOCKSSocketPool* socks_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9436 | new CaptureGroupNameSOCKSSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9437 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9438 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9439 | auto mock_pool_manager = base::MakeUnique<MockClientSocketPoolManager>(); |
avi | adef344 | 2016-10-03 18:50:39 | [diff] [blame] | 9440 | mock_pool_manager->SetSocketPoolForSOCKSProxy( |
| 9441 | proxy_host, base::WrapUnique(socks_conn_pool)); |
| 9442 | mock_pool_manager->SetSocketPoolForSSLWithProxy( |
| 9443 | proxy_host, base::WrapUnique(ssl_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 9444 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9445 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9446 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9447 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9448 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9449 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9450 | if (tests[i].ssl) |
| 9451 | EXPECT_EQ(tests[i].expected_group_name, |
| 9452 | ssl_conn_pool->last_group_name_received()); |
| 9453 | else |
| 9454 | EXPECT_EQ(tests[i].expected_group_name, |
| 9455 | socks_conn_pool->last_group_name_received()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9456 | } |
| 9457 | } |
| 9458 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9459 | TEST_F(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9460 | HttpRequestInfo request; |
| 9461 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9462 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9463 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9464 | session_deps_.proxy_service = |
| 9465 | ProxyService::CreateFixed("myproxy:70;foobar:80"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 9466 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 9467 | // This simulates failure resolving all hostnames; that means we will fail |
| 9468 | // connecting to both proxies (myproxy:70 and foobar:80). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9469 | session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 9470 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9471 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9472 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9473 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9474 | TestCompletionCallback callback; |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9475 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9476 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9477 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9478 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9479 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9480 | EXPECT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9481 | } |
| 9482 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9483 | // Base test to make sure that when the load flags for a request specify to |
| 9484 | // bypass the cache, the DNS cache is not used. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9485 | void HttpNetworkTransactionTest::BypassHostCacheOnRefreshHelper( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9486 | int load_flags) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9487 | // Issue a request, asking to bypass the cache(s). |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9488 | HttpRequestInfo request_info; |
| 9489 | request_info.method = "GET"; |
| 9490 | request_info.load_flags = load_flags; |
| 9491 | request_info.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9492 | |
[email protected] | a2c2fb9 | 2009-07-18 07:31:04 | [diff] [blame] | 9493 | // Select a host resolver that does caching. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9494 | session_deps_.host_resolver = base::MakeUnique<MockCachingHostResolver>(); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 9495 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9496 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9497 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9498 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9499 | // 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] | 9500 | AddressList addrlist; |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 9501 | TestCompletionCallback callback; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9502 | std::unique_ptr<HostResolver::Request> request1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9503 | int rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9504 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9505 | DEFAULT_PRIORITY, &addrlist, callback.callback(), &request1, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9506 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9507 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 9508 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9509 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9510 | |
| 9511 | // Verify that it was added to host cache, by doing a subsequent async lookup |
| 9512 | // and confirming it completes synchronously. |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9513 | std::unique_ptr<HostResolver::Request> request2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9514 | rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9515 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9516 | DEFAULT_PRIORITY, &addrlist, callback.callback(), &request2, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9517 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9518 | ASSERT_THAT(rv, IsOk()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9519 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9520 | // 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] | 9521 | // we can tell if the next lookup hit the cache, or the "network". |
| 9522 | // (cache --> success, "network" --> failure). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9523 | session_deps_.host_resolver->rules()->AddSimulatedFailure("www.example.org"); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9524 | |
| 9525 | // Connect up a mock socket which will fail with ERR_UNEXPECTED during the |
| 9526 | // 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] | 9527 | MockRead data_reads[] = { MockRead(SYNCHRONOUS, ERR_UNEXPECTED) }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9528 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9529 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9530 | |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9531 | // Run the request. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9532 | rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9533 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9534 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9535 | |
| 9536 | // If we bypassed the cache, we would have gotten a failure while resolving |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9537 | // "www.example.org". |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9538 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9539 | } |
| 9540 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9541 | // There are multiple load flags that should trigger the host cache bypass. |
| 9542 | // Test each in isolation: |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9543 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh1) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9544 | BypassHostCacheOnRefreshHelper(LOAD_BYPASS_CACHE); |
| 9545 | } |
| 9546 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9547 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh2) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9548 | BypassHostCacheOnRefreshHelper(LOAD_VALIDATE_CACHE); |
| 9549 | } |
| 9550 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9551 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh3) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9552 | BypassHostCacheOnRefreshHelper(LOAD_DISABLE_CACHE); |
| 9553 | } |
| 9554 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9555 | // Make sure we can handle an error when writing the request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9556 | TEST_F(HttpNetworkTransactionTest, RequestWriteError) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9557 | HttpRequestInfo request; |
| 9558 | request.method = "GET"; |
| 9559 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9560 | |
| 9561 | MockWrite write_failure[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9562 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9563 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9564 | StaticSocketDataProvider data(NULL, 0, |
| 9565 | write_failure, arraysize(write_failure)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9566 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9567 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9568 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9569 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9570 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9571 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9572 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9573 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9574 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9575 | |
| 9576 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9577 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9578 | |
| 9579 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9580 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9581 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9582 | } |
| 9583 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9584 | // Check that a connection closed after the start of the headers finishes ok. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9585 | TEST_F(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9586 | HttpRequestInfo request; |
| 9587 | request.method = "GET"; |
| 9588 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9589 | |
| 9590 | MockRead data_reads[] = { |
| 9591 | MockRead("HTTP/1."), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9592 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9593 | }; |
| 9594 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9595 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9596 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9597 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9598 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9599 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9600 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9601 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9602 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9603 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9604 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9605 | |
| 9606 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9607 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9608 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9609 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9610 | ASSERT_TRUE(response); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9611 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9612 | EXPECT_TRUE(response->headers); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9613 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 9614 | |
| 9615 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9616 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9617 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9618 | EXPECT_EQ("", response_data); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9619 | |
| 9620 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9621 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9622 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9623 | } |
| 9624 | |
| 9625 | // Make sure that a dropped connection while draining the body for auth |
| 9626 | // restart does the right thing. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9627 | TEST_F(HttpNetworkTransactionTest, DrainResetOK) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9628 | HttpRequestInfo request; |
| 9629 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9630 | request.url = GURL("http://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9631 | |
| 9632 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9633 | MockWrite( |
| 9634 | "GET / HTTP/1.1\r\n" |
| 9635 | "Host: www.example.org\r\n" |
| 9636 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9637 | }; |
| 9638 | |
| 9639 | MockRead data_reads1[] = { |
| 9640 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 9641 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9642 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9643 | MockRead("Content-Length: 14\r\n\r\n"), |
| 9644 | MockRead("Unauth"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9645 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9646 | }; |
| 9647 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9648 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 9649 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9650 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9651 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9652 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9653 | // be issuing -- the final header line contains the credentials. |
| 9654 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9655 | MockWrite( |
| 9656 | "GET / HTTP/1.1\r\n" |
| 9657 | "Host: www.example.org\r\n" |
| 9658 | "Connection: keep-alive\r\n" |
| 9659 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9660 | }; |
| 9661 | |
| 9662 | // Lastly, the server responds with the actual content. |
| 9663 | MockRead data_reads2[] = { |
| 9664 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9665 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9666 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9667 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9668 | }; |
| 9669 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9670 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 9671 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9672 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9673 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9674 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9675 | TestCompletionCallback callback1; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9676 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9677 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9678 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9679 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9680 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9681 | |
| 9682 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9683 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9684 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9685 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9686 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9687 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9688 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9689 | TestCompletionCallback callback2; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9690 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9691 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9692 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9693 | |
| 9694 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9695 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9696 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9697 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9698 | ASSERT_TRUE(response); |
| 9699 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9700 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9701 | } |
| 9702 | |
| 9703 | // Test HTTPS connections going through a proxy that sends extra data. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9704 | TEST_F(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9705 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9706 | |
| 9707 | HttpRequestInfo request; |
| 9708 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9709 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9710 | |
| 9711 | MockRead proxy_reads[] = { |
| 9712 | MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9713 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9714 | }; |
| 9715 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9716 | StaticSocketDataProvider data(proxy_reads, arraysize(proxy_reads), NULL, 0); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9717 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9718 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9719 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9720 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9721 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9722 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9723 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9724 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9725 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9726 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9727 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9728 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9729 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9730 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9731 | |
| 9732 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9733 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9734 | } |
| 9735 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9736 | TEST_F(HttpNetworkTransactionTest, LargeContentLengthThenClose) { |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9737 | HttpRequestInfo request; |
| 9738 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9739 | request.url = GURL("http://www.example.org/"); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9740 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9741 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9742 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9743 | |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 9744 | MockRead data_reads[] = { |
| 9745 | 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] | 9746 | MockRead(SYNCHRONOUS, OK), |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 9747 | }; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9748 | |
| 9749 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9750 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9751 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9752 | TestCompletionCallback callback; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9753 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9754 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9755 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9756 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9757 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9758 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9759 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9760 | ASSERT_TRUE(response); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9761 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9762 | EXPECT_TRUE(response->headers); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9763 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 9764 | |
| 9765 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9766 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9767 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 9768 | } |
| 9769 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9770 | TEST_F(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 9771 | base::FilePath temp_file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 9772 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path)); |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 9773 | const uint64_t kFakeSize = 100000; // file is actually blank |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 9774 | UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 9775 | overriding_content_length(kFakeSize); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9776 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9777 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 9778 | element_readers.push_back(base::MakeUnique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 9779 | base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 9780 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9781 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9782 | |
| 9783 | HttpRequestInfo request; |
| 9784 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9785 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9786 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9787 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9788 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9789 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9790 | |
| 9791 | MockRead data_reads[] = { |
| 9792 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 9793 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9794 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9795 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9796 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9797 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9798 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9799 | TestCompletionCallback callback; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9800 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9801 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9802 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9803 | |
| 9804 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9805 | EXPECT_THAT(rv, IsError(ERR_UPLOAD_FILE_CHANGED)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9806 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9807 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9808 | ASSERT_TRUE(response); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9809 | |
maksim.sisov | e869bf5 | 2016-06-23 17:11:52 | [diff] [blame] | 9810 | EXPECT_FALSE(response->headers); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9811 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 9812 | base::DeleteFile(temp_file_path, false); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9813 | } |
| 9814 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9815 | TEST_F(HttpNetworkTransactionTest, UploadUnreadableFile) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 9816 | base::FilePath temp_file; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 9817 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9818 | std::string temp_file_content("Unreadable file."); |
lazyboy | 8df84fc | 2017-04-12 02:12:48 | [diff] [blame] | 9819 | ASSERT_EQ(static_cast<int>(temp_file_content.length()), |
| 9820 | base::WriteFile(temp_file, temp_file_content.c_str(), |
| 9821 | temp_file_content.length())); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 9822 | ASSERT_TRUE(base::MakeFileUnreadable(temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9823 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9824 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 9825 | element_readers.push_back(base::MakeUnique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 9826 | base::ThreadTaskRunnerHandle::Get().get(), temp_file, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 9827 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9828 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9829 | |
| 9830 | HttpRequestInfo request; |
| 9831 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9832 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9833 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9834 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 9835 | // If we try to upload an unreadable file, the transaction should fail. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9836 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9837 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9838 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 9839 | StaticSocketDataProvider data(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9840 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9841 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9842 | TestCompletionCallback callback; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9843 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9844 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9845 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9846 | |
| 9847 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9848 | EXPECT_THAT(rv, IsError(ERR_ACCESS_DENIED)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9849 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 9850 | base::DeleteFile(temp_file, false); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9851 | } |
| 9852 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9853 | TEST_F(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9854 | class FakeUploadElementReader : public UploadElementReader { |
| 9855 | public: |
| 9856 | FakeUploadElementReader() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9857 | ~FakeUploadElementReader() override {} |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9858 | |
| 9859 | const CompletionCallback& callback() const { return callback_; } |
| 9860 | |
| 9861 | // UploadElementReader overrides: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9862 | int Init(const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9863 | callback_ = callback; |
| 9864 | return ERR_IO_PENDING; |
| 9865 | } |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 9866 | uint64_t GetContentLength() const override { return 0; } |
| 9867 | uint64_t BytesRemaining() const override { return 0; } |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9868 | int Read(IOBuffer* buf, |
| 9869 | int buf_length, |
| 9870 | const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9871 | return ERR_FAILED; |
| 9872 | } |
| 9873 | |
| 9874 | private: |
| 9875 | CompletionCallback callback_; |
| 9876 | }; |
| 9877 | |
| 9878 | FakeUploadElementReader* fake_reader = new FakeUploadElementReader; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9879 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
| 9880 | element_readers.push_back(base::WrapUnique(fake_reader)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9881 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9882 | |
| 9883 | HttpRequestInfo request; |
| 9884 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9885 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9886 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9887 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9888 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9889 | auto trans = |
| 9890 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9891 | |
| 9892 | StaticSocketDataProvider data; |
| 9893 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9894 | |
| 9895 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9896 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9897 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 9898 | base::RunLoop().RunUntilIdle(); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9899 | |
| 9900 | // Transaction is pending on request body initialization. |
| 9901 | ASSERT_FALSE(fake_reader->callback().is_null()); |
| 9902 | |
| 9903 | // Return Init()'s result after the transaction gets destroyed. |
| 9904 | trans.reset(); |
| 9905 | fake_reader->callback().Run(OK); // Should not crash. |
| 9906 | } |
| 9907 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9908 | // Tests that changes to Auth realms are treated like auth rejections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9909 | TEST_F(HttpNetworkTransactionTest, ChangeAuthRealms) { |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9910 | HttpRequestInfo request; |
| 9911 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9912 | request.url = GURL("http://www.example.org/"); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9913 | |
| 9914 | // First transaction will request a resource and receive a Basic challenge |
| 9915 | // with realm="first_realm". |
| 9916 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9917 | MockWrite( |
| 9918 | "GET / HTTP/1.1\r\n" |
| 9919 | "Host: www.example.org\r\n" |
| 9920 | "Connection: keep-alive\r\n" |
| 9921 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9922 | }; |
| 9923 | MockRead data_reads1[] = { |
| 9924 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 9925 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 9926 | "\r\n"), |
| 9927 | }; |
| 9928 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9929 | // After calling trans.RestartWithAuth(), provide an Authentication header |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9930 | // for first_realm. The server will reject and provide a challenge with |
| 9931 | // second_realm. |
| 9932 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9933 | MockWrite( |
| 9934 | "GET / HTTP/1.1\r\n" |
| 9935 | "Host: www.example.org\r\n" |
| 9936 | "Connection: keep-alive\r\n" |
| 9937 | "Authorization: Basic Zmlyc3Q6YmF6\r\n" |
| 9938 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9939 | }; |
| 9940 | MockRead data_reads2[] = { |
| 9941 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 9942 | "WWW-Authenticate: Basic realm=\"second_realm\"\r\n" |
| 9943 | "\r\n"), |
| 9944 | }; |
| 9945 | |
| 9946 | // This again fails, and goes back to first_realm. Make sure that the |
| 9947 | // entry is removed from cache. |
| 9948 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9949 | MockWrite( |
| 9950 | "GET / HTTP/1.1\r\n" |
| 9951 | "Host: www.example.org\r\n" |
| 9952 | "Connection: keep-alive\r\n" |
| 9953 | "Authorization: Basic c2Vjb25kOmZvdQ==\r\n" |
| 9954 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9955 | }; |
| 9956 | MockRead data_reads3[] = { |
| 9957 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 9958 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 9959 | "\r\n"), |
| 9960 | }; |
| 9961 | |
| 9962 | // Try one last time (with the correct password) and get the resource. |
| 9963 | MockWrite data_writes4[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9964 | MockWrite( |
| 9965 | "GET / HTTP/1.1\r\n" |
| 9966 | "Host: www.example.org\r\n" |
| 9967 | "Connection: keep-alive\r\n" |
| 9968 | "Authorization: Basic Zmlyc3Q6YmFy\r\n" |
| 9969 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9970 | }; |
| 9971 | MockRead data_reads4[] = { |
| 9972 | MockRead("HTTP/1.1 200 OK\r\n" |
| 9973 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9974 | "Content-Length: 5\r\n" |
| 9975 | "\r\n" |
| 9976 | "hello"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9977 | }; |
| 9978 | |
| 9979 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 9980 | data_writes1, arraysize(data_writes1)); |
| 9981 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 9982 | data_writes2, arraysize(data_writes2)); |
| 9983 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 9984 | data_writes3, arraysize(data_writes3)); |
| 9985 | StaticSocketDataProvider data4(data_reads4, arraysize(data_reads4), |
| 9986 | data_writes4, arraysize(data_writes4)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9987 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9988 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 9989 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 9990 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9991 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9992 | TestCompletionCallback callback1; |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9993 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9994 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9995 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9996 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9997 | // Issue the first request with Authorize headers. There should be a |
| 9998 | // password prompt for first_realm waiting to be filled in after the |
| 9999 | // transaction completes. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10000 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10001 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10002 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10003 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10004 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10005 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10006 | const AuthChallengeInfo* challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10007 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10008 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10009 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10010 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 10011 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10012 | |
| 10013 | // Issue the second request with an incorrect password. There should be a |
| 10014 | // password prompt for second_realm waiting to be filled in after the |
| 10015 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10016 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10017 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBaz), |
| 10018 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10019 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10020 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10021 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10022 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10023 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10024 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10025 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10026 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10027 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10028 | EXPECT_EQ("second_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 10029 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10030 | |
| 10031 | // Issue the third request with another incorrect password. There should be |
| 10032 | // a password prompt for first_realm waiting to be filled in. If the password |
| 10033 | // prompt is not present, it indicates that the HttpAuthCacheEntry for |
| 10034 | // first_realm was not correctly removed. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10035 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10036 | rv = trans.RestartWithAuth(AuthCredentials(kSecond, kFou), |
| 10037 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10038 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10039 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10040 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10041 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10042 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10043 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10044 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10045 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10046 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10047 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 10048 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10049 | |
| 10050 | // Issue the fourth request with the correct password and username. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10051 | TestCompletionCallback callback4; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10052 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBar), |
| 10053 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10054 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10055 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10056 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10057 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10058 | ASSERT_TRUE(response); |
| 10059 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10060 | } |
| 10061 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10062 | TEST_F(HttpNetworkTransactionTest, HonorAlternativeServiceHeader) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10063 | MockRead data_reads[] = { |
| 10064 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10065 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10066 | MockRead("\r\n"), |
| 10067 | MockRead("hello world"), |
| 10068 | MockRead(SYNCHRONOUS, OK), |
| 10069 | }; |
| 10070 | |
| 10071 | HttpRequestInfo request; |
| 10072 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10073 | request.url = GURL("https://www.example.org/"); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10074 | |
| 10075 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10076 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10077 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10078 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10079 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10080 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10081 | TestCompletionCallback callback; |
| 10082 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10083 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10084 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10085 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10086 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10087 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10088 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10089 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10090 | HttpServerProperties* http_server_properties = |
| 10091 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10092 | EXPECT_TRUE( |
| 10093 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10094 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10095 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10096 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10097 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10098 | ASSERT_TRUE(response); |
| 10099 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10100 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10101 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10102 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10103 | |
| 10104 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10105 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10106 | EXPECT_EQ("hello world", response_data); |
| 10107 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10108 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 10109 | http_server_properties->GetAlternativeServiceInfos(test_server); |
| 10110 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 10111 | AlternativeService alternative_service(kProtoHTTP2, "mail.example.org", 443); |
| 10112 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame^] | 10113 | alternative_service_info_vector[0].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10114 | } |
| 10115 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10116 | // Regression test for https://crbug.com/615497. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10117 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10118 | DoNotParseAlternativeServiceHeaderOnInsecureRequest) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10119 | MockRead data_reads[] = { |
| 10120 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10121 | MockRead(kAlternativeServiceHttpHeader), |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10122 | MockRead("\r\n"), |
| 10123 | MockRead("hello world"), |
| 10124 | MockRead(SYNCHRONOUS, OK), |
| 10125 | }; |
| 10126 | |
| 10127 | HttpRequestInfo request; |
| 10128 | request.method = "GET"; |
| 10129 | request.url = GURL("http://www.example.org/"); |
| 10130 | request.load_flags = 0; |
| 10131 | |
| 10132 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 10133 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10134 | |
| 10135 | TestCompletionCallback callback; |
| 10136 | |
| 10137 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10138 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10139 | |
| 10140 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10141 | HttpServerProperties* http_server_properties = |
| 10142 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10143 | EXPECT_TRUE( |
| 10144 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10145 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10146 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10147 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10148 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10149 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10150 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10151 | ASSERT_TRUE(response); |
| 10152 | ASSERT_TRUE(response->headers); |
| 10153 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10154 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10155 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10156 | |
| 10157 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10158 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10159 | EXPECT_EQ("hello world", response_data); |
| 10160 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10161 | EXPECT_TRUE( |
| 10162 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10163 | } |
| 10164 | |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 10165 | // HTTP/2 Alternative Services should be disabled by default. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10166 | // TODO(bnc): Remove when https://crbug.com/615413 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10167 | TEST_F(HttpNetworkTransactionTest, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10168 | DisableHTTP2AlternativeServicesWithDifferentHost) { |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 10169 | session_deps_.enable_http2_alternative_service = false; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10170 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10171 | HttpRequestInfo request; |
| 10172 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10173 | request.url = GURL("https://www.example.org/"); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10174 | request.load_flags = 0; |
| 10175 | |
| 10176 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10177 | StaticSocketDataProvider first_data; |
| 10178 | first_data.set_connect_data(mock_connect); |
| 10179 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10180 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10181 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10182 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10183 | |
| 10184 | MockRead data_reads[] = { |
| 10185 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 10186 | MockRead(ASYNC, OK), |
| 10187 | }; |
| 10188 | StaticSocketDataProvider second_data(data_reads, arraysize(data_reads), NULL, |
| 10189 | 0); |
| 10190 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 10191 | |
| 10192 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10193 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10194 | HttpServerProperties* http_server_properties = |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10195 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10196 | AlternativeService alternative_service(kProtoHTTP2, "different.example.org", |
| 10197 | 444); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10198 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 10199 | http_server_properties->SetAlternativeService( |
| 10200 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 10201 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10202 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10203 | TestCompletionCallback callback; |
| 10204 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10205 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10206 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10207 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10208 | } |
| 10209 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10210 | // Regression test for https://crbug.com/615497: |
| 10211 | // Alternative Services should be disabled for http origin. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10212 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10213 | DisableAlternativeServicesForInsecureOrigin) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10214 | HttpRequestInfo request; |
| 10215 | request.method = "GET"; |
| 10216 | request.url = GURL("http://www.example.org/"); |
| 10217 | request.load_flags = 0; |
| 10218 | |
| 10219 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10220 | StaticSocketDataProvider first_data; |
| 10221 | first_data.set_connect_data(mock_connect); |
| 10222 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
| 10223 | |
| 10224 | MockRead data_reads[] = { |
| 10225 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 10226 | MockRead(ASYNC, OK), |
| 10227 | }; |
| 10228 | StaticSocketDataProvider second_data(data_reads, arraysize(data_reads), NULL, |
| 10229 | 0); |
| 10230 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 10231 | |
| 10232 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10233 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10234 | HttpServerProperties* http_server_properties = |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10235 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10236 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10237 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 10238 | http_server_properties->SetAlternativeService( |
| 10239 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 10240 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10241 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10242 | TestCompletionCallback callback; |
| 10243 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10244 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10245 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10246 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10247 | } |
| 10248 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10249 | TEST_F(HttpNetworkTransactionTest, ClearAlternativeServices) { |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10250 | // Set an alternative service for origin. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10251 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10252 | HttpServerProperties* http_server_properties = |
| 10253 | session->http_server_properties(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10254 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10255 | AlternativeService alternative_service(kProtoQUIC, "", 80); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10256 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10257 | http_server_properties->SetAlternativeService( |
| 10258 | test_server, alternative_service, expiration); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10259 | EXPECT_EQ( |
| 10260 | 1u, |
| 10261 | http_server_properties->GetAlternativeServiceInfos(test_server).size()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10262 | |
| 10263 | // Send a clear header. |
| 10264 | MockRead data_reads[] = { |
| 10265 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10266 | MockRead("Alt-Svc: clear\r\n"), |
| 10267 | MockRead("\r\n"), |
| 10268 | MockRead("hello world"), |
| 10269 | MockRead(SYNCHRONOUS, OK), |
| 10270 | }; |
| 10271 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 10272 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10273 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10274 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10275 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10276 | |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10277 | HttpRequestInfo request; |
| 10278 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10279 | request.url = GURL("https://www.example.org/"); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10280 | |
| 10281 | TestCompletionCallback callback; |
| 10282 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10283 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10284 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10285 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10286 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10287 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10288 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10289 | ASSERT_TRUE(response); |
| 10290 | ASSERT_TRUE(response->headers); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10291 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10292 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10293 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10294 | |
| 10295 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10296 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10297 | EXPECT_EQ("hello world", response_data); |
| 10298 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10299 | EXPECT_TRUE( |
| 10300 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10301 | } |
| 10302 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10303 | TEST_F(HttpNetworkTransactionTest, HonorMultipleAlternativeServiceHeaders) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10304 | MockRead data_reads[] = { |
| 10305 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10306 | MockRead("Alt-Svc: h2=\"www.example.com:443\","), |
| 10307 | MockRead("h2=\":1234\"\r\n\r\n"), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10308 | MockRead("hello world"), |
| 10309 | MockRead(SYNCHRONOUS, OK), |
| 10310 | }; |
| 10311 | |
| 10312 | HttpRequestInfo request; |
| 10313 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10314 | request.url = GURL("https://www.example.org/"); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10315 | |
| 10316 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10317 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10318 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10319 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10320 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10321 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10322 | TestCompletionCallback callback; |
| 10323 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10324 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10325 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10326 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10327 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10328 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10329 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10330 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10331 | HttpServerProperties* http_server_properties = |
| 10332 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10333 | EXPECT_TRUE( |
| 10334 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10335 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10336 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10337 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10338 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10339 | ASSERT_TRUE(response); |
| 10340 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10341 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10342 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10343 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10344 | |
| 10345 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10346 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10347 | EXPECT_EQ("hello world", response_data); |
| 10348 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10349 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 10350 | http_server_properties->GetAlternativeServiceInfos(test_server); |
| 10351 | ASSERT_EQ(2u, alternative_service_info_vector.size()); |
| 10352 | |
| 10353 | AlternativeService alternative_service(kProtoHTTP2, "www.example.com", 443); |
| 10354 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame^] | 10355 | alternative_service_info_vector[0].alternative_service()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10356 | AlternativeService alternative_service_2(kProtoHTTP2, "www.example.org", |
| 10357 | 1234); |
| 10358 | EXPECT_EQ(alternative_service_2, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame^] | 10359 | alternative_service_info_vector[1].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10360 | } |
| 10361 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10362 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10363 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10364 | HostPortPair alternative("alternative.example.org", 443); |
| 10365 | std::string origin_url = "https://origin.example.org:443"; |
| 10366 | std::string alternative_url = "https://alternative.example.org:443"; |
| 10367 | |
| 10368 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 10369 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10370 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10371 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10372 | |
| 10373 | // HTTP/1.1 data for request. |
| 10374 | MockWrite http_writes[] = { |
| 10375 | MockWrite("GET / HTTP/1.1\r\n" |
| 10376 | "Host: alternative.example.org\r\n" |
| 10377 | "Connection: keep-alive\r\n\r\n"), |
| 10378 | }; |
| 10379 | |
| 10380 | MockRead http_reads[] = { |
| 10381 | MockRead("HTTP/1.1 200 OK\r\n" |
| 10382 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10383 | "Content-Length: 40\r\n\r\n" |
| 10384 | "first HTTP/1.1 response from alternative"), |
| 10385 | }; |
| 10386 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 10387 | http_writes, arraysize(http_writes)); |
| 10388 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 10389 | |
| 10390 | StaticSocketDataProvider data_refused; |
| 10391 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 10392 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 10393 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10394 | // Set up a QUIC alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10395 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10396 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10397 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10398 | AlternativeService alternative_service(kProtoQUIC, alternative); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10399 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10400 | http_server_properties->SetAlternativeService(server, alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10401 | expiration); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10402 | // Mark the QUIC alternative service as broken. |
| 10403 | http_server_properties->MarkAlternativeServiceBroken(alternative_service); |
| 10404 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10405 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 10406 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10407 | request.method = "GET"; |
| 10408 | request.url = GURL(origin_url); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10409 | TestCompletionCallback callback; |
| 10410 | NetErrorDetails details; |
| 10411 | EXPECT_FALSE(details.quic_broken); |
| 10412 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10413 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10414 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10415 | EXPECT_TRUE(details.quic_broken); |
| 10416 | } |
| 10417 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10418 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicNotBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10419 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10420 | HostPortPair alternative1("alternative1.example.org", 443); |
| 10421 | HostPortPair alternative2("alternative2.example.org", 443); |
| 10422 | std::string origin_url = "https://origin.example.org:443"; |
| 10423 | std::string alternative_url1 = "https://alternative1.example.org:443"; |
| 10424 | std::string alternative_url2 = "https://alternative2.example.org:443"; |
| 10425 | |
| 10426 | // Negotiate HTTP/1.1 with alternative1.example.org. |
| 10427 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10428 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10429 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10430 | |
| 10431 | // HTTP/1.1 data for request. |
| 10432 | MockWrite http_writes[] = { |
| 10433 | MockWrite("GET / HTTP/1.1\r\n" |
| 10434 | "Host: alternative1.example.org\r\n" |
| 10435 | "Connection: keep-alive\r\n\r\n"), |
| 10436 | }; |
| 10437 | |
| 10438 | MockRead http_reads[] = { |
| 10439 | MockRead("HTTP/1.1 200 OK\r\n" |
| 10440 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10441 | "Content-Length: 40\r\n\r\n" |
| 10442 | "first HTTP/1.1 response from alternative1"), |
| 10443 | }; |
| 10444 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 10445 | http_writes, arraysize(http_writes)); |
| 10446 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 10447 | |
| 10448 | StaticSocketDataProvider data_refused; |
| 10449 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 10450 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 10451 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10452 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10453 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10454 | session->http_server_properties(); |
| 10455 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10456 | // Set up two QUIC alternative services for server. |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10457 | AlternativeServiceInfoVector alternative_service_info_vector; |
| 10458 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 10459 | |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10460 | AlternativeService alternative_service1(kProtoQUIC, alternative1); |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10461 | AlternativeServiceInfo alternative_service_info1(alternative_service1, |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10462 | expiration); |
| 10463 | alternative_service_info_vector.push_back(alternative_service_info1); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10464 | AlternativeService alternative_service2(kProtoQUIC, alternative2); |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10465 | AlternativeServiceInfo alternative_service_info2(alternative_service2, |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10466 | expiration); |
| 10467 | alternative_service_info_vector.push_back(alternative_service_info2); |
| 10468 | |
| 10469 | http_server_properties->SetAlternativeServices( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10470 | server, alternative_service_info_vector); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10471 | |
| 10472 | // Mark one of the QUIC alternative service as broken. |
| 10473 | http_server_properties->MarkAlternativeServiceBroken(alternative_service1); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10474 | EXPECT_EQ(2u, |
| 10475 | http_server_properties->GetAlternativeServiceInfos(server).size()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10476 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10477 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 10478 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10479 | request.method = "GET"; |
| 10480 | request.url = GURL(origin_url); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10481 | TestCompletionCallback callback; |
| 10482 | NetErrorDetails details; |
| 10483 | EXPECT_FALSE(details.quic_broken); |
| 10484 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10485 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10486 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10487 | EXPECT_FALSE(details.quic_broken); |
| 10488 | } |
| 10489 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10490 | TEST_F(HttpNetworkTransactionTest, MarkBrokenAlternateProtocolAndFallback) { |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10491 | HttpRequestInfo request; |
| 10492 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10493 | request.url = GURL("https://www.example.org/"); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10494 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10495 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10496 | StaticSocketDataProvider first_data; |
| 10497 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10498 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10499 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10500 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10501 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10502 | |
| 10503 | MockRead data_reads[] = { |
| 10504 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10505 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10506 | MockRead(ASYNC, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10507 | }; |
| 10508 | StaticSocketDataProvider second_data( |
| 10509 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10510 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10511 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10512 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10513 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10514 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10515 | session->http_server_properties(); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10516 | const url::SchemeHostPort server(request.url); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10517 | // Port must be < 1024, or the header will be ignored (since initial port was |
| 10518 | // port 80 (another restricted port). |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 10519 | const AlternativeService alternative_service( |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10520 | kProtoHTTP2, "www.example.org", |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 10521 | 666); // Port is ignored by MockConnect anyway. |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10522 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10523 | http_server_properties->SetAlternativeService(server, alternative_service, |
| 10524 | expiration); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10525 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10526 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10527 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10528 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10529 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10530 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10531 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10532 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10533 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10534 | ASSERT_TRUE(response); |
| 10535 | ASSERT_TRUE(response->headers); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10536 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10537 | |
| 10538 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10539 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10540 | EXPECT_EQ("hello world", response_data); |
| 10541 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10542 | const AlternativeServiceInfoVector alternative_service_info_vector = |
| 10543 | http_server_properties->GetAlternativeServiceInfos(server); |
| 10544 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 10545 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame^] | 10546 | alternative_service_info_vector[0].alternative_service()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10547 | EXPECT_TRUE( |
| 10548 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10549 | } |
| 10550 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10551 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10552 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10553 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10554 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10555 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedBlocked) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10556 | HttpRequestInfo restricted_port_request; |
| 10557 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10558 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10559 | restricted_port_request.load_flags = 0; |
| 10560 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10561 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10562 | StaticSocketDataProvider first_data; |
| 10563 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10564 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10565 | |
| 10566 | MockRead data_reads[] = { |
| 10567 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10568 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10569 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10570 | }; |
| 10571 | StaticSocketDataProvider second_data( |
| 10572 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10573 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10574 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10575 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10576 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10577 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10578 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10579 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10580 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10581 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10582 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10583 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 10584 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10585 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10586 | http_server_properties->SetAlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10587 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10588 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10589 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10590 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10591 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10592 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10593 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 10594 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10595 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10596 | // Invalid change to unrestricted port should fail. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10597 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_REFUSED)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10598 | } |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10599 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10600 | // Ensure that we are allowed to redirect traffic via an alternate protocol to |
| 10601 | // an unrestricted (port >= 1024) when the original traffic was on a restricted |
| 10602 | // port (port < 1024) if we set |enable_user_alternate_protocol_ports|. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10603 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedPermitted) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10604 | session_deps_.enable_user_alternate_protocol_ports = true; |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10605 | |
| 10606 | HttpRequestInfo restricted_port_request; |
| 10607 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10608 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10609 | restricted_port_request.load_flags = 0; |
| 10610 | |
| 10611 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10612 | StaticSocketDataProvider first_data; |
| 10613 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10614 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10615 | |
| 10616 | MockRead data_reads[] = { |
| 10617 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10618 | MockRead("hello world"), |
| 10619 | MockRead(ASYNC, OK), |
| 10620 | }; |
| 10621 | StaticSocketDataProvider second_data( |
| 10622 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10623 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10624 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10625 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10626 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10627 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10628 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10629 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10630 | HttpServerProperties* http_server_properties = |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10631 | session->http_server_properties(); |
| 10632 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10633 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 10634 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10635 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10636 | http_server_properties->SetAlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10637 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10638 | expiration); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10639 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10640 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10641 | TestCompletionCallback callback; |
| 10642 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10643 | EXPECT_EQ(ERR_IO_PENDING, |
| 10644 | trans.Start(&restricted_port_request, callback.callback(), |
| 10645 | NetLogWithSource())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10646 | // Change to unrestricted port should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10647 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10648 | } |
| 10649 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10650 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10651 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10652 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10653 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10654 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedAllowed) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10655 | HttpRequestInfo restricted_port_request; |
| 10656 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10657 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10658 | restricted_port_request.load_flags = 0; |
| 10659 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10660 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10661 | StaticSocketDataProvider first_data; |
| 10662 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10663 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10664 | |
| 10665 | MockRead data_reads[] = { |
| 10666 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10667 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10668 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10669 | }; |
| 10670 | StaticSocketDataProvider second_data( |
| 10671 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10672 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10673 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10674 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10675 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10676 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10677 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10678 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10679 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10680 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10681 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10682 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 10683 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10684 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10685 | http_server_properties->SetAlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10686 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10687 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10688 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10689 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10690 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10691 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10692 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 10693 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10694 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10695 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10696 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10697 | } |
| 10698 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10699 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10700 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10701 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10702 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10703 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed1) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10704 | HttpRequestInfo unrestricted_port_request; |
| 10705 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10706 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10707 | unrestricted_port_request.load_flags = 0; |
| 10708 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10709 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10710 | StaticSocketDataProvider first_data; |
| 10711 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10712 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10713 | |
| 10714 | MockRead data_reads[] = { |
| 10715 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10716 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10717 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10718 | }; |
| 10719 | StaticSocketDataProvider second_data( |
| 10720 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10721 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10722 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10723 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10724 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10725 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10726 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10727 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10728 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10729 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10730 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10731 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 10732 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10733 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10734 | http_server_properties->SetAlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10735 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10736 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10737 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10738 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10739 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10740 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10741 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10742 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10743 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10744 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10745 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10746 | } |
| 10747 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10748 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10749 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10750 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10751 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10752 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed2) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10753 | HttpRequestInfo unrestricted_port_request; |
| 10754 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10755 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10756 | unrestricted_port_request.load_flags = 0; |
| 10757 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10758 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10759 | StaticSocketDataProvider first_data; |
| 10760 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10761 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10762 | |
| 10763 | MockRead data_reads[] = { |
| 10764 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10765 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10766 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10767 | }; |
| 10768 | StaticSocketDataProvider second_data( |
| 10769 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10770 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10771 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10772 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10773 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10774 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10775 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10776 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10777 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10778 | session->http_server_properties(); |
bnc | 0bbb0262 | 2015-07-23 10:06:22 | [diff] [blame] | 10779 | const int kUnrestrictedAlternatePort = 1025; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10780 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 10781 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10782 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10783 | http_server_properties->SetAlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10784 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10785 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10786 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10787 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10788 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10789 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10790 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10791 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10792 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10793 | // Valid change to an unrestricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10794 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10795 | } |
| 10796 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10797 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10798 | // to an unsafe port, and that we resume the second HttpStreamFactoryImpl::Job |
| 10799 | // once the alternate protocol request fails. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10800 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) { |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10801 | HttpRequestInfo request; |
| 10802 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10803 | request.url = GURL("http://www.example.org/"); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10804 | |
| 10805 | // The alternate protocol request will error out before we attempt to connect, |
| 10806 | // so only the standard HTTP request will try to connect. |
| 10807 | MockRead data_reads[] = { |
| 10808 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10809 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10810 | MockRead(ASYNC, OK), |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10811 | }; |
| 10812 | StaticSocketDataProvider data( |
| 10813 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10814 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10815 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10816 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10817 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10818 | HttpServerProperties* http_server_properties = |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10819 | session->http_server_properties(); |
| 10820 | const int kUnsafePort = 7; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10821 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 10822 | kUnsafePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10823 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10824 | http_server_properties->SetAlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10825 | url::SchemeHostPort(request.url), alternative_service, expiration); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10826 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10827 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10828 | TestCompletionCallback callback; |
| 10829 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10830 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10831 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10832 | // The HTTP request should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10833 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10834 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10835 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10836 | ASSERT_TRUE(response); |
| 10837 | ASSERT_TRUE(response->headers); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10838 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10839 | |
| 10840 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10841 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10842 | EXPECT_EQ("hello world", response_data); |
| 10843 | } |
| 10844 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10845 | TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10846 | HttpRequestInfo request; |
| 10847 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10848 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10849 | |
| 10850 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10851 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10852 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10853 | MockRead("\r\n"), |
| 10854 | MockRead("hello world"), |
| 10855 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 10856 | MockRead(ASYNC, OK)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10857 | |
| 10858 | StaticSocketDataProvider first_transaction( |
| 10859 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10860 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10861 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10862 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10863 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10864 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 10865 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10866 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10867 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10868 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10869 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10870 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 10871 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10872 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10873 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10874 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10875 | }; |
| 10876 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10877 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 10878 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10879 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10880 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10881 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10882 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 10883 | NULL, 0, NULL, 0); |
| 10884 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 10885 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10886 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10887 | &hanging_non_alternate_protocol_socket); |
| 10888 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10889 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10890 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10891 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10892 | auto trans = |
| 10893 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10894 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10895 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10896 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10897 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10898 | |
| 10899 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10900 | ASSERT_TRUE(response); |
| 10901 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10902 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10903 | |
| 10904 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10905 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10906 | EXPECT_EQ("hello world", response_data); |
| 10907 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10908 | trans = |
| 10909 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10910 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10911 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10912 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10913 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10914 | |
| 10915 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10916 | ASSERT_TRUE(response); |
| 10917 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 10918 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10919 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10920 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10921 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10922 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10923 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10924 | } |
| 10925 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10926 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10927 | HttpRequestInfo request; |
| 10928 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10929 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10930 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10931 | // First transaction receives Alt-Svc header over HTTP/1.1. |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10932 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10933 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10934 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10935 | MockRead("\r\n"), |
| 10936 | MockRead("hello world"), |
| 10937 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 10938 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10939 | }; |
| 10940 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10941 | StaticSocketDataProvider http11_data(data_reads, arraysize(data_reads), NULL, |
| 10942 | 0); |
| 10943 | session_deps_.socket_factory->AddSocketDataProvider(&http11_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10944 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10945 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
| 10946 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
| 10947 | |
| 10948 | // Second transaction starts an alternative and a non-alternative Job. |
| 10949 | // Both sockets hang. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10950 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 10951 | StaticSocketDataProvider hanging_socket1(NULL, 0, NULL, 0); |
| 10952 | hanging_socket1.set_connect_data(never_finishing_connect); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 10953 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket1); |
| 10954 | |
| 10955 | StaticSocketDataProvider hanging_socket2(NULL, 0, NULL, 0); |
| 10956 | hanging_socket2.set_connect_data(never_finishing_connect); |
| 10957 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket2); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10958 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10959 | // Third transaction starts an alternative and a non-alternative job. |
| 10960 | // The non-alternative job hangs, but the alternative one succeeds. |
| 10961 | // The second transaction, still pending, binds to this socket. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10962 | SpdySerializedFrame req1( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10963 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10964 | SpdySerializedFrame req2( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10965 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 3, LOWEST)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10966 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10967 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 1), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10968 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 10969 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10970 | SpdySerializedFrame data1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 10971 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10972 | SpdySerializedFrame data2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10973 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10974 | CreateMockRead(resp1, 2), CreateMockRead(data1, 3), |
| 10975 | CreateMockRead(resp2, 4), CreateMockRead(data2, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10976 | MockRead(ASYNC, 0, 6), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10977 | }; |
| 10978 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10979 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 10980 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10981 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10982 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 10983 | AddSSLSocketData(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10984 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 10985 | StaticSocketDataProvider hanging_socket3(NULL, 0, NULL, 0); |
| 10986 | hanging_socket3.set_connect_data(never_finishing_connect); |
| 10987 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket3); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10988 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10989 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10990 | TestCompletionCallback callback1; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10991 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10992 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10993 | int rv = trans1.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10994 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10995 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10996 | |
| 10997 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10998 | ASSERT_TRUE(response); |
| 10999 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11000 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11001 | |
| 11002 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11003 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11004 | EXPECT_EQ("hello world", response_data); |
| 11005 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11006 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11007 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11008 | rv = trans2.Start(&request, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11009 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11010 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11011 | TestCompletionCallback callback3; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11012 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11013 | rv = trans3.Start(&request, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11014 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11015 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11016 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
| 11017 | EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11018 | |
| 11019 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11020 | ASSERT_TRUE(response); |
| 11021 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11022 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11023 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11024 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11025 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11026 | EXPECT_EQ("hello!", response_data); |
| 11027 | |
| 11028 | response = trans3.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11029 | ASSERT_TRUE(response); |
| 11030 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11031 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11032 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11033 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11034 | ASSERT_THAT(ReadTransaction(&trans3, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11035 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11036 | } |
| 11037 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11038 | TEST_F(HttpNetworkTransactionTest, StallAlternativeServiceForNpnSpdy) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11039 | HttpRequestInfo request; |
| 11040 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11041 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11042 | |
| 11043 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11044 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11045 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11046 | MockRead("\r\n"), |
| 11047 | MockRead("hello world"), |
| 11048 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11049 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11050 | }; |
| 11051 | |
| 11052 | StaticSocketDataProvider first_transaction( |
| 11053 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11054 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11055 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11056 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11057 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11058 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11059 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11060 | StaticSocketDataProvider hanging_alternate_protocol_socket( |
| 11061 | NULL, 0, NULL, 0); |
| 11062 | hanging_alternate_protocol_socket.set_connect_data( |
| 11063 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11064 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11065 | &hanging_alternate_protocol_socket); |
| 11066 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11067 | // 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] | 11068 | StaticSocketDataProvider second_transaction(data_reads, arraysize(data_reads), |
| 11069 | NULL, 0); |
| 11070 | session_deps_.socket_factory->AddSocketDataProvider(&second_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11071 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11072 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11073 | TestCompletionCallback callback; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11074 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11075 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11076 | auto trans = |
| 11077 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11078 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11079 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11080 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11081 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11082 | |
| 11083 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11084 | ASSERT_TRUE(response); |
| 11085 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11086 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11087 | |
| 11088 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11089 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11090 | EXPECT_EQ("hello world", response_data); |
| 11091 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11092 | trans = |
| 11093 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11094 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11095 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11096 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11097 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11098 | |
| 11099 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11100 | ASSERT_TRUE(response); |
| 11101 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11102 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11103 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11104 | EXPECT_FALSE(response->was_alpn_negotiated); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11105 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11106 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11107 | EXPECT_EQ("hello world", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11108 | } |
| 11109 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11110 | class CapturingProxyResolver : public ProxyResolver { |
| 11111 | public: |
sammc | e90c921 | 2015-05-27 23:43:35 | [diff] [blame] | 11112 | CapturingProxyResolver() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11113 | ~CapturingProxyResolver() override {} |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11114 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11115 | int GetProxyForURL(const GURL& url, |
| 11116 | ProxyInfo* results, |
| 11117 | const CompletionCallback& callback, |
maksim.sisov | 7e15726 | 2016-10-20 11:19:55 | [diff] [blame] | 11118 | std::unique_ptr<Request>* request, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11119 | const NetLogWithSource& net_log) override { |
[email protected] | fae7669f | 2010-08-02 21:49:40 | [diff] [blame] | 11120 | ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, |
| 11121 | HostPortPair("myproxy", 80)); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11122 | results->UseProxyServer(proxy_server); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11123 | resolved_.push_back(url); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11124 | return OK; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11125 | } |
| 11126 | |
[email protected] | 2447640 | 2010-07-20 20:55:17 | [diff] [blame] | 11127 | const std::vector<GURL>& resolved() const { return resolved_; } |
| 11128 | |
| 11129 | private: |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11130 | std::vector<GURL> resolved_; |
| 11131 | |
| 11132 | DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); |
| 11133 | }; |
| 11134 | |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 11135 | class CapturingProxyResolverFactory : public ProxyResolverFactory { |
| 11136 | public: |
| 11137 | explicit CapturingProxyResolverFactory(CapturingProxyResolver* resolver) |
| 11138 | : ProxyResolverFactory(false), resolver_(resolver) {} |
| 11139 | |
| 11140 | int CreateProxyResolver( |
| 11141 | const scoped_refptr<ProxyResolverScriptData>& pac_script, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11142 | std::unique_ptr<ProxyResolver>* resolver, |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 11143 | const net::CompletionCallback& callback, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11144 | std::unique_ptr<Request>* request) override { |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11145 | *resolver = base::MakeUnique<ForwardingProxyResolver>(resolver_); |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 11146 | return OK; |
| 11147 | } |
| 11148 | |
| 11149 | private: |
| 11150 | ProxyResolver* resolver_; |
| 11151 | }; |
| 11152 | |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11153 | // Test that proxy is resolved using the origin url, |
| 11154 | // regardless of the alternative server. |
| 11155 | TEST_F(HttpNetworkTransactionTest, UseOriginNotAlternativeForProxy) { |
| 11156 | // Configure proxy to bypass www.example.org, which is the origin URL. |
| 11157 | ProxyConfig proxy_config; |
| 11158 | proxy_config.proxy_rules().ParseFromString("myproxy:70"); |
| 11159 | proxy_config.proxy_rules().bypass_rules.AddRuleFromString("www.example.org"); |
| 11160 | auto proxy_config_service = |
| 11161 | base::MakeUnique<ProxyConfigServiceFixed>(proxy_config); |
| 11162 | |
| 11163 | CapturingProxyResolver capturing_proxy_resolver; |
| 11164 | auto proxy_resolver_factory = base::MakeUnique<CapturingProxyResolverFactory>( |
| 11165 | &capturing_proxy_resolver); |
| 11166 | |
| 11167 | TestNetLog net_log; |
| 11168 | |
| 11169 | session_deps_.proxy_service = base::MakeUnique<ProxyService>( |
| 11170 | std::move(proxy_config_service), std::move(proxy_resolver_factory), |
| 11171 | &net_log); |
| 11172 | |
| 11173 | session_deps_.net_log = &net_log; |
| 11174 | |
| 11175 | // Configure alternative service with a hostname that is not bypassed by the |
| 11176 | // proxy. |
| 11177 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11178 | HttpServerProperties* http_server_properties = |
| 11179 | session->http_server_properties(); |
| 11180 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 11181 | HostPortPair alternative("www.example.com", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11182 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11183 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 11184 | http_server_properties->SetAlternativeService(server, alternative_service, |
| 11185 | expiration); |
| 11186 | |
| 11187 | // Non-alternative job should hang. |
| 11188 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
| 11189 | StaticSocketDataProvider hanging_alternate_protocol_socket(nullptr, 0, |
| 11190 | nullptr, 0); |
| 11191 | hanging_alternate_protocol_socket.set_connect_data(never_finishing_connect); |
| 11192 | session_deps_.socket_factory->AddSocketDataProvider( |
| 11193 | &hanging_alternate_protocol_socket); |
| 11194 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11195 | AddSSLSocketData(); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11196 | |
| 11197 | HttpRequestInfo request; |
| 11198 | request.method = "GET"; |
| 11199 | request.url = GURL("https://www.example.org/"); |
| 11200 | request.load_flags = 0; |
| 11201 | |
| 11202 | SpdySerializedFrame req( |
| 11203 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
| 11204 | |
| 11205 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
| 11206 | |
| 11207 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 11208 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 11209 | MockRead spdy_reads[] = { |
| 11210 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
| 11211 | }; |
| 11212 | |
| 11213 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11214 | arraysize(spdy_writes)); |
| 11215 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 11216 | |
| 11217 | TestCompletionCallback callback; |
| 11218 | |
| 11219 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 11220 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11221 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11222 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 11223 | |
| 11224 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 11225 | ASSERT_TRUE(response); |
| 11226 | ASSERT_TRUE(response->headers); |
| 11227 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 11228 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11229 | EXPECT_TRUE(response->was_alpn_negotiated); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11230 | |
| 11231 | std::string response_data; |
| 11232 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 11233 | EXPECT_EQ("hello!", response_data); |
| 11234 | |
| 11235 | // Origin host bypasses proxy, no resolution should have happened. |
| 11236 | ASSERT_TRUE(capturing_proxy_resolver.resolved().empty()); |
| 11237 | } |
| 11238 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11239 | TEST_F(HttpNetworkTransactionTest, UseAlternativeServiceForTunneledNpnSpdy) { |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11240 | ProxyConfig proxy_config; |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11241 | proxy_config.set_auto_detect(true); |
| 11242 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 11243 | |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11244 | CapturingProxyResolver capturing_proxy_resolver; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11245 | session_deps_.proxy_service = base::MakeUnique<ProxyService>( |
| 11246 | base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), |
| 11247 | base::MakeUnique<CapturingProxyResolverFactory>( |
| 11248 | &capturing_proxy_resolver), |
| 11249 | nullptr); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11250 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11251 | session_deps_.net_log = &net_log; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11252 | |
| 11253 | HttpRequestInfo request; |
| 11254 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11255 | request.url = GURL("https://www.example.org/"); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11256 | |
| 11257 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11258 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11259 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11260 | MockRead("\r\n"), |
| 11261 | MockRead("hello world"), |
| 11262 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11263 | MockRead(ASYNC, OK), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11264 | }; |
| 11265 | |
| 11266 | StaticSocketDataProvider first_transaction( |
| 11267 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11268 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11269 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11270 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11271 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11272 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11273 | AddSSLSocketData(); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11274 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11275 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11276 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11277 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11278 | MockWrite(ASYNC, 0, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11279 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 11280 | "Host: www.example.org:443\r\n" |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11281 | "Proxy-Connection: keep-alive\r\n\r\n"), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11282 | CreateMockWrite(req, 2), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11283 | }; |
| 11284 | |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11285 | const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 11286 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 11287 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11288 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11289 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11290 | MockRead(ASYNC, 1, kCONNECTResponse), CreateMockRead(resp, 3), |
| 11291 | CreateMockRead(data, 4), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11292 | }; |
| 11293 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11294 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11295 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11296 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11297 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11298 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11299 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 11300 | NULL, 0, NULL, 0); |
| 11301 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 11302 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11303 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11304 | &hanging_non_alternate_protocol_socket); |
| 11305 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11306 | TestCompletionCallback callback; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11307 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11308 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11309 | auto trans = |
| 11310 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11311 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11312 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 11313 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11314 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 11315 | |
| 11316 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 11317 | ASSERT_TRUE(response); |
| 11318 | ASSERT_TRUE(response->headers); |
| 11319 | EXPECT_EQ("HTTP/0.9 200 OK", response->headers->GetStatusLine()); |
| 11320 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11321 | EXPECT_TRUE(response->was_alpn_negotiated); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 11322 | |
| 11323 | std::string response_data; |
| 11324 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 11325 | EXPECT_EQ("hello world", response_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11326 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11327 | trans = |
| 11328 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11329 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11330 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11331 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11332 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11333 | |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 11334 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11335 | ASSERT_TRUE(response); |
| 11336 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11337 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11338 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11339 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11340 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11341 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11342 | EXPECT_EQ("hello!", response_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11343 | ASSERT_EQ(2u, capturing_proxy_resolver.resolved().size()); |
| 11344 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11345 | capturing_proxy_resolver.resolved()[0].spec()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11346 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11347 | capturing_proxy_resolver.resolved()[1].spec()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11348 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11349 | LoadTimingInfo load_timing_info; |
| 11350 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 11351 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11352 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11353 | } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11354 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11355 | TEST_F(HttpNetworkTransactionTest, |
bnc | 1c196c6e | 2016-05-28 13:51:48 | [diff] [blame] | 11356 | UseAlternativeServiceForNpnSpdyWithExistingSpdySession) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11357 | HttpRequestInfo request; |
| 11358 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11359 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11360 | |
| 11361 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11362 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11363 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11364 | MockRead("\r\n"), |
| 11365 | MockRead("hello world"), |
| 11366 | MockRead(ASYNC, OK), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11367 | }; |
| 11368 | |
| 11369 | StaticSocketDataProvider first_transaction( |
| 11370 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11371 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11372 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11373 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11374 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11375 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11376 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11377 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11378 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11379 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11380 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11381 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 11382 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11383 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11384 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11385 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11386 | }; |
| 11387 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11388 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11389 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11390 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11391 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 11392 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11393 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11394 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11395 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11396 | auto trans = |
| 11397 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11398 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11399 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11400 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11401 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11402 | |
| 11403 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11404 | ASSERT_TRUE(response); |
| 11405 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11406 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11407 | |
| 11408 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11409 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11410 | EXPECT_EQ("hello world", response_data); |
| 11411 | |
| 11412 | // Set up an initial SpdySession in the pool to reuse. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11413 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 11414 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 11415 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 11416 | base::WeakPtr<SpdySession> spdy_session = |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11417 | CreateSecureSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 11418 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11419 | trans = |
| 11420 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11421 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11422 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11423 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11424 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11425 | |
| 11426 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11427 | ASSERT_TRUE(response); |
| 11428 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11429 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11430 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11431 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11432 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11433 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11434 | EXPECT_EQ("hello!", response_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11435 | } |
| 11436 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11437 | // GenerateAuthToken is a mighty big test. |
| 11438 | // It tests all permutation of GenerateAuthToken behavior: |
| 11439 | // - Synchronous and Asynchronous completion. |
| 11440 | // - OK or error on completion. |
| 11441 | // - Direct connection, non-authenticating proxy, and authenticating proxy. |
| 11442 | // - HTTP or HTTPS backend (to include proxy tunneling). |
| 11443 | // - Non-authenticating and authenticating backend. |
| 11444 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 11445 | // In all, there are 44 reasonable permuations (for example, if there are |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11446 | // problems generating an auth token for an authenticating proxy, we don't |
| 11447 | // need to test all permutations of the backend server). |
| 11448 | // |
| 11449 | // The test proceeds by going over each of the configuration cases, and |
| 11450 | // potentially running up to three rounds in each of the tests. The TestConfig |
| 11451 | // specifies both the configuration for the test as well as the expectations |
| 11452 | // for the results. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11453 | TEST_F(HttpNetworkTransactionTest, GenerateAuthToken) { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11454 | static const char kServer[] = "http://www.example.com"; |
| 11455 | static const char kSecureServer[] = "https://www.example.com"; |
| 11456 | static const char kProxy[] = "myproxy:70"; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11457 | |
| 11458 | enum AuthTiming { |
| 11459 | AUTH_NONE, |
| 11460 | AUTH_SYNC, |
| 11461 | AUTH_ASYNC, |
| 11462 | }; |
| 11463 | |
| 11464 | const MockWrite kGet( |
| 11465 | "GET / HTTP/1.1\r\n" |
| 11466 | "Host: www.example.com\r\n" |
| 11467 | "Connection: keep-alive\r\n\r\n"); |
| 11468 | const MockWrite kGetProxy( |
| 11469 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11470 | "Host: www.example.com\r\n" |
| 11471 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 11472 | const MockWrite kGetAuth( |
| 11473 | "GET / HTTP/1.1\r\n" |
| 11474 | "Host: www.example.com\r\n" |
| 11475 | "Connection: keep-alive\r\n" |
| 11476 | "Authorization: auth_token\r\n\r\n"); |
| 11477 | const MockWrite kGetProxyAuth( |
| 11478 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11479 | "Host: www.example.com\r\n" |
| 11480 | "Proxy-Connection: keep-alive\r\n" |
| 11481 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 11482 | const MockWrite kGetAuthThroughProxy( |
| 11483 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11484 | "Host: www.example.com\r\n" |
| 11485 | "Proxy-Connection: keep-alive\r\n" |
| 11486 | "Authorization: auth_token\r\n\r\n"); |
| 11487 | const MockWrite kGetAuthWithProxyAuth( |
| 11488 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11489 | "Host: www.example.com\r\n" |
| 11490 | "Proxy-Connection: keep-alive\r\n" |
| 11491 | "Proxy-Authorization: auth_token\r\n" |
| 11492 | "Authorization: auth_token\r\n\r\n"); |
| 11493 | const MockWrite kConnect( |
| 11494 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 11495 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11496 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 11497 | const MockWrite kConnectProxyAuth( |
| 11498 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 11499 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11500 | "Proxy-Connection: keep-alive\r\n" |
| 11501 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 11502 | |
| 11503 | const MockRead kSuccess( |
| 11504 | "HTTP/1.1 200 OK\r\n" |
| 11505 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11506 | "Content-Length: 3\r\n\r\n" |
| 11507 | "Yes"); |
| 11508 | const MockRead kFailure( |
| 11509 | "Should not be called."); |
| 11510 | const MockRead kServerChallenge( |
| 11511 | "HTTP/1.1 401 Unauthorized\r\n" |
| 11512 | "WWW-Authenticate: Mock realm=server\r\n" |
| 11513 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11514 | "Content-Length: 14\r\n\r\n" |
| 11515 | "Unauthorized\r\n"); |
| 11516 | const MockRead kProxyChallenge( |
| 11517 | "HTTP/1.1 407 Unauthorized\r\n" |
| 11518 | "Proxy-Authenticate: Mock realm=proxy\r\n" |
| 11519 | "Proxy-Connection: close\r\n" |
| 11520 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11521 | "Content-Length: 14\r\n\r\n" |
| 11522 | "Unauthorized\r\n"); |
| 11523 | const MockRead kProxyConnected( |
| 11524 | "HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 11525 | |
| 11526 | // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with |
| 11527 | // no constructors, but the C++ compiler on Windows warns about |
| 11528 | // unspecified data in compound literals. So, moved to using constructors, |
| 11529 | // and TestRound's created with the default constructor should not be used. |
| 11530 | struct TestRound { |
| 11531 | TestRound() |
| 11532 | : expected_rv(ERR_UNEXPECTED), |
| 11533 | extra_write(NULL), |
| 11534 | extra_read(NULL) { |
| 11535 | } |
| 11536 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 11537 | int expected_rv_arg) |
| 11538 | : write(write_arg), |
| 11539 | read(read_arg), |
| 11540 | expected_rv(expected_rv_arg), |
| 11541 | extra_write(NULL), |
| 11542 | extra_read(NULL) { |
| 11543 | } |
| 11544 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 11545 | int expected_rv_arg, const MockWrite* extra_write_arg, |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 11546 | const MockRead* extra_read_arg) |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11547 | : write(write_arg), |
| 11548 | read(read_arg), |
| 11549 | expected_rv(expected_rv_arg), |
| 11550 | extra_write(extra_write_arg), |
| 11551 | extra_read(extra_read_arg) { |
| 11552 | } |
| 11553 | MockWrite write; |
| 11554 | MockRead read; |
| 11555 | int expected_rv; |
| 11556 | const MockWrite* extra_write; |
| 11557 | const MockRead* extra_read; |
| 11558 | }; |
| 11559 | |
| 11560 | static const int kNoSSL = 500; |
| 11561 | |
| 11562 | struct TestConfig { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11563 | int line_number; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 11564 | const char* const proxy_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11565 | AuthTiming proxy_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11566 | int first_generate_proxy_token_rv; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 11567 | const char* const server_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11568 | AuthTiming server_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11569 | int first_generate_server_token_rv; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11570 | int num_auth_rounds; |
| 11571 | int first_ssl_round; |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11572 | TestRound rounds[4]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11573 | } test_configs[] = { |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11574 | // Non-authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11575 | {__LINE__, |
| 11576 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11577 | AUTH_NONE, |
| 11578 | OK, |
| 11579 | kServer, |
| 11580 | AUTH_NONE, |
| 11581 | OK, |
| 11582 | 1, |
| 11583 | kNoSSL, |
| 11584 | {TestRound(kGet, kSuccess, OK)}}, |
| 11585 | // Authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11586 | {__LINE__, |
| 11587 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11588 | AUTH_NONE, |
| 11589 | OK, |
| 11590 | kServer, |
| 11591 | AUTH_SYNC, |
| 11592 | OK, |
| 11593 | 2, |
| 11594 | kNoSSL, |
| 11595 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11596 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11597 | {__LINE__, |
| 11598 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11599 | AUTH_NONE, |
| 11600 | OK, |
| 11601 | kServer, |
| 11602 | AUTH_SYNC, |
| 11603 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11604 | 3, |
| 11605 | kNoSSL, |
| 11606 | {TestRound(kGet, kServerChallenge, OK), |
| 11607 | TestRound(kGet, kServerChallenge, OK), |
| 11608 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11609 | {__LINE__, |
| 11610 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11611 | AUTH_NONE, |
| 11612 | OK, |
| 11613 | kServer, |
| 11614 | AUTH_SYNC, |
| 11615 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 11616 | 2, |
| 11617 | kNoSSL, |
| 11618 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11619 | {__LINE__, |
| 11620 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11621 | AUTH_NONE, |
| 11622 | OK, |
| 11623 | kServer, |
| 11624 | AUTH_SYNC, |
| 11625 | ERR_UNDOCUMENTED_SECURITY_LIBRARY_STATUS, |
| 11626 | 2, |
| 11627 | kNoSSL, |
| 11628 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11629 | {__LINE__, |
| 11630 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11631 | AUTH_SYNC, |
| 11632 | ERR_FAILED, |
| 11633 | kServer, |
| 11634 | AUTH_NONE, |
| 11635 | OK, |
| 11636 | 2, |
| 11637 | kNoSSL, |
| 11638 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 11639 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11640 | {__LINE__, |
| 11641 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11642 | AUTH_ASYNC, |
| 11643 | ERR_FAILED, |
| 11644 | kServer, |
| 11645 | AUTH_NONE, |
| 11646 | OK, |
| 11647 | 2, |
| 11648 | kNoSSL, |
| 11649 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 11650 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11651 | {__LINE__, |
| 11652 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11653 | AUTH_NONE, |
| 11654 | OK, |
| 11655 | kServer, |
| 11656 | AUTH_SYNC, |
| 11657 | ERR_FAILED, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11658 | 2, |
| 11659 | kNoSSL, |
| 11660 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11661 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11662 | {__LINE__, |
| 11663 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11664 | AUTH_NONE, |
| 11665 | OK, |
| 11666 | kServer, |
| 11667 | AUTH_ASYNC, |
| 11668 | ERR_FAILED, |
| 11669 | 2, |
| 11670 | kNoSSL, |
| 11671 | {TestRound(kGet, kServerChallenge, OK), |
| 11672 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11673 | {__LINE__, |
| 11674 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11675 | AUTH_NONE, |
| 11676 | OK, |
| 11677 | kServer, |
| 11678 | AUTH_ASYNC, |
| 11679 | OK, |
| 11680 | 2, |
| 11681 | kNoSSL, |
| 11682 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11683 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11684 | {__LINE__, |
| 11685 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11686 | AUTH_NONE, |
| 11687 | OK, |
| 11688 | kServer, |
| 11689 | AUTH_ASYNC, |
| 11690 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11691 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11692 | kNoSSL, |
| 11693 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11694 | // The second round uses a HttpAuthHandlerMock that always succeeds. |
| 11695 | TestRound(kGet, kServerChallenge, OK), |
| 11696 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11697 | // Non-authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11698 | {__LINE__, |
| 11699 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11700 | AUTH_NONE, |
| 11701 | OK, |
| 11702 | kServer, |
| 11703 | AUTH_NONE, |
| 11704 | OK, |
| 11705 | 1, |
| 11706 | kNoSSL, |
| 11707 | {TestRound(kGetProxy, kSuccess, OK)}}, |
| 11708 | // Authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11709 | {__LINE__, |
| 11710 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11711 | AUTH_NONE, |
| 11712 | OK, |
| 11713 | kServer, |
| 11714 | AUTH_SYNC, |
| 11715 | OK, |
| 11716 | 2, |
| 11717 | kNoSSL, |
| 11718 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11719 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11720 | {__LINE__, |
| 11721 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11722 | AUTH_NONE, |
| 11723 | OK, |
| 11724 | kServer, |
| 11725 | AUTH_SYNC, |
| 11726 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11727 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11728 | kNoSSL, |
| 11729 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11730 | TestRound(kGetProxy, kServerChallenge, OK), |
| 11731 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11732 | {__LINE__, |
| 11733 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11734 | AUTH_NONE, |
| 11735 | OK, |
| 11736 | kServer, |
| 11737 | AUTH_ASYNC, |
| 11738 | OK, |
| 11739 | 2, |
| 11740 | kNoSSL, |
| 11741 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11742 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11743 | {__LINE__, |
| 11744 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11745 | AUTH_NONE, |
| 11746 | OK, |
| 11747 | kServer, |
| 11748 | AUTH_ASYNC, |
| 11749 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11750 | 2, |
| 11751 | kNoSSL, |
| 11752 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11753 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11754 | // Non-authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11755 | {__LINE__, |
| 11756 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11757 | AUTH_SYNC, |
| 11758 | OK, |
| 11759 | kServer, |
| 11760 | AUTH_NONE, |
| 11761 | OK, |
| 11762 | 2, |
| 11763 | kNoSSL, |
| 11764 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11765 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11766 | {__LINE__, |
| 11767 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11768 | AUTH_SYNC, |
| 11769 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11770 | kServer, |
| 11771 | AUTH_NONE, |
| 11772 | OK, |
| 11773 | 2, |
| 11774 | kNoSSL, |
| 11775 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11776 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11777 | {__LINE__, |
| 11778 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11779 | AUTH_ASYNC, |
| 11780 | OK, |
| 11781 | kServer, |
| 11782 | AUTH_NONE, |
| 11783 | OK, |
| 11784 | 2, |
| 11785 | kNoSSL, |
| 11786 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11787 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11788 | {__LINE__, |
| 11789 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11790 | AUTH_ASYNC, |
| 11791 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11792 | kServer, |
| 11793 | AUTH_NONE, |
| 11794 | OK, |
| 11795 | 2, |
| 11796 | kNoSSL, |
| 11797 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11798 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11799 | {__LINE__, |
| 11800 | kProxy, |
| 11801 | AUTH_ASYNC, |
| 11802 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11803 | kServer, |
| 11804 | AUTH_NONE, |
| 11805 | OK, |
| 11806 | 3, |
| 11807 | kNoSSL, |
| 11808 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 11809 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 11810 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11811 | // Authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11812 | {__LINE__, |
| 11813 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11814 | AUTH_SYNC, |
| 11815 | OK, |
| 11816 | kServer, |
| 11817 | AUTH_SYNC, |
| 11818 | OK, |
| 11819 | 3, |
| 11820 | kNoSSL, |
| 11821 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11822 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11823 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11824 | {__LINE__, |
| 11825 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11826 | AUTH_SYNC, |
| 11827 | OK, |
| 11828 | kServer, |
| 11829 | AUTH_SYNC, |
| 11830 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11831 | 3, |
| 11832 | kNoSSL, |
| 11833 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11834 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11835 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11836 | {__LINE__, |
| 11837 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11838 | AUTH_ASYNC, |
| 11839 | OK, |
| 11840 | kServer, |
| 11841 | AUTH_SYNC, |
| 11842 | OK, |
| 11843 | 3, |
| 11844 | kNoSSL, |
| 11845 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11846 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11847 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11848 | {__LINE__, |
| 11849 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11850 | AUTH_ASYNC, |
| 11851 | OK, |
| 11852 | kServer, |
| 11853 | AUTH_SYNC, |
| 11854 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11855 | 3, |
| 11856 | kNoSSL, |
| 11857 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11858 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11859 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11860 | {__LINE__, |
| 11861 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11862 | AUTH_SYNC, |
| 11863 | OK, |
| 11864 | kServer, |
| 11865 | AUTH_ASYNC, |
| 11866 | OK, |
| 11867 | 3, |
| 11868 | kNoSSL, |
| 11869 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11870 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11871 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11872 | {__LINE__, |
| 11873 | kProxy, |
| 11874 | AUTH_SYNC, |
| 11875 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11876 | kServer, |
| 11877 | AUTH_ASYNC, |
| 11878 | OK, |
| 11879 | 4, |
| 11880 | kNoSSL, |
| 11881 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 11882 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 11883 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11884 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 11885 | {__LINE__, |
| 11886 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11887 | AUTH_SYNC, |
| 11888 | OK, |
| 11889 | kServer, |
| 11890 | AUTH_ASYNC, |
| 11891 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11892 | 3, |
| 11893 | kNoSSL, |
| 11894 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11895 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11896 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11897 | {__LINE__, |
| 11898 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11899 | AUTH_ASYNC, |
| 11900 | OK, |
| 11901 | kServer, |
| 11902 | AUTH_ASYNC, |
| 11903 | OK, |
| 11904 | 3, |
| 11905 | kNoSSL, |
| 11906 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11907 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11908 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11909 | {__LINE__, |
| 11910 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11911 | AUTH_ASYNC, |
| 11912 | OK, |
| 11913 | kServer, |
| 11914 | AUTH_ASYNC, |
| 11915 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11916 | 3, |
| 11917 | kNoSSL, |
| 11918 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11919 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11920 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11921 | {__LINE__, |
| 11922 | kProxy, |
| 11923 | AUTH_ASYNC, |
| 11924 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11925 | kServer, |
| 11926 | AUTH_ASYNC, |
| 11927 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11928 | 4, |
| 11929 | kNoSSL, |
| 11930 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 11931 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 11932 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11933 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11934 | // Non-authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11935 | {__LINE__, |
| 11936 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11937 | AUTH_NONE, |
| 11938 | OK, |
| 11939 | kSecureServer, |
| 11940 | AUTH_NONE, |
| 11941 | OK, |
| 11942 | 1, |
| 11943 | 0, |
| 11944 | {TestRound(kGet, kSuccess, OK)}}, |
| 11945 | // Authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11946 | {__LINE__, |
| 11947 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11948 | AUTH_NONE, |
| 11949 | OK, |
| 11950 | kSecureServer, |
| 11951 | AUTH_SYNC, |
| 11952 | OK, |
| 11953 | 2, |
| 11954 | 0, |
| 11955 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11956 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11957 | {__LINE__, |
| 11958 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11959 | AUTH_NONE, |
| 11960 | OK, |
| 11961 | kSecureServer, |
| 11962 | AUTH_SYNC, |
| 11963 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11964 | 2, |
| 11965 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11966 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11967 | {__LINE__, |
| 11968 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11969 | AUTH_NONE, |
| 11970 | OK, |
| 11971 | kSecureServer, |
| 11972 | AUTH_ASYNC, |
| 11973 | OK, |
| 11974 | 2, |
| 11975 | 0, |
| 11976 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11977 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11978 | {__LINE__, |
| 11979 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11980 | AUTH_NONE, |
| 11981 | OK, |
| 11982 | kSecureServer, |
| 11983 | AUTH_ASYNC, |
| 11984 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11985 | 2, |
| 11986 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11987 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11988 | // Non-authenticating HTTPS server with a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11989 | {__LINE__, |
| 11990 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11991 | AUTH_NONE, |
| 11992 | OK, |
| 11993 | kSecureServer, |
| 11994 | AUTH_NONE, |
| 11995 | OK, |
| 11996 | 1, |
| 11997 | 0, |
| 11998 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 11999 | // Authenticating HTTPS server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12000 | {__LINE__, |
| 12001 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12002 | AUTH_NONE, |
| 12003 | OK, |
| 12004 | kSecureServer, |
| 12005 | AUTH_SYNC, |
| 12006 | OK, |
| 12007 | 2, |
| 12008 | 0, |
| 12009 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12010 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12011 | {__LINE__, |
| 12012 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12013 | AUTH_NONE, |
| 12014 | OK, |
| 12015 | kSecureServer, |
| 12016 | AUTH_SYNC, |
| 12017 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12018 | 2, |
| 12019 | 0, |
| 12020 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12021 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12022 | {__LINE__, |
| 12023 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12024 | AUTH_NONE, |
| 12025 | OK, |
| 12026 | kSecureServer, |
| 12027 | AUTH_ASYNC, |
| 12028 | OK, |
| 12029 | 2, |
| 12030 | 0, |
| 12031 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12032 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12033 | {__LINE__, |
| 12034 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12035 | AUTH_NONE, |
| 12036 | OK, |
| 12037 | kSecureServer, |
| 12038 | AUTH_ASYNC, |
| 12039 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12040 | 2, |
| 12041 | 0, |
| 12042 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12043 | TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12044 | // Non-Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12045 | {__LINE__, |
| 12046 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12047 | AUTH_SYNC, |
| 12048 | OK, |
| 12049 | kSecureServer, |
| 12050 | AUTH_NONE, |
| 12051 | OK, |
| 12052 | 2, |
| 12053 | 1, |
| 12054 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12055 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12056 | {__LINE__, |
| 12057 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12058 | AUTH_SYNC, |
| 12059 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12060 | kSecureServer, |
| 12061 | AUTH_NONE, |
| 12062 | OK, |
| 12063 | 2, |
| 12064 | kNoSSL, |
| 12065 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12066 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12067 | {__LINE__, |
| 12068 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12069 | AUTH_SYNC, |
| 12070 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 12071 | kSecureServer, |
| 12072 | AUTH_NONE, |
| 12073 | OK, |
| 12074 | 2, |
| 12075 | kNoSSL, |
| 12076 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12077 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12078 | {__LINE__, |
| 12079 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12080 | AUTH_SYNC, |
| 12081 | ERR_UNEXPECTED, |
| 12082 | kSecureServer, |
| 12083 | AUTH_NONE, |
| 12084 | OK, |
| 12085 | 2, |
| 12086 | kNoSSL, |
| 12087 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12088 | TestRound(kConnect, kProxyConnected, ERR_UNEXPECTED)}}, |
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_ASYNC, |
| 12092 | OK, |
| 12093 | kSecureServer, |
| 12094 | AUTH_NONE, |
| 12095 | OK, |
| 12096 | 2, |
| 12097 | 1, |
| 12098 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12099 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
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_ASYNC, |
| 12103 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12104 | kSecureServer, |
| 12105 | AUTH_NONE, |
| 12106 | OK, |
| 12107 | 2, |
| 12108 | kNoSSL, |
| 12109 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12110 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12111 | // Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12112 | {__LINE__, |
| 12113 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12114 | AUTH_SYNC, |
| 12115 | OK, |
| 12116 | kSecureServer, |
| 12117 | AUTH_SYNC, |
| 12118 | OK, |
| 12119 | 3, |
| 12120 | 1, |
| 12121 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12122 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12123 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12124 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12125 | {__LINE__, |
| 12126 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12127 | AUTH_SYNC, |
| 12128 | OK, |
| 12129 | kSecureServer, |
| 12130 | AUTH_SYNC, |
| 12131 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12132 | 3, |
| 12133 | 1, |
| 12134 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12135 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12136 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12137 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12138 | {__LINE__, |
| 12139 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12140 | AUTH_ASYNC, |
| 12141 | OK, |
| 12142 | kSecureServer, |
| 12143 | AUTH_SYNC, |
| 12144 | OK, |
| 12145 | 3, |
| 12146 | 1, |
| 12147 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12148 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12149 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12150 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12151 | {__LINE__, |
| 12152 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12153 | AUTH_ASYNC, |
| 12154 | OK, |
| 12155 | kSecureServer, |
| 12156 | AUTH_SYNC, |
| 12157 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12158 | 3, |
| 12159 | 1, |
| 12160 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12161 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12162 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12163 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12164 | {__LINE__, |
| 12165 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12166 | AUTH_SYNC, |
| 12167 | OK, |
| 12168 | kSecureServer, |
| 12169 | AUTH_ASYNC, |
| 12170 | OK, |
| 12171 | 3, |
| 12172 | 1, |
| 12173 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12174 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12175 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12176 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12177 | {__LINE__, |
| 12178 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12179 | AUTH_SYNC, |
| 12180 | OK, |
| 12181 | kSecureServer, |
| 12182 | AUTH_ASYNC, |
| 12183 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12184 | 3, |
| 12185 | 1, |
| 12186 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12187 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12188 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12189 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12190 | {__LINE__, |
| 12191 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12192 | AUTH_ASYNC, |
| 12193 | OK, |
| 12194 | kSecureServer, |
| 12195 | AUTH_ASYNC, |
| 12196 | OK, |
| 12197 | 3, |
| 12198 | 1, |
| 12199 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12200 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12201 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12202 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12203 | {__LINE__, |
| 12204 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12205 | AUTH_ASYNC, |
| 12206 | OK, |
| 12207 | kSecureServer, |
| 12208 | AUTH_ASYNC, |
| 12209 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12210 | 3, |
| 12211 | 1, |
| 12212 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12213 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12214 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12215 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12216 | {__LINE__, |
| 12217 | kProxy, |
| 12218 | AUTH_ASYNC, |
| 12219 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12220 | kSecureServer, |
| 12221 | AUTH_ASYNC, |
| 12222 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12223 | 4, |
| 12224 | 2, |
| 12225 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12226 | TestRound(kConnect, kProxyChallenge, OK), |
| 12227 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12228 | &kServerChallenge), |
| 12229 | TestRound(kGet, kSuccess, OK)}}, |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12230 | }; |
| 12231 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12232 | for (const auto& test_config : test_configs) { |
| 12233 | SCOPED_TRACE(::testing::Message() << "Test config at " |
| 12234 | << test_config.line_number); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12235 | HttpAuthHandlerMock::Factory* auth_factory( |
| 12236 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12237 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 12238 | SSLInfo empty_ssl_info; |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 12239 | |
| 12240 | // Set up authentication handlers as necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12241 | if (test_config.proxy_auth_timing != AUTH_NONE) { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12242 | for (int n = 0; n < 3; n++) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12243 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 12244 | std::string auth_challenge = "Mock realm=proxy"; |
| 12245 | GURL origin(test_config.proxy_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 12246 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 12247 | auth_challenge.end()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12248 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12249 | empty_ssl_info, origin, |
| 12250 | NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12251 | auth_handler->SetGenerateExpectation( |
| 12252 | test_config.proxy_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12253 | n == 0 ? test_config.first_generate_proxy_token_rv : OK); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12254 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 12255 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12256 | } |
| 12257 | if (test_config.server_auth_timing != AUTH_NONE) { |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 12258 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12259 | std::string auth_challenge = "Mock realm=server"; |
| 12260 | GURL origin(test_config.server_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 12261 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 12262 | auth_challenge.end()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12263 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12264 | empty_ssl_info, origin, |
| 12265 | NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12266 | auth_handler->SetGenerateExpectation( |
| 12267 | test_config.server_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12268 | test_config.first_generate_server_token_rv); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12269 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12270 | |
| 12271 | // The second handler always succeeds. It should only be used where there |
| 12272 | // are multiple auth sessions for server auth in the same network |
| 12273 | // transaction using the same auth scheme. |
| 12274 | std::unique_ptr<HttpAuthHandlerMock> second_handler = |
| 12275 | base::MakeUnique<HttpAuthHandlerMock>(); |
| 12276 | second_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 12277 | empty_ssl_info, origin, |
| 12278 | NetLogWithSource()); |
| 12279 | second_handler->SetGenerateExpectation(true, OK); |
| 12280 | auth_factory->AddMockHandler(second_handler.release(), |
| 12281 | HttpAuth::AUTH_SERVER); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12282 | } |
| 12283 | if (test_config.proxy_url) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12284 | session_deps_.proxy_service = |
| 12285 | ProxyService::CreateFixed(test_config.proxy_url); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12286 | } else { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12287 | session_deps_.proxy_service = ProxyService::CreateDirect(); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12288 | } |
| 12289 | |
| 12290 | HttpRequestInfo request; |
| 12291 | request.method = "GET"; |
| 12292 | request.url = GURL(test_config.server_url); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12293 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12294 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12295 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12296 | SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
| 12297 | |
| 12298 | std::vector<std::vector<MockRead>> mock_reads(1); |
| 12299 | std::vector<std::vector<MockWrite>> mock_writes(1); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12300 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 12301 | SCOPED_TRACE(round); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12302 | const TestRound& read_write_round = test_config.rounds[round]; |
| 12303 | |
| 12304 | // Set up expected reads and writes. |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12305 | mock_reads.back().push_back(read_write_round.read); |
| 12306 | mock_writes.back().push_back(read_write_round.write); |
| 12307 | |
| 12308 | // kProxyChallenge uses Proxy-Connection: close which means that the |
| 12309 | // socket is closed and a new one will be created for the next request. |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 12310 | if (read_write_round.read.data == kProxyChallenge.data) { |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12311 | mock_reads.push_back(std::vector<MockRead>()); |
| 12312 | mock_writes.push_back(std::vector<MockWrite>()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12313 | } |
| 12314 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12315 | if (read_write_round.extra_read) { |
| 12316 | mock_reads.back().push_back(*read_write_round.extra_read); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12317 | } |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12318 | if (read_write_round.extra_write) { |
| 12319 | mock_writes.back().push_back(*read_write_round.extra_write); |
| 12320 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12321 | |
| 12322 | // Add an SSL sequence if necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12323 | if (round >= test_config.first_ssl_round) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12324 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12325 | &ssl_socket_data_provider); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12326 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12327 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12328 | std::vector<std::unique_ptr<StaticSocketDataProvider>> data_providers; |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12329 | for (size_t i = 0; i < mock_reads.size(); ++i) { |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12330 | data_providers.push_back(base::MakeUnique<StaticSocketDataProvider>( |
davidben | 5f8b6bc | 2015-11-25 03:19:54 | [diff] [blame] | 12331 | mock_reads[i].data(), mock_reads[i].size(), mock_writes[i].data(), |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12332 | mock_writes[i].size())); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12333 | session_deps_.socket_factory->AddSocketDataProvider( |
olli.raula | 525048c | 2015-12-10 07:38:32 | [diff] [blame] | 12334 | data_providers.back().get()); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12335 | } |
| 12336 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12337 | // Transaction must be created after DataProviders, so it's destroyed before |
| 12338 | // they are as well. |
| 12339 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 12340 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12341 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 12342 | SCOPED_TRACE(round); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12343 | const TestRound& read_write_round = test_config.rounds[round]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12344 | // Start or restart the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12345 | TestCompletionCallback callback; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12346 | int rv; |
| 12347 | if (round == 0) { |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12348 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12349 | } else { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12350 | rv = trans.RestartWithAuth( |
| 12351 | AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12352 | } |
| 12353 | if (rv == ERR_IO_PENDING) |
| 12354 | rv = callback.WaitForResult(); |
| 12355 | |
| 12356 | // Compare results with expected data. |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12357 | EXPECT_THAT(rv, IsError(read_write_round.expected_rv)); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12358 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | c0c82849 | 2015-05-15 01:25:55 | [diff] [blame] | 12359 | if (read_write_round.expected_rv != OK) { |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12360 | EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
| 12361 | continue; |
| 12362 | } |
| 12363 | if (round + 1 < test_config.num_auth_rounds) { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12364 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12365 | } else { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12366 | EXPECT_FALSE(response->auth_challenge); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12367 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12368 | } |
| 12369 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 12370 | } |
| 12371 | } |
| 12372 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12373 | TEST_F(HttpNetworkTransactionTest, MultiRoundAuth) { |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12374 | // Do multi-round authentication and make sure it works correctly. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12375 | HttpAuthHandlerMock::Factory* auth_factory( |
| 12376 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12377 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12378 | session_deps_.proxy_service = ProxyService::CreateDirect(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12379 | session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
| 12380 | session_deps_.host_resolver->set_synchronous_mode(true); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12381 | |
| 12382 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 12383 | auth_handler->set_connection_based(true); |
| 12384 | std::string auth_challenge = "Mock realm=server"; |
| 12385 | GURL origin("http://www.example.com"); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 12386 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 12387 | auth_challenge.end()); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 12388 | SSLInfo empty_ssl_info; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12389 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12390 | empty_ssl_info, origin, NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12391 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12392 | |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12393 | int rv = OK; |
| 12394 | const HttpResponseInfo* response = NULL; |
| 12395 | HttpRequestInfo request; |
| 12396 | request.method = "GET"; |
| 12397 | request.url = origin; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12398 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12399 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12400 | |
| 12401 | // Use a TCP Socket Pool with only one connection per group. This is used |
| 12402 | // to validate that the TCP socket is not released to the pool between |
| 12403 | // each round of multi-round authentication. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12404 | HttpNetworkSessionPeer session_peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12405 | TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12406 | 50, // Max sockets for pool |
| 12407 | 1, // Max sockets per group |
tbansal | 7b403bcc | 2016-04-13 22:33:21 | [diff] [blame] | 12408 | session_deps_.host_resolver.get(), session_deps_.socket_factory.get(), |
| 12409 | NULL, session_deps_.net_log); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12410 | auto mock_pool_manager = base::MakeUnique<MockClientSocketPoolManager>(); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 12411 | mock_pool_manager->SetTransportSocketPool(transport_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 12412 | session_peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12413 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12414 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12415 | TestCompletionCallback callback; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12416 | |
| 12417 | const MockWrite kGet( |
| 12418 | "GET / HTTP/1.1\r\n" |
| 12419 | "Host: www.example.com\r\n" |
| 12420 | "Connection: keep-alive\r\n\r\n"); |
| 12421 | const MockWrite kGetAuth( |
| 12422 | "GET / HTTP/1.1\r\n" |
| 12423 | "Host: www.example.com\r\n" |
| 12424 | "Connection: keep-alive\r\n" |
| 12425 | "Authorization: auth_token\r\n\r\n"); |
| 12426 | |
| 12427 | const MockRead kServerChallenge( |
| 12428 | "HTTP/1.1 401 Unauthorized\r\n" |
| 12429 | "WWW-Authenticate: Mock realm=server\r\n" |
| 12430 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12431 | "Content-Length: 14\r\n\r\n" |
| 12432 | "Unauthorized\r\n"); |
| 12433 | const MockRead kSuccess( |
| 12434 | "HTTP/1.1 200 OK\r\n" |
| 12435 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12436 | "Content-Length: 3\r\n\r\n" |
| 12437 | "Yes"); |
| 12438 | |
| 12439 | MockWrite writes[] = { |
| 12440 | // First round |
| 12441 | kGet, |
| 12442 | // Second round |
| 12443 | kGetAuth, |
| 12444 | // Third round |
| 12445 | kGetAuth, |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 12446 | // Fourth round |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12447 | kGetAuth, |
| 12448 | // Competing request |
| 12449 | kGet, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12450 | }; |
| 12451 | MockRead reads[] = { |
| 12452 | // First round |
| 12453 | kServerChallenge, |
| 12454 | // Second round |
| 12455 | kServerChallenge, |
| 12456 | // Third round |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 12457 | kServerChallenge, |
| 12458 | // Fourth round |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12459 | kSuccess, |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12460 | // Competing response |
| 12461 | kSuccess, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12462 | }; |
| 12463 | StaticSocketDataProvider data_provider(reads, arraysize(reads), |
| 12464 | writes, arraysize(writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12465 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12466 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 12467 | const char kSocketGroup[] = "www.example.com:80"; |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12468 | |
| 12469 | // First round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12470 | auth_handler->SetGenerateExpectation(false, OK); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12471 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12472 | if (rv == ERR_IO_PENDING) |
| 12473 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12474 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12475 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12476 | ASSERT_TRUE(response); |
| 12477 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12478 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12479 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 12480 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12481 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12482 | // In between rounds, another request comes in for the same domain. |
| 12483 | // It should not be able to grab the TCP socket that trans has already |
| 12484 | // claimed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12485 | HttpNetworkTransaction trans_compete(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12486 | TestCompletionCallback callback_compete; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12487 | rv = trans_compete.Start(&request, callback_compete.callback(), |
| 12488 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12489 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12490 | // callback_compete.WaitForResult at this point would stall forever, |
| 12491 | // since the HttpNetworkTransaction does not release the request back to |
| 12492 | // the pool until after authentication completes. |
| 12493 | |
| 12494 | // Second round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12495 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12496 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12497 | if (rv == ERR_IO_PENDING) |
| 12498 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12499 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12500 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12501 | ASSERT_TRUE(response); |
| 12502 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12503 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12504 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 12505 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12506 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12507 | // Third round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12508 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12509 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12510 | if (rv == ERR_IO_PENDING) |
| 12511 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12512 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12513 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12514 | ASSERT_TRUE(response); |
| 12515 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12516 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12517 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 12518 | auth_handler->state()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 12519 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12520 | // Fourth round of authentication, which completes successfully. |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 12521 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12522 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 12523 | if (rv == ERR_IO_PENDING) |
| 12524 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12525 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12526 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12527 | ASSERT_TRUE(response); |
| 12528 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12529 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12530 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12531 | // In WAIT_FOR_CHALLENGE, although in reality the auth handler is done. A real |
| 12532 | // auth handler should transition to a DONE state in concert with the remote |
| 12533 | // server. But that's not something we can test here with a mock handler. |
| 12534 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_CHALLENGE, |
| 12535 | auth_handler->state()); |
| 12536 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12537 | // Read the body since the fourth round was successful. This will also |
| 12538 | // release the socket back to the pool. |
| 12539 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(50)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12540 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12541 | if (rv == ERR_IO_PENDING) |
| 12542 | rv = callback.WaitForResult(); |
| 12543 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12544 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12545 | EXPECT_EQ(0, rv); |
| 12546 | // There are still 0 idle sockets, since the trans_compete transaction |
| 12547 | // will be handed it immediately after trans releases it to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12548 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12549 | |
| 12550 | // The competing request can now finish. Wait for the headers and then |
| 12551 | // read the body. |
| 12552 | rv = callback_compete.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12553 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12554 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12555 | if (rv == ERR_IO_PENDING) |
| 12556 | rv = callback.WaitForResult(); |
| 12557 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12558 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12559 | EXPECT_EQ(0, rv); |
| 12560 | |
| 12561 | // Finally, the socket is released to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12562 | EXPECT_EQ(1, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12563 | } |
| 12564 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12565 | // This tests the case that a request is issued via http instead of spdy after |
| 12566 | // npn is negotiated. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12567 | TEST_F(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12568 | HttpRequestInfo request; |
| 12569 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12570 | request.url = GURL("https://www.example.org/"); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12571 | |
| 12572 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12573 | MockWrite( |
| 12574 | "GET / HTTP/1.1\r\n" |
| 12575 | "Host: www.example.org\r\n" |
| 12576 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12577 | }; |
| 12578 | |
| 12579 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12580 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12581 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12582 | MockRead("\r\n"), |
| 12583 | MockRead("hello world"), |
| 12584 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12585 | }; |
| 12586 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12587 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12588 | ssl.next_proto = kProtoHTTP11; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12589 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12590 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12591 | |
| 12592 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 12593 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12594 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12595 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12596 | TestCompletionCallback callback; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12597 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12598 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12599 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12600 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12601 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12602 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12603 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12604 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12605 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12606 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12607 | ASSERT_TRUE(response); |
| 12608 | ASSERT_TRUE(response->headers); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12609 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12610 | |
| 12611 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12612 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12613 | EXPECT_EQ("hello world", response_data); |
| 12614 | |
| 12615 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12616 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12617 | } |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12618 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12619 | // Simulate the SSL handshake completing with an NPN negotiation followed by an |
| 12620 | // immediate server closing of the socket. |
| 12621 | // Regression test for https://crbug.com/46369. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12622 | TEST_F(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12623 | HttpRequestInfo request; |
| 12624 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12625 | request.url = GURL("https://www.example.org/"); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12626 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12627 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12628 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12629 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12630 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12631 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 12632 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12633 | MockWrite spdy_writes[] = {CreateMockWrite(req, 1)}; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12634 | |
| 12635 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12636 | MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12637 | }; |
| 12638 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12639 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 12640 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12641 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12642 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12643 | TestCompletionCallback callback; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12644 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12645 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12646 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12647 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12648 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12649 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12650 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12651 | } |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 12652 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 12653 | // A subclass of HttpAuthHandlerMock that records the request URL when |
| 12654 | // it gets it. This is needed since the auth handler may get destroyed |
| 12655 | // before we get a chance to query it. |
| 12656 | class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock { |
| 12657 | public: |
| 12658 | explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {} |
| 12659 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12660 | ~UrlRecordingHttpAuthHandlerMock() override {} |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 12661 | |
| 12662 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12663 | int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 12664 | const HttpRequestInfo* request, |
| 12665 | const CompletionCallback& callback, |
| 12666 | std::string* auth_token) override { |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 12667 | *url_ = request->url; |
| 12668 | return HttpAuthHandlerMock::GenerateAuthTokenImpl( |
| 12669 | credentials, request, callback, auth_token); |
| 12670 | } |
| 12671 | |
| 12672 | private: |
| 12673 | GURL* url_; |
| 12674 | }; |
| 12675 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12676 | // Test that if we cancel the transaction as the connection is completing, that |
| 12677 | // everything tears down correctly. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12678 | TEST_F(HttpNetworkTransactionTest, SimpleCancel) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12679 | // Setup everything about the connection to complete synchronously, so that |
| 12680 | // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
| 12681 | // for is the callback from the HttpStreamRequest. |
| 12682 | // Then cancel the transaction. |
| 12683 | // Verify that we don't crash. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12684 | MockConnect mock_connect(SYNCHRONOUS, OK); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12685 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12686 | MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), |
| 12687 | MockRead(SYNCHRONOUS, "hello world"), |
| 12688 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12689 | }; |
| 12690 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12691 | HttpRequestInfo request; |
| 12692 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12693 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12694 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12695 | session_deps_.host_resolver->set_synchronous_mode(true); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12696 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12697 | auto trans = |
| 12698 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12699 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12700 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 12701 | data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12702 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12703 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12704 | TestCompletionCallback callback; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12705 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12706 | BoundTestNetLog log; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12707 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12708 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12709 | trans.reset(); // Cancel the transaction here. |
| 12710 | |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 12711 | base::RunLoop().RunUntilIdle(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 12712 | } |
| 12713 | |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12714 | // Test that if a transaction is cancelled after receiving the headers, the |
| 12715 | // stream is drained properly and added back to the socket pool. The main |
| 12716 | // purpose of this test is to make sure that an HttpStreamParser can be read |
| 12717 | // from after the HttpNetworkTransaction and the objects it owns have been |
| 12718 | // deleted. |
| 12719 | // See http://crbug.com/368418 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12720 | TEST_F(HttpNetworkTransactionTest, CancelAfterHeaders) { |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12721 | MockRead data_reads[] = { |
| 12722 | MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"), |
| 12723 | MockRead(ASYNC, "Content-Length: 2\r\n"), |
| 12724 | MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"), |
| 12725 | MockRead(ASYNC, "1"), |
| 12726 | // 2 async reads are necessary to trigger a ReadResponseBody call after the |
| 12727 | // HttpNetworkTransaction has been deleted. |
| 12728 | MockRead(ASYNC, "2"), |
| 12729 | MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this. |
| 12730 | }; |
| 12731 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 12732 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12733 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12734 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12735 | |
| 12736 | { |
| 12737 | HttpRequestInfo request; |
| 12738 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12739 | request.url = GURL("http://www.example.org/"); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12740 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12741 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12742 | TestCompletionCallback callback; |
| 12743 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12744 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12745 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12746 | callback.WaitForResult(); |
| 12747 | |
| 12748 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12749 | ASSERT_TRUE(response); |
| 12750 | EXPECT_TRUE(response->headers); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12751 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12752 | |
| 12753 | // The transaction and HttpRequestInfo are deleted. |
| 12754 | } |
| 12755 | |
| 12756 | // Let the HttpResponseBodyDrainer drain the socket. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 12757 | base::RunLoop().RunUntilIdle(); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12758 | |
| 12759 | // Socket should now be idle, waiting to be reused. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12760 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12761 | } |
| 12762 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12763 | // Test a basic GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12764 | TEST_F(HttpNetworkTransactionTest, ProxyGet) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12765 | session_deps_.proxy_service = |
| 12766 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12767 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12768 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12769 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12770 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12771 | HttpRequestInfo request; |
| 12772 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12773 | request.url = GURL("http://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12774 | |
| 12775 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12776 | MockWrite( |
| 12777 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 12778 | "Host: www.example.org\r\n" |
| 12779 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12780 | }; |
| 12781 | |
| 12782 | MockRead data_reads1[] = { |
| 12783 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12784 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 12785 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12786 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12787 | }; |
| 12788 | |
| 12789 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 12790 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12791 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12792 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12793 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12794 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12795 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 12796 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12797 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 12798 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 12799 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12800 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12801 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12802 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12803 | |
| 12804 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12805 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12806 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12807 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12808 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12809 | |
| 12810 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 12811 | EXPECT_EQ(200, response->headers->response_code()); |
| 12812 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 12813 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 12814 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 12815 | HostPortPair::FromString("myproxy:70")), |
| 12816 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 12817 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 12818 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 12819 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12820 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12821 | |
| 12822 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12823 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12824 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12825 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12826 | } |
| 12827 | |
| 12828 | // Test a basic HTTPS GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12829 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGet) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12830 | session_deps_.proxy_service = |
| 12831 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12832 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12833 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12834 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12835 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12836 | HttpRequestInfo request; |
| 12837 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12838 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12839 | |
| 12840 | // Since we have proxy, should try to establish tunnel. |
| 12841 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12842 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 12843 | "Host: www.example.org:443\r\n" |
| 12844 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12845 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12846 | MockWrite("GET / HTTP/1.1\r\n" |
| 12847 | "Host: www.example.org\r\n" |
| 12848 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12849 | }; |
| 12850 | |
| 12851 | MockRead data_reads1[] = { |
| 12852 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 12853 | |
| 12854 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12855 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 12856 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12857 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12858 | }; |
| 12859 | |
| 12860 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 12861 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12862 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12863 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12864 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12865 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12866 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12867 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12868 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 12869 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12870 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 12871 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 12872 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12873 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12874 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12875 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12876 | |
| 12877 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12878 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 12879 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12880 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12881 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 12882 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 12883 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12884 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12885 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 12886 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 12887 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12888 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12889 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12890 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12891 | |
| 12892 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 12893 | EXPECT_EQ(200, response->headers->response_code()); |
| 12894 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 12895 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 12896 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 12897 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 12898 | HostPortPair::FromString("myproxy:70")), |
| 12899 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 12900 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 12901 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 12902 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12903 | |
| 12904 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12905 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12906 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12907 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12908 | } |
| 12909 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12910 | // Test a basic HTTPS GET request through a proxy, connecting to an IPv6 |
| 12911 | // literal host. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12912 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetIPv6) { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12913 | session_deps_.proxy_service = |
| 12914 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 12915 | BoundTestNetLog log; |
| 12916 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12917 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12918 | |
| 12919 | HttpRequestInfo request; |
| 12920 | request.method = "GET"; |
| 12921 | request.url = GURL("https://[::1]:443/"); |
| 12922 | |
| 12923 | // Since we have proxy, should try to establish tunnel. |
| 12924 | MockWrite data_writes1[] = { |
| 12925 | MockWrite("CONNECT [::1]:443 HTTP/1.1\r\n" |
| 12926 | "Host: [::1]:443\r\n" |
| 12927 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 12928 | |
| 12929 | MockWrite("GET / HTTP/1.1\r\n" |
| 12930 | "Host: [::1]\r\n" |
| 12931 | "Connection: keep-alive\r\n\r\n"), |
| 12932 | }; |
| 12933 | |
| 12934 | MockRead data_reads1[] = { |
| 12935 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 12936 | |
| 12937 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12938 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 12939 | MockRead("Content-Length: 100\r\n\r\n"), |
| 12940 | MockRead(SYNCHRONOUS, OK), |
| 12941 | }; |
| 12942 | |
| 12943 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 12944 | data_writes1, arraysize(data_writes1)); |
| 12945 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 12946 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12947 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12948 | |
| 12949 | TestCompletionCallback callback1; |
| 12950 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12951 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12952 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12953 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12954 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12955 | |
| 12956 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12957 | EXPECT_THAT(rv, IsOk()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12958 | TestNetLogEntry::List entries; |
| 12959 | log.GetEntries(&entries); |
| 12960 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 12961 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 12962 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12963 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 12964 | entries, pos, |
| 12965 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 12966 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12967 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12968 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12969 | ASSERT_TRUE(response); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12970 | |
| 12971 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 12972 | EXPECT_EQ(200, response->headers->response_code()); |
| 12973 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 12974 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 12975 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 12976 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 12977 | HostPortPair::FromString("myproxy:70")), |
| 12978 | response->proxy_server); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12979 | |
| 12980 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12981 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12982 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12983 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 12984 | } |
| 12985 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12986 | // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 12987 | // while establishing the tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12988 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12989 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12990 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12991 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12992 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12993 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12994 | HttpRequestInfo request; |
| 12995 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12996 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12997 | |
| 12998 | // Since we have proxy, should try to establish tunnel. |
| 12999 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13000 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 13001 | "Host: www.example.org:443\r\n" |
| 13002 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13003 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13004 | MockWrite("GET / HTTP/1.1\r\n" |
| 13005 | "Host: www.example.org\r\n" |
| 13006 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13007 | }; |
| 13008 | |
| 13009 | MockRead data_reads1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13010 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13011 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13012 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13013 | }; |
| 13014 | |
| 13015 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 13016 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13017 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13018 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13019 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13020 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13021 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13022 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13023 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13024 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13025 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13026 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13027 | |
| 13028 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13029 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 13030 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 13031 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13032 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13033 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 13034 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13035 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 13036 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13037 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 13038 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13039 | } |
| 13040 | |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13041 | // Test for crbug.com/55424. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13042 | TEST_F(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13043 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13044 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13045 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13046 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13047 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13048 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13049 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13050 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13051 | }; |
| 13052 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13053 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 13054 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13055 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13056 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13057 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13058 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13059 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13060 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13061 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13062 | |
| 13063 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13064 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 13065 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 13066 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13067 | base::WeakPtr<SpdySession> spdy_session = |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13068 | CreateSecureSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13069 | |
| 13070 | HttpRequestInfo request; |
| 13071 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13072 | request.url = GURL("https://www.example.org/"); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13073 | |
| 13074 | // This is the important line that marks this as a preconnect. |
| 13075 | request.motivation = HttpRequestInfo::PRECONNECT_MOTIVATED; |
| 13076 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13077 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13078 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13079 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13080 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13081 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13082 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13083 | } |
| 13084 | |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13085 | // Given a net error, cause that error to be returned from the first Write() |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13086 | // call and verify that the HttpNetworkTransaction fails with that error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13087 | void HttpNetworkTransactionTest::CheckErrorIsPassedBack( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13088 | int error, IoMode mode) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13089 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13090 | request_info.url = GURL("https://www.example.com/"); |
| 13091 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13092 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13093 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13094 | SSLSocketDataProvider ssl_data(mode, OK); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13095 | MockWrite data_writes[] = { |
| 13096 | MockWrite(mode, error), |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13097 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13098 | StaticSocketDataProvider data(NULL, 0, data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13099 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13100 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13101 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13102 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13103 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13104 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13105 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13106 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13107 | if (rv == ERR_IO_PENDING) |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13108 | rv = callback.WaitForResult(); |
| 13109 | ASSERT_EQ(error, rv); |
| 13110 | } |
| 13111 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13112 | TEST_F(HttpNetworkTransactionTest, SSLWriteCertError) { |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13113 | // Just check a grab bag of cert errors. |
| 13114 | static const int kErrors[] = { |
| 13115 | ERR_CERT_COMMON_NAME_INVALID, |
| 13116 | ERR_CERT_AUTHORITY_INVALID, |
| 13117 | ERR_CERT_DATE_INVALID, |
| 13118 | }; |
| 13119 | for (size_t i = 0; i < arraysize(kErrors); i++) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13120 | CheckErrorIsPassedBack(kErrors[i], ASYNC); |
| 13121 | CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13122 | } |
| 13123 | } |
| 13124 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13125 | // Ensure that a client certificate is removed from the SSL client auth |
| 13126 | // cache when: |
| 13127 | // 1) No proxy is involved. |
| 13128 | // 2) TLS False Start is disabled. |
| 13129 | // 3) The initial TLS handshake requests a client certificate. |
| 13130 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13131 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_NoFalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13132 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13133 | request_info.url = GURL("https://www.example.com/"); |
| 13134 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13135 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13136 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13137 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13138 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13139 | |
| 13140 | // [ssl_]data1 contains the data for the first SSL handshake. When a |
| 13141 | // CertificateRequest is received for the first time, the handshake will |
| 13142 | // be aborted to allow the caller to provide a certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13143 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13144 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13145 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13146 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13147 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13148 | |
| 13149 | // [ssl_]data2 contains the data for the second SSL handshake. When TLS |
| 13150 | // False Start is not being used, the result of the SSL handshake will be |
| 13151 | // returned as part of the SSLClientSocket::Connect() call. This test |
| 13152 | // matches the result of a server sending a handshake_failure alert, |
| 13153 | // rather than a Finished message, because it requires a client |
| 13154 | // certificate and none was supplied. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13155 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13156 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13157 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13158 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13159 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13160 | |
| 13161 | // [ssl_]data3 contains the data for the third SSL handshake. When a |
| 13162 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 13163 | // HttpNetworkTransaction will attempt to fallback to TLSv1.1 if the previous |
| 13164 | // connection was attempted with TLSv1.2. This is transparent to the caller |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13165 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 13166 | // requiring a client certificate, this fallback handshake should also |
| 13167 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13168 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13169 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13170 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13171 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13172 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13173 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13174 | // [ssl_]data4 contains the data for the fourth SSL handshake. When a |
| 13175 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 13176 | // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous |
| 13177 | // connection was attempted with TLSv1.1. This is transparent to the caller |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13178 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 13179 | // requiring a client certificate, this fallback handshake should also |
| 13180 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13181 | SSLSocketDataProvider ssl_data4(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13182 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13183 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13184 | StaticSocketDataProvider data4(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13185 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13186 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13187 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13188 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13189 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13190 | // Begin the SSL handshake with the peer. This consumes ssl_data1. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13191 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13192 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13193 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13194 | |
| 13195 | // Complete the SSL handshake, which should abort due to requiring a |
| 13196 | // client certificate. |
| 13197 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13198 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13199 | |
| 13200 | // Indicate that no certificate should be supplied. From the perspective |
| 13201 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 13202 | // certificate, so this is the same as supply a |
| 13203 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13204 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13205 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13206 | |
| 13207 | // Ensure the certificate was added to the client auth cache before |
| 13208 | // allowing the connection to continue restarting. |
| 13209 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13210 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13211 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13212 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13213 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13214 | |
| 13215 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13216 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 13217 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13218 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13219 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13220 | |
| 13221 | // Ensure that the client certificate is removed from the cache on a |
| 13222 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13223 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13224 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13225 | } |
| 13226 | |
| 13227 | // Ensure that a client certificate is removed from the SSL client auth |
| 13228 | // cache when: |
| 13229 | // 1) No proxy is involved. |
| 13230 | // 2) TLS False Start is enabled. |
| 13231 | // 3) The initial TLS handshake requests a client certificate. |
| 13232 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13233 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_FalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13234 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13235 | request_info.url = GURL("https://www.example.com/"); |
| 13236 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13237 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13238 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13239 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13240 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13241 | |
| 13242 | // When TLS False Start is used, SSLClientSocket::Connect() calls will |
| 13243 | // return successfully after reading up to the peer's Certificate message. |
| 13244 | // This is to allow the caller to call SSLClientSocket::Write(), which can |
| 13245 | // enqueue application data to be sent in the same packet as the |
| 13246 | // ChangeCipherSpec and Finished messages. |
| 13247 | // The actual handshake will be finished when SSLClientSocket::Read() is |
| 13248 | // called, which expects to process the peer's ChangeCipherSpec and |
| 13249 | // Finished messages. If there was an error negotiating with the peer, |
| 13250 | // such as due to the peer requiring a client certificate when none was |
| 13251 | // supplied, the alert sent by the peer won't be processed until Read() is |
| 13252 | // called. |
| 13253 | |
| 13254 | // Like the non-False Start case, when a client certificate is requested by |
| 13255 | // the peer, the handshake is aborted during the Connect() call. |
| 13256 | // [ssl_]data1 represents the initial SSL handshake with the peer. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13257 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13258 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13259 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13260 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13261 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13262 | |
| 13263 | // When a client certificate is supplied, Connect() will not be aborted |
| 13264 | // when the peer requests the certificate. Instead, the handshake will |
| 13265 | // artificially succeed, allowing the caller to write the HTTP request to |
| 13266 | // the socket. The handshake messages are not processed until Read() is |
| 13267 | // called, which then detects that the handshake was aborted, due to the |
| 13268 | // peer sending a handshake_failure because it requires a client |
| 13269 | // certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13270 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13271 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13272 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13273 | MockRead data2_reads[] = { |
| 13274 | MockRead(ASYNC /* async */, ERR_SSL_PROTOCOL_ERROR), |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13275 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13276 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13277 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13278 | |
| 13279 | // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13280 | // the data for the SSL handshake once the TLSv1.1 connection falls back to |
| 13281 | // TLSv1. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13282 | SSLSocketDataProvider ssl_data3(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13283 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13284 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13285 | StaticSocketDataProvider data3(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13286 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13287 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13288 | // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection |
| 13289 | // falls back to SSLv3. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13290 | SSLSocketDataProvider ssl_data4(ASYNC, OK); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13291 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13292 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13293 | StaticSocketDataProvider data4(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13294 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13295 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 13296 | // Need one more if TLSv1.2 is enabled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13297 | SSLSocketDataProvider ssl_data5(ASYNC, OK); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 13298 | ssl_data5.cert_request_info = cert_request.get(); |
| 13299 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13300 | StaticSocketDataProvider data5(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 13301 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 13302 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13303 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13304 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13305 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13306 | // Begin the initial SSL handshake. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13307 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13308 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13309 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13310 | |
| 13311 | // Complete the SSL handshake, which should abort due to requiring a |
| 13312 | // client certificate. |
| 13313 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13314 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13315 | |
| 13316 | // Indicate that no certificate should be supplied. From the perspective |
| 13317 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 13318 | // certificate, so this is the same as supply a |
| 13319 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13320 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13321 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13322 | |
| 13323 | // Ensure the certificate was added to the client auth cache before |
| 13324 | // allowing the connection to continue restarting. |
| 13325 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13326 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13327 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13328 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13329 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13330 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13331 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13332 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 13333 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13334 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13335 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13336 | |
| 13337 | // Ensure that the client certificate is removed from the cache on a |
| 13338 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13339 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13340 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13341 | } |
| 13342 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13343 | // Ensure that a client certificate is removed from the SSL client auth |
| 13344 | // cache when: |
| 13345 | // 1) An HTTPS proxy is involved. |
| 13346 | // 3) The HTTPS proxy requests a client certificate. |
| 13347 | // 4) The client supplies an invalid/unacceptable certificate for the |
| 13348 | // proxy. |
| 13349 | // The test is repeated twice, first for connecting to an HTTPS endpoint, |
| 13350 | // then for connecting to an HTTP endpoint. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13351 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 13352 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13353 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13354 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13355 | |
| 13356 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13357 | cert_request->host_and_port = HostPortPair("proxy", 70); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13358 | |
| 13359 | // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of |
| 13360 | // [ssl_]data[1-3]. Rather than represending the endpoint |
| 13361 | // (www.example.com:443), they represent failures with the HTTPS proxy |
| 13362 | // (proxy:70). |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13363 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13364 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13365 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13366 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13367 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13368 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13369 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13370 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13371 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13372 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13373 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13374 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13375 | // TODO(wtc): find out why this unit test doesn't need [ssl_]data3. |
| 13376 | #if 0 |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13377 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13378 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13379 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13380 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13381 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13382 | #endif |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13383 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13384 | HttpRequestInfo requests[2]; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13385 | requests[0].url = GURL("https://www.example.com/"); |
| 13386 | requests[0].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13387 | requests[0].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13388 | |
| 13389 | requests[1].url = GURL("http://www.example.com/"); |
| 13390 | requests[1].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13391 | requests[1].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13392 | |
| 13393 | for (size_t i = 0; i < arraysize(requests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13394 | session_deps_.socket_factory->ResetNextMockIndexes(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13395 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13396 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13397 | |
| 13398 | // Begin the SSL handshake with the proxy. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13399 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13400 | int rv = trans.Start(&requests[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13401 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13402 | |
| 13403 | // Complete the SSL handshake, which should abort due to requiring a |
| 13404 | // client certificate. |
| 13405 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13406 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13407 | |
| 13408 | // Indicate that no certificate should be supplied. From the perspective |
| 13409 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 13410 | // certificate, so this is the same as supply a |
| 13411 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13412 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13413 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13414 | |
| 13415 | // Ensure the certificate was added to the client auth cache before |
| 13416 | // allowing the connection to continue restarting. |
| 13417 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13418 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13419 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13420 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13421 | ASSERT_FALSE(client_cert); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13422 | // Ensure the certificate was NOT cached for the endpoint. This only |
| 13423 | // applies to HTTPS requests, but is fine to check for HTTP requests. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13424 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13425 | HostPortPair("www.example.com", 443), &client_cert, |
| 13426 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13427 | |
| 13428 | // Restart the handshake. This will consume ssl_data2, which fails, and |
| 13429 | // then consume ssl_data3, which should also fail. The result code is |
| 13430 | // checked against what ssl_data3 should return. |
| 13431 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13432 | ASSERT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13433 | |
| 13434 | // Now that the new handshake has failed, ensure that the client |
| 13435 | // certificate was removed from the client auth cache. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13436 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13437 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13438 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13439 | HostPortPair("www.example.com", 443), &client_cert, |
| 13440 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13441 | } |
| 13442 | } |
| 13443 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13444 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPooling) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13445 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13446 | session_deps_.host_resolver = base::MakeUnique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13447 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13448 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13449 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13450 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13451 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13452 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13453 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13454 | SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13455 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13456 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13457 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13458 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13459 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13460 | SpdySerializedFrame host1_resp_body( |
| 13461 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13462 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13463 | SpdySerializedFrame host2_resp_body( |
| 13464 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13465 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13466 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 13467 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13468 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13469 | }; |
| 13470 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 13471 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13472 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13473 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 13474 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13475 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13476 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 13477 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13478 | HttpRequestInfo request1; |
| 13479 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13480 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13481 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13482 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13483 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13484 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13485 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13486 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13487 | |
| 13488 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13489 | ASSERT_TRUE(response); |
| 13490 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13491 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13492 | |
| 13493 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13494 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13495 | EXPECT_EQ("hello!", response_data); |
| 13496 | |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13497 | // Preload mail.example.com into HostCache. |
| 13498 | HostPortPair host_port("mail.example.com", 443); |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 13499 | HostResolver::RequestInfo resolve_info(host_port); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13500 | AddressList ignored; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 13501 | std::unique_ptr<HostResolver::Request> request; |
| 13502 | rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 13503 | &ignored, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13504 | &request, NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13505 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 13506 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13507 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13508 | |
| 13509 | HttpRequestInfo request2; |
| 13510 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13511 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13512 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13513 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13514 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13515 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13516 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13517 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13518 | |
| 13519 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13520 | ASSERT_TRUE(response); |
| 13521 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13522 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13523 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13524 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13525 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13526 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13527 | } |
| 13528 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13529 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) { |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13530 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13531 | session_deps_.host_resolver = base::MakeUnique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13532 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13533 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13534 | AddSSLSocketData(); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13535 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13536 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13537 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13538 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13539 | SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13540 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13541 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13542 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13543 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13544 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13545 | SpdySerializedFrame host1_resp_body( |
| 13546 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13547 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13548 | SpdySerializedFrame host2_resp_body( |
| 13549 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13550 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13551 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 13552 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13553 | MockRead(ASYNC, 0, 6), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13554 | }; |
| 13555 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 13556 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13557 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13558 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 13559 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13560 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13561 | |
| 13562 | TestCompletionCallback callback; |
| 13563 | HttpRequestInfo request1; |
| 13564 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13565 | request1.url = GURL("https://www.example.org/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13566 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13567 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13568 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13569 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13570 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13571 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13572 | |
| 13573 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13574 | ASSERT_TRUE(response); |
| 13575 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13576 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13577 | |
| 13578 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13579 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13580 | EXPECT_EQ("hello!", response_data); |
| 13581 | |
| 13582 | HttpRequestInfo request2; |
| 13583 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13584 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13585 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13586 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13587 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13588 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13589 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13590 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13591 | |
| 13592 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13593 | ASSERT_TRUE(response); |
| 13594 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13595 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13596 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13597 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13598 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13599 | EXPECT_EQ("hello!", response_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13600 | } |
| 13601 | |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 13602 | // Regression test for https://crbug.com/546991. |
| 13603 | // The server might not be able to serve an IP pooled request, and might send a |
| 13604 | // 421 Misdirected Request response status to indicate this. |
| 13605 | // HttpNetworkTransaction should reset the request and retry without IP pooling. |
| 13606 | TEST_F(HttpNetworkTransactionTest, RetryWithoutConnectionPooling) { |
| 13607 | // Two hosts resolve to the same IP address. |
| 13608 | const std::string ip_addr = "1.2.3.4"; |
| 13609 | IPAddress ip; |
| 13610 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 13611 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 13612 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13613 | session_deps_.host_resolver = base::MakeUnique<MockCachingHostResolver>(); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 13614 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 13615 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 13616 | |
| 13617 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13618 | |
| 13619 | // Two requests on the first connection. |
| 13620 | SpdySerializedFrame req1( |
| 13621 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 13622 | spdy_util_.UpdateWithStreamDestruction(1); |
| 13623 | SpdySerializedFrame req2( |
| 13624 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
| 13625 | SpdySerializedFrame rst( |
| 13626 | spdy_util_.ConstructSpdyRstStream(3, ERROR_CODE_CANCEL)); |
| 13627 | MockWrite writes1[] = { |
| 13628 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 13629 | CreateMockWrite(rst, 6), |
| 13630 | }; |
| 13631 | |
| 13632 | // The first one succeeds, the second gets error 421 Misdirected Request. |
| 13633 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 13634 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 13635 | SpdyHeaderBlock response_headers; |
| 13636 | response_headers[SpdyTestUtil::GetStatusKey()] = "421"; |
| 13637 | SpdySerializedFrame resp2( |
| 13638 | spdy_util_.ConstructSpdyReply(3, std::move(response_headers))); |
| 13639 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 13640 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 13641 | |
| 13642 | MockConnect connect1(ASYNC, OK, peer_addr); |
| 13643 | SequencedSocketData data1(connect1, reads1, arraysize(reads1), writes1, |
| 13644 | arraysize(writes1)); |
| 13645 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 13646 | |
| 13647 | AddSSLSocketData(); |
| 13648 | |
| 13649 | // Retry the second request on a second connection. |
| 13650 | SpdyTestUtil spdy_util2; |
| 13651 | SpdySerializedFrame req3( |
| 13652 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 13653 | MockWrite writes2[] = { |
| 13654 | CreateMockWrite(req3, 0), |
| 13655 | }; |
| 13656 | |
| 13657 | SpdySerializedFrame resp3(spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 13658 | SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 13659 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 13660 | MockRead(ASYNC, 0, 3)}; |
| 13661 | |
| 13662 | MockConnect connect2(ASYNC, OK, peer_addr); |
| 13663 | SequencedSocketData data2(connect2, reads2, arraysize(reads2), writes2, |
| 13664 | arraysize(writes2)); |
| 13665 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 13666 | |
| 13667 | AddSSLSocketData(); |
| 13668 | |
| 13669 | // Preload mail.example.org into HostCache. |
| 13670 | HostPortPair host_port("mail.example.org", 443); |
| 13671 | HostResolver::RequestInfo resolve_info(host_port); |
| 13672 | AddressList ignored; |
| 13673 | std::unique_ptr<HostResolver::Request> request; |
| 13674 | TestCompletionCallback callback; |
| 13675 | int rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 13676 | &ignored, callback.callback(), |
| 13677 | &request, NetLogWithSource()); |
| 13678 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13679 | rv = callback.WaitForResult(); |
| 13680 | EXPECT_THAT(rv, IsOk()); |
| 13681 | |
| 13682 | HttpRequestInfo request1; |
| 13683 | request1.method = "GET"; |
| 13684 | request1.url = GURL("https://www.example.org/"); |
| 13685 | request1.load_flags = 0; |
| 13686 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 13687 | |
| 13688 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 13689 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13690 | rv = callback.WaitForResult(); |
| 13691 | EXPECT_THAT(rv, IsOk()); |
| 13692 | |
| 13693 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 13694 | ASSERT_TRUE(response); |
| 13695 | ASSERT_TRUE(response->headers); |
| 13696 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 13697 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 13698 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 13699 | std::string response_data; |
| 13700 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 13701 | EXPECT_EQ("hello!", response_data); |
| 13702 | |
| 13703 | HttpRequestInfo request2; |
| 13704 | request2.method = "GET"; |
| 13705 | request2.url = GURL("https://mail.example.org/"); |
| 13706 | request2.load_flags = 0; |
| 13707 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 13708 | |
| 13709 | BoundTestNetLog log; |
| 13710 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 13711 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13712 | rv = callback.WaitForResult(); |
| 13713 | EXPECT_THAT(rv, IsOk()); |
| 13714 | |
| 13715 | response = trans2.GetResponseInfo(); |
| 13716 | ASSERT_TRUE(response); |
| 13717 | ASSERT_TRUE(response->headers); |
| 13718 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 13719 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 13720 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 13721 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 13722 | EXPECT_EQ("hello!", response_data); |
| 13723 | |
| 13724 | TestNetLogEntry::List entries; |
| 13725 | log.GetEntries(&entries); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 13726 | ExpectLogContainsSomewhere( |
| 13727 | entries, 0, NetLogEventType::HTTP_TRANSACTION_RESTART_MISDIRECTED_REQUEST, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 13728 | NetLogEventPhase::NONE); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 13729 | } |
| 13730 | |
| 13731 | // Test that HTTP 421 responses are properly returned to the caller if received |
| 13732 | // on the retry as well. HttpNetworkTransaction should not infinite loop or lose |
| 13733 | // portions of the response. |
| 13734 | TEST_F(HttpNetworkTransactionTest, ReturnHTTP421OnRetry) { |
| 13735 | // Two hosts resolve to the same IP address. |
| 13736 | const std::string ip_addr = "1.2.3.4"; |
| 13737 | IPAddress ip; |
| 13738 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 13739 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 13740 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13741 | session_deps_.host_resolver = base::MakeUnique<MockCachingHostResolver>(); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 13742 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 13743 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 13744 | |
| 13745 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13746 | |
| 13747 | // Two requests on the first connection. |
| 13748 | SpdySerializedFrame req1( |
| 13749 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 13750 | spdy_util_.UpdateWithStreamDestruction(1); |
| 13751 | SpdySerializedFrame req2( |
| 13752 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
| 13753 | SpdySerializedFrame rst( |
| 13754 | spdy_util_.ConstructSpdyRstStream(3, ERROR_CODE_CANCEL)); |
| 13755 | MockWrite writes1[] = { |
| 13756 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 13757 | CreateMockWrite(rst, 6), |
| 13758 | }; |
| 13759 | |
| 13760 | // The first one succeeds, the second gets error 421 Misdirected Request. |
| 13761 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 13762 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 13763 | SpdyHeaderBlock response_headers; |
| 13764 | response_headers[SpdyTestUtil::GetStatusKey()] = "421"; |
| 13765 | SpdySerializedFrame resp2( |
| 13766 | spdy_util_.ConstructSpdyReply(3, response_headers.Clone())); |
| 13767 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 13768 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 13769 | |
| 13770 | MockConnect connect1(ASYNC, OK, peer_addr); |
| 13771 | SequencedSocketData data1(connect1, reads1, arraysize(reads1), writes1, |
| 13772 | arraysize(writes1)); |
| 13773 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 13774 | |
| 13775 | AddSSLSocketData(); |
| 13776 | |
| 13777 | // Retry the second request on a second connection. It returns 421 Misdirected |
| 13778 | // Retry again. |
| 13779 | SpdyTestUtil spdy_util2; |
| 13780 | SpdySerializedFrame req3( |
| 13781 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 13782 | MockWrite writes2[] = { |
| 13783 | CreateMockWrite(req3, 0), |
| 13784 | }; |
| 13785 | |
| 13786 | SpdySerializedFrame resp3( |
| 13787 | spdy_util2.ConstructSpdyReply(1, std::move(response_headers))); |
| 13788 | SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 13789 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 13790 | MockRead(ASYNC, 0, 3)}; |
| 13791 | |
| 13792 | MockConnect connect2(ASYNC, OK, peer_addr); |
| 13793 | SequencedSocketData data2(connect2, reads2, arraysize(reads2), writes2, |
| 13794 | arraysize(writes2)); |
| 13795 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 13796 | |
| 13797 | AddSSLSocketData(); |
| 13798 | |
| 13799 | // Preload mail.example.org into HostCache. |
| 13800 | HostPortPair host_port("mail.example.org", 443); |
| 13801 | HostResolver::RequestInfo resolve_info(host_port); |
| 13802 | AddressList ignored; |
| 13803 | std::unique_ptr<HostResolver::Request> request; |
| 13804 | TestCompletionCallback callback; |
| 13805 | int rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 13806 | &ignored, callback.callback(), |
| 13807 | &request, NetLogWithSource()); |
| 13808 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13809 | rv = callback.WaitForResult(); |
| 13810 | EXPECT_THAT(rv, IsOk()); |
| 13811 | |
| 13812 | HttpRequestInfo request1; |
| 13813 | request1.method = "GET"; |
| 13814 | request1.url = GURL("https://www.example.org/"); |
| 13815 | request1.load_flags = 0; |
| 13816 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 13817 | |
| 13818 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 13819 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13820 | rv = callback.WaitForResult(); |
| 13821 | EXPECT_THAT(rv, IsOk()); |
| 13822 | |
| 13823 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 13824 | ASSERT_TRUE(response); |
| 13825 | ASSERT_TRUE(response->headers); |
| 13826 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 13827 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 13828 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 13829 | std::string response_data; |
| 13830 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 13831 | EXPECT_EQ("hello!", response_data); |
| 13832 | |
| 13833 | HttpRequestInfo request2; |
| 13834 | request2.method = "GET"; |
| 13835 | request2.url = GURL("https://mail.example.org/"); |
| 13836 | request2.load_flags = 0; |
| 13837 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 13838 | |
| 13839 | BoundTestNetLog log; |
| 13840 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 13841 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13842 | rv = callback.WaitForResult(); |
| 13843 | EXPECT_THAT(rv, IsOk()); |
| 13844 | |
| 13845 | // After a retry, the 421 Misdirected Request is reported back up to the |
| 13846 | // caller. |
| 13847 | response = trans2.GetResponseInfo(); |
| 13848 | ASSERT_TRUE(response); |
| 13849 | ASSERT_TRUE(response->headers); |
| 13850 | EXPECT_EQ("HTTP/1.1 421", response->headers->GetStatusLine()); |
| 13851 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 13852 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 13853 | EXPECT_TRUE(response->ssl_info.cert); |
| 13854 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 13855 | EXPECT_EQ("hello!", response_data); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 13856 | } |
| 13857 | |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 13858 | class OneTimeCachingHostResolver : public MockHostResolverBase { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13859 | public: |
| 13860 | explicit OneTimeCachingHostResolver(const HostPortPair& host_port) |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 13861 | : MockHostResolverBase(/* use_caching = */ true), host_port_(host_port) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13862 | ~OneTimeCachingHostResolver() override {} |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13863 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13864 | int ResolveFromCache(const RequestInfo& info, |
| 13865 | AddressList* addresses, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13866 | const NetLogWithSource& net_log) override { |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 13867 | int rv = MockHostResolverBase::ResolveFromCache(info, addresses, net_log); |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 13868 | if (rv == OK && info.host_port_pair().Equals(host_port_)) |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 13869 | GetHostCache()->clear(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13870 | return rv; |
| 13871 | } |
| 13872 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13873 | private: |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13874 | const HostPortPair host_port_; |
| 13875 | }; |
| 13876 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13877 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 13878 | UseIPConnectionPoolingWithHostCacheExpiration) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13879 | // Set up a special HttpNetworkSession with a OneTimeCachingHostResolver. |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 13880 | session_deps_.host_resolver = base::MakeUnique<OneTimeCachingHostResolver>( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13881 | HostPortPair("mail.example.com", 443)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13882 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13883 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13884 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13885 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13886 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13887 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13888 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13889 | SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13890 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13891 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13892 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13893 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13894 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13895 | SpdySerializedFrame host1_resp_body( |
| 13896 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13897 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13898 | SpdySerializedFrame host2_resp_body( |
| 13899 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13900 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13901 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 13902 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13903 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13904 | }; |
| 13905 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 13906 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13907 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13908 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 13909 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13910 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13911 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 13912 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13913 | HttpRequestInfo request1; |
| 13914 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13915 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13916 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13917 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13918 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13919 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13920 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13921 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13922 | |
| 13923 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13924 | ASSERT_TRUE(response); |
| 13925 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13926 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13927 | |
| 13928 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13929 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13930 | EXPECT_EQ("hello!", response_data); |
| 13931 | |
| 13932 | // Preload cache entries into HostCache. |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13933 | HostResolver::RequestInfo resolve_info(HostPortPair("mail.example.com", 443)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13934 | AddressList ignored; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 13935 | std::unique_ptr<HostResolver::Request> request; |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 13936 | rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 13937 | &ignored, callback.callback(), |
| 13938 | &request, NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13939 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 13940 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13941 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13942 | |
| 13943 | HttpRequestInfo request2; |
| 13944 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13945 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13946 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13947 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13948 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13949 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13950 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13951 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13952 | |
| 13953 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13954 | ASSERT_TRUE(response); |
| 13955 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13956 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13957 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13958 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13959 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13960 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13961 | } |
| 13962 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13963 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13964 | const std::string https_url = "https://www.example.org:8080/"; |
| 13965 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13966 | |
| 13967 | // SPDY GET for HTTPS URL |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13968 | SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13969 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13970 | |
| 13971 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13972 | CreateMockWrite(req1, 0), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13973 | }; |
| 13974 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13975 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13976 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 13977 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 13978 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3)}; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13979 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13980 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 13981 | arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13982 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 13983 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13984 | |
| 13985 | // HTTP GET for the HTTP URL |
| 13986 | MockWrite writes2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13987 | MockWrite(ASYNC, 0, |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 13988 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13989 | "Host: www.example.org:8080\r\n" |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 13990 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13991 | }; |
| 13992 | |
| 13993 | MockRead reads2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13994 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 13995 | MockRead(ASYNC, 2, "hello"), |
| 13996 | MockRead(ASYNC, OK, 3), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13997 | }; |
| 13998 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13999 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 14000 | arraysize(writes2)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14001 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14002 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14003 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14004 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14005 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 14006 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14007 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14008 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14009 | |
| 14010 | // Start the first transaction to set up the SpdySession |
| 14011 | HttpRequestInfo request1; |
| 14012 | request1.method = "GET"; |
| 14013 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14014 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14015 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14016 | TestCompletionCallback callback1; |
| 14017 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14018 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 14019 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14020 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14021 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14022 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 14023 | |
| 14024 | // Now, start the HTTP request |
| 14025 | HttpRequestInfo request2; |
| 14026 | request2.method = "GET"; |
| 14027 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14028 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14029 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14030 | TestCompletionCallback callback2; |
| 14031 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14032 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 14033 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14034 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14035 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14036 | EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 14037 | } |
| 14038 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14039 | // Alternative service requires HTTP/2 (or SPDY), but HTTP/1.1 is negotiated |
| 14040 | // with the alternative server. That connection should not be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14041 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceNotOnHttp11) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14042 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 14043 | HostPortPair alternative("www.example.org", 444); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14044 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14045 | // Negotiate HTTP/1.1 with alternative. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14046 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14047 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14048 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14049 | |
| 14050 | // No data should be read from the alternative, because HTTP/1.1 is |
| 14051 | // negotiated. |
| 14052 | StaticSocketDataProvider data; |
| 14053 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14054 | |
| 14055 | // 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] | 14056 | // negotiated. In order to test this, a failed connection to the server is |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14057 | // mocked. This way the request relies on the alternate Job. |
| 14058 | StaticSocketDataProvider data_refused; |
| 14059 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 14060 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 14061 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14062 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14063 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 14064 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14065 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 14066 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 14067 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14068 | http_server_properties->SetAlternativeService(server, alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 14069 | expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14070 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14071 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 14072 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14073 | request.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14074 | request.url = GURL("https://www.example.org:443"); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14075 | TestCompletionCallback callback; |
| 14076 | |
| 14077 | // HTTP/2 (or SPDY) is required for alternative service, if HTTP/1.1 is |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14078 | // negotiated, the alternate Job should fail with ERR_ALPN_NEGOTIATION_FAILED. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14079 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14080 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_ALPN_NEGOTIATION_FAILED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14081 | } |
| 14082 | |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14083 | // 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] | 14084 | // server, and an alternate one to the alternative server. If the former |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14085 | // succeeds, the request should succeed, even if the latter fails because |
| 14086 | // HTTP/1.1 is negotiated which is insufficient for alternative service. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14087 | TEST_F(HttpNetworkTransactionTest, FailedAlternativeServiceIsNotUserVisible) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14088 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 14089 | HostPortPair alternative("www.example.org", 444); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14090 | |
| 14091 | // Negotiate HTTP/1.1 with alternative. |
| 14092 | SSLSocketDataProvider alternative_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14093 | alternative_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14094 | session_deps_.socket_factory->AddSSLSocketDataProvider(&alternative_ssl); |
| 14095 | |
| 14096 | // No data should be read from the alternative, because HTTP/1.1 is |
| 14097 | // negotiated. |
| 14098 | StaticSocketDataProvider data; |
| 14099 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14100 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14101 | // Negotiate HTTP/1.1 with server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14102 | SSLSocketDataProvider origin_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14103 | origin_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14104 | session_deps_.socket_factory->AddSSLSocketDataProvider(&origin_ssl); |
| 14105 | |
| 14106 | MockWrite http_writes[] = { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14107 | MockWrite("GET / HTTP/1.1\r\n" |
| 14108 | "Host: www.example.org\r\n" |
| 14109 | "Connection: keep-alive\r\n\r\n"), |
| 14110 | MockWrite("GET /second HTTP/1.1\r\n" |
| 14111 | "Host: www.example.org\r\n" |
| 14112 | "Connection: keep-alive\r\n\r\n"), |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14113 | }; |
| 14114 | |
| 14115 | MockRead http_reads[] = { |
| 14116 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14117 | MockRead("Content-Type: text/html\r\n"), |
| 14118 | MockRead("Content-Length: 6\r\n\r\n"), |
| 14119 | MockRead("foobar"), |
| 14120 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14121 | MockRead("Content-Type: text/html\r\n"), |
| 14122 | MockRead("Content-Length: 7\r\n\r\n"), |
| 14123 | MockRead("another"), |
| 14124 | }; |
| 14125 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 14126 | http_writes, arraysize(http_writes)); |
| 14127 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 14128 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14129 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14130 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 14131 | HttpServerProperties* http_server_properties = |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14132 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 14133 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 14134 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14135 | http_server_properties->SetAlternativeService(server, alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 14136 | expiration); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14137 | |
| 14138 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 14139 | HttpRequestInfo request1; |
| 14140 | request1.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14141 | request1.url = GURL("https://www.example.org:443"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14142 | request1.load_flags = 0; |
| 14143 | TestCompletionCallback callback1; |
| 14144 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14145 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14146 | rv = callback1.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14147 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14148 | |
| 14149 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14150 | ASSERT_TRUE(response1); |
| 14151 | ASSERT_TRUE(response1->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14152 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 14153 | |
| 14154 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14155 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14156 | EXPECT_EQ("foobar", response_data1); |
| 14157 | |
| 14158 | // Alternative should be marked as broken, because HTTP/1.1 is not sufficient |
| 14159 | // for alternative service. |
| 14160 | EXPECT_TRUE( |
| 14161 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
| 14162 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14163 | // Since |alternative_service| is broken, a second transaction to server |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14164 | // should not start an alternate Job. It should pool to existing connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14165 | // to server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14166 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 14167 | HttpRequestInfo request2; |
| 14168 | request2.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14169 | request2.url = GURL("https://www.example.org:443/second"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14170 | request2.load_flags = 0; |
| 14171 | TestCompletionCallback callback2; |
| 14172 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14173 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14174 | rv = callback2.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14175 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14176 | |
| 14177 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14178 | ASSERT_TRUE(response2); |
| 14179 | ASSERT_TRUE(response2->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14180 | EXPECT_EQ("HTTP/1.1 200 OK", response2->headers->GetStatusLine()); |
| 14181 | |
| 14182 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14183 | ASSERT_THAT(ReadTransaction(&trans2, &response_data2), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14184 | EXPECT_EQ("another", response_data2); |
| 14185 | } |
| 14186 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14187 | // Alternative service requires HTTP/2 (or SPDY), but there is already a |
| 14188 | // HTTP/1.1 socket open to the alternative server. That socket should not be |
| 14189 | // used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14190 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceShouldNotPoolToHttp11) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14191 | url::SchemeHostPort server("https", "origin.example.org", 443); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14192 | HostPortPair alternative("alternative.example.org", 443); |
| 14193 | std::string origin_url = "https://origin.example.org:443"; |
| 14194 | std::string alternative_url = "https://alternative.example.org:443"; |
| 14195 | |
| 14196 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 14197 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14198 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14199 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14200 | |
| 14201 | // HTTP/1.1 data for |request1| and |request2|. |
| 14202 | MockWrite http_writes[] = { |
| 14203 | MockWrite( |
| 14204 | "GET / HTTP/1.1\r\n" |
| 14205 | "Host: alternative.example.org\r\n" |
| 14206 | "Connection: keep-alive\r\n\r\n"), |
| 14207 | MockWrite( |
| 14208 | "GET / HTTP/1.1\r\n" |
| 14209 | "Host: alternative.example.org\r\n" |
| 14210 | "Connection: keep-alive\r\n\r\n"), |
| 14211 | }; |
| 14212 | |
| 14213 | MockRead http_reads[] = { |
| 14214 | MockRead( |
| 14215 | "HTTP/1.1 200 OK\r\n" |
| 14216 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 14217 | "Content-Length: 40\r\n\r\n" |
| 14218 | "first HTTP/1.1 response from alternative"), |
| 14219 | MockRead( |
| 14220 | "HTTP/1.1 200 OK\r\n" |
| 14221 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 14222 | "Content-Length: 41\r\n\r\n" |
| 14223 | "second HTTP/1.1 response from alternative"), |
| 14224 | }; |
| 14225 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 14226 | http_writes, arraysize(http_writes)); |
| 14227 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 14228 | |
| 14229 | // This test documents that an alternate Job should not pool to an already |
| 14230 | // existing HTTP/1.1 connection. In order to test this, a failed connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14231 | // to the server is mocked. This way |request2| relies on the alternate Job. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14232 | StaticSocketDataProvider data_refused; |
| 14233 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 14234 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 14235 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14236 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14237 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 14238 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14239 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 14240 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 14241 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14242 | http_server_properties->SetAlternativeService(server, alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 14243 | expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14244 | |
| 14245 | // First transaction to alternative to open an HTTP/1.1 socket. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14246 | HttpRequestInfo request1; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 14247 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14248 | request1.method = "GET"; |
| 14249 | request1.url = GURL(alternative_url); |
| 14250 | request1.load_flags = 0; |
| 14251 | TestCompletionCallback callback1; |
| 14252 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14253 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14254 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14255 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14256 | ASSERT_TRUE(response1); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14257 | ASSERT_TRUE(response1->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14258 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14259 | EXPECT_TRUE(response1->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14260 | EXPECT_FALSE(response1->was_fetched_via_spdy); |
| 14261 | std::string response_data1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14262 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14263 | EXPECT_EQ("first HTTP/1.1 response from alternative", response_data1); |
| 14264 | |
| 14265 | // Request for origin.example.org, which has an alternative service. This |
| 14266 | // will start two Jobs: the alternative looks for connections to pool to, |
| 14267 | // 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] | 14268 | // open other connections to alternative server. The Job to server fails, so |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14269 | // this request fails. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14270 | HttpRequestInfo request2; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 14271 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14272 | request2.method = "GET"; |
| 14273 | request2.url = GURL(origin_url); |
| 14274 | request2.load_flags = 0; |
| 14275 | TestCompletionCallback callback2; |
| 14276 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14277 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14278 | EXPECT_THAT(callback2.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14279 | |
| 14280 | // Another transaction to alternative. This is to test that the HTTP/1.1 |
| 14281 | // socket is still open and in the pool. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14282 | HttpRequestInfo request3; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 14283 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14284 | request3.method = "GET"; |
| 14285 | request3.url = GURL(alternative_url); |
| 14286 | request3.load_flags = 0; |
| 14287 | TestCompletionCallback callback3; |
| 14288 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14289 | rv = trans3.Start(&request3, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14290 | EXPECT_THAT(callback3.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14291 | const HttpResponseInfo* response3 = trans3.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14292 | ASSERT_TRUE(response3); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14293 | ASSERT_TRUE(response3->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14294 | EXPECT_EQ("HTTP/1.1 200 OK", response3->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14295 | EXPECT_TRUE(response3->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14296 | EXPECT_FALSE(response3->was_fetched_via_spdy); |
| 14297 | std::string response_data3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14298 | ASSERT_THAT(ReadTransaction(&trans3, &response_data3), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14299 | EXPECT_EQ("second HTTP/1.1 response from alternative", response_data3); |
| 14300 | } |
| 14301 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14302 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14303 | const std::string https_url = "https://www.example.org:8080/"; |
| 14304 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14305 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14306 | // Separate SPDY util instance for naked and wrapped requests. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14307 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14308 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14309 | // SPDY GET for HTTPS URL (through CONNECT tunnel) |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14310 | const HostPortPair host_port_pair("www.example.org", 8080); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14311 | SpdySerializedFrame connect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 14312 | spdy_util_.ConstructSpdyConnect(NULL, 0, 1, LOWEST, host_port_pair)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14313 | SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14314 | spdy_util_wrapped.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14315 | SpdySerializedFrame wrapped_req1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 14316 | spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 14317 | |
| 14318 | // SPDY GET for HTTP URL (through the proxy, but not the tunnel). |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 14319 | SpdyHeaderBlock req2_block; |
| 14320 | req2_block[spdy_util_.GetMethodKey()] = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14321 | req2_block[spdy_util_.GetHostKey()] = "www.example.org:8080"; |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 14322 | req2_block[spdy_util_.GetSchemeKey()] = "http"; |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 14323 | req2_block[spdy_util_.GetPathKey()] = "/"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14324 | SpdySerializedFrame req2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14325 | spdy_util_.ConstructSpdyHeaders(3, std::move(req2_block), MEDIUM, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14326 | |
| 14327 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14328 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_req1, 2), |
| 14329 | CreateMockWrite(req2, 6), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14330 | }; |
| 14331 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14332 | SpdySerializedFrame conn_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14333 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14334 | SpdySerializedFrame resp1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14335 | spdy_util_wrapped.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14336 | SpdySerializedFrame body1(spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 14337 | SpdySerializedFrame wrapped_resp1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14338 | spdy_util_wrapped.ConstructWrappedSpdyFrame(resp1, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14339 | SpdySerializedFrame wrapped_body1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14340 | spdy_util_wrapped.ConstructWrappedSpdyFrame(body1, 1)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14341 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14342 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14343 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14344 | CreateMockRead(conn_resp, 1), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14345 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14346 | CreateMockRead(wrapped_resp1, 4), |
| 14347 | CreateMockRead(wrapped_body1, 5), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14348 | MockRead(ASYNC, ERR_IO_PENDING, 7), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14349 | CreateMockRead(resp2, 8), |
| 14350 | CreateMockRead(body2, 9), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14351 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 10), |
| 14352 | }; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14353 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14354 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 14355 | arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14356 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 14357 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14358 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 14359 | session_deps_.proxy_service = |
| 14360 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14361 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14362 | session_deps_.net_log = &log; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14363 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14364 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14365 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14366 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14367 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14368 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 14369 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14370 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14371 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14372 | |
| 14373 | // Start the first transaction to set up the SpdySession |
| 14374 | HttpRequestInfo request1; |
| 14375 | request1.method = "GET"; |
| 14376 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14377 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14378 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14379 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14380 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14381 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14382 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 14383 | data1.RunUntilPaused(); |
| 14384 | base::RunLoop().RunUntilIdle(); |
| 14385 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14386 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14387 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 14388 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 14389 | LoadTimingInfo load_timing_info1; |
| 14390 | EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); |
| 14391 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 14392 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 14393 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14394 | // Now, start the HTTP request. |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14395 | HttpRequestInfo request2; |
| 14396 | request2.method = "GET"; |
| 14397 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14398 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14399 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14400 | TestCompletionCallback callback2; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14401 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14402 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14403 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 14404 | data1.RunUntilPaused(); |
| 14405 | base::RunLoop().RunUntilIdle(); |
| 14406 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14407 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14408 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14409 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 14410 | |
| 14411 | LoadTimingInfo load_timing_info2; |
| 14412 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
| 14413 | // The established SPDY sessions is considered reused by the HTTP request. |
| 14414 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 14415 | // HTTP requests over a SPDY session should have a different connection |
| 14416 | // socket_log_id than requests over a tunnel. |
| 14417 | 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] | 14418 | } |
| 14419 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14420 | // Test that in the case where we have a SPDY session to a SPDY proxy |
| 14421 | // that we do not pool other origins that resolve to the same IP when |
| 14422 | // the certificate does not match the new origin. |
| 14423 | // http://crbug.com/134690 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14424 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14425 | const std::string url1 = "http://www.example.org/"; |
| 14426 | const std::string url2 = "https://news.example.org/"; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14427 | const std::string ip_addr = "1.2.3.4"; |
| 14428 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14429 | // Second SpdyTestUtil instance for the second socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14430 | SpdyTestUtil spdy_util_secure; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14431 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14432 | // SPDY GET for HTTP URL (through SPDY proxy) |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 14433 | SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14434 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14435 | SpdySerializedFrame req1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14436 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14437 | |
| 14438 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14439 | CreateMockWrite(req1, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14440 | }; |
| 14441 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14442 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14443 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14444 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14445 | MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(resp1, 2), |
| 14446 | CreateMockRead(body1, 3), MockRead(ASYNC, OK, 4), // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14447 | }; |
| 14448 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14449 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 14450 | arraysize(writes1)); |
martijn | fe9636e | 2016-02-06 14:33:32 | [diff] [blame] | 14451 | IPAddress ip; |
martijn | 654c8c4 | 2016-02-10 22:10:59 | [diff] [blame] | 14452 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14453 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 14454 | MockConnect connect_data1(ASYNC, OK, peer_addr); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14455 | data1.set_connect_data(connect_data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14456 | |
| 14457 | // SPDY GET for HTTPS URL (direct) |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14458 | SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14459 | spdy_util_secure.ConstructSpdyGet(url2.c_str(), 1, MEDIUM)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14460 | |
| 14461 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14462 | CreateMockWrite(req2, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14463 | }; |
| 14464 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14465 | SpdySerializedFrame resp2(spdy_util_secure.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14466 | SpdySerializedFrame body2(spdy_util_secure.ConstructSpdyDataFrame(1, true)); |
| 14467 | MockRead reads2[] = {CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14468 | MockRead(ASYNC, OK, 3)}; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14469 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14470 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 14471 | arraysize(writes2)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14472 | MockConnect connect_data2(ASYNC, OK); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14473 | data2.set_connect_data(connect_data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14474 | |
| 14475 | // Set up a proxy config that sends HTTP requests to a proxy, and |
| 14476 | // all others direct. |
| 14477 | ProxyConfig proxy_config; |
| 14478 | proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14479 | session_deps_.proxy_service = base::MakeUnique<ProxyService>( |
| 14480 | base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), nullptr, |
| 14481 | nullptr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14482 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14483 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14484 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14485 | // Load a valid cert. Note, that this does not need to |
| 14486 | // be valid for proxy because the MockSSLClientSocket does |
| 14487 | // not actually verify it. But SpdySession will use this |
| 14488 | // to see if it is valid for the new origin |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14489 | ssl1.cert = ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem"); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14490 | ASSERT_TRUE(ssl1.cert); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14491 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 14492 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14493 | |
| 14494 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14495 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14496 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 14497 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14498 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14499 | session_deps_.host_resolver = base::MakeUnique<MockCachingHostResolver>(); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14500 | session_deps_.host_resolver->rules()->AddRule("news.example.org", ip_addr); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14501 | session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14502 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14503 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14504 | |
| 14505 | // Start the first transaction to set up the SpdySession |
| 14506 | HttpRequestInfo request1; |
| 14507 | request1.method = "GET"; |
| 14508 | request1.url = GURL(url1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14509 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14510 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14511 | TestCompletionCallback callback1; |
| 14512 | ASSERT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14513 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14514 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 14515 | data1.RunUntilPaused(); |
| 14516 | base::RunLoop().RunUntilIdle(); |
| 14517 | data1.Resume(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14518 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14519 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14520 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 14521 | |
| 14522 | // Now, start the HTTP request |
| 14523 | HttpRequestInfo request2; |
| 14524 | request2.method = "GET"; |
| 14525 | request2.url = GURL(url2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14526 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14527 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14528 | TestCompletionCallback callback2; |
| 14529 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14530 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 14531 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14532 | |
| 14533 | ASSERT_TRUE(callback2.have_result()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14534 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14535 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 14536 | } |
| 14537 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14538 | // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 14539 | // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 14540 | // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 14541 | // SpdySession) do work. http://crbug.com/224701 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14542 | TEST_F(HttpNetworkTransactionTest, ErrorSocketNotConnected) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14543 | const std::string https_url = "https://www.example.org/"; |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14544 | |
| 14545 | MockRead reads1[] = { |
| 14546 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 14547 | }; |
| 14548 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14549 | SequencedSocketData data1(reads1, arraysize(reads1), NULL, 0); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14550 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14551 | SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14552 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, MEDIUM)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14553 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14554 | CreateMockWrite(req2, 0), |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14555 | }; |
| 14556 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14557 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14558 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14559 | MockRead reads2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14560 | CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
| 14561 | MockRead(ASYNC, OK, 3) // EOF |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14562 | }; |
| 14563 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14564 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 14565 | arraysize(writes2)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14566 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14567 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14568 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14569 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 14570 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14571 | |
| 14572 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14573 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14574 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 14575 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14576 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14577 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14578 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14579 | |
| 14580 | // Start the first transaction to set up the SpdySession and verify that |
| 14581 | // connection was closed. |
| 14582 | HttpRequestInfo request1; |
| 14583 | request1.method = "GET"; |
| 14584 | request1.url = GURL(https_url); |
| 14585 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14586 | HttpNetworkTransaction trans1(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14587 | TestCompletionCallback callback1; |
| 14588 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14589 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14590 | EXPECT_THAT(callback1.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14591 | |
| 14592 | // Now, start the second request and make sure it succeeds. |
| 14593 | HttpRequestInfo request2; |
| 14594 | request2.method = "GET"; |
| 14595 | request2.url = GURL(https_url); |
| 14596 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14597 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14598 | TestCompletionCallback callback2; |
| 14599 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14600 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14601 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14602 | ASSERT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14603 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 14604 | } |
| 14605 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14606 | TEST_F(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14607 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 14608 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14609 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 14610 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14611 | |
| 14612 | // Use two different hosts with different IPs so they don't get pooled. |
| 14613 | session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); |
| 14614 | session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14615 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14616 | |
| 14617 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14618 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14619 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14620 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14621 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 14622 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 14623 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14624 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14625 | spdy_util_.ConstructSpdyGet("https://www.a.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14626 | MockWrite spdy1_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14627 | CreateMockWrite(host1_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14628 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14629 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14630 | SpdySerializedFrame host1_resp_body( |
| 14631 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14632 | MockRead spdy1_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14633 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 14634 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14635 | }; |
| 14636 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14637 | // Use a separate test instance for the separate SpdySession that will be |
| 14638 | // created. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14639 | SpdyTestUtil spdy_util_2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14640 | auto spdy1_data = base::MakeUnique<SequencedSocketData>( |
| 14641 | spdy1_reads, arraysize(spdy1_reads), spdy1_writes, |
| 14642 | arraysize(spdy1_writes)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14643 | session_deps_.socket_factory->AddSocketDataProvider(spdy1_data.get()); |
| 14644 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14645 | SpdySerializedFrame host2_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14646 | spdy_util_2.ConstructSpdyGet("https://www.b.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14647 | MockWrite spdy2_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14648 | CreateMockWrite(host2_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14649 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14650 | SpdySerializedFrame host2_resp(spdy_util_2.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14651 | SpdySerializedFrame host2_resp_body( |
| 14652 | spdy_util_2.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14653 | MockRead spdy2_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14654 | CreateMockRead(host2_resp, 1), CreateMockRead(host2_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 14655 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14656 | }; |
| 14657 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14658 | auto spdy2_data = base::MakeUnique<SequencedSocketData>( |
| 14659 | spdy2_reads, arraysize(spdy2_reads), spdy2_writes, |
| 14660 | arraysize(spdy2_writes)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14661 | session_deps_.socket_factory->AddSocketDataProvider(spdy2_data.get()); |
| 14662 | |
| 14663 | MockWrite http_write[] = { |
| 14664 | MockWrite("GET / HTTP/1.1\r\n" |
| 14665 | "Host: www.a.com\r\n" |
| 14666 | "Connection: keep-alive\r\n\r\n"), |
| 14667 | }; |
| 14668 | |
| 14669 | MockRead http_read[] = { |
| 14670 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14671 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 14672 | MockRead("Content-Length: 6\r\n\r\n"), |
| 14673 | MockRead("hello!"), |
| 14674 | }; |
| 14675 | StaticSocketDataProvider http_data(http_read, arraysize(http_read), |
| 14676 | http_write, arraysize(http_write)); |
| 14677 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 14678 | |
| 14679 | HostPortPair host_port_pair_a("www.a.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 14680 | SpdySessionKey spdy_session_key_a( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 14681 | host_port_pair_a, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14682 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14683 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14684 | |
| 14685 | TestCompletionCallback callback; |
| 14686 | HttpRequestInfo request1; |
| 14687 | request1.method = "GET"; |
| 14688 | request1.url = GURL("https://www.a.com/"); |
| 14689 | request1.load_flags = 0; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14690 | auto trans = |
| 14691 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14692 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14693 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14694 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14695 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14696 | |
| 14697 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14698 | ASSERT_TRUE(response); |
| 14699 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14700 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14701 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14702 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14703 | |
| 14704 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14705 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14706 | EXPECT_EQ("hello!", response_data); |
| 14707 | trans.reset(); |
| 14708 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14709 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14710 | |
| 14711 | HostPortPair host_port_pair_b("www.b.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 14712 | SpdySessionKey spdy_session_key_b( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 14713 | host_port_pair_b, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14714 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14715 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14716 | HttpRequestInfo request2; |
| 14717 | request2.method = "GET"; |
| 14718 | request2.url = GURL("https://www.b.com/"); |
| 14719 | request2.load_flags = 0; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14720 | trans = |
| 14721 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14722 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14723 | rv = trans->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14724 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14725 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14726 | |
| 14727 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14728 | ASSERT_TRUE(response); |
| 14729 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14730 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14731 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14732 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14733 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14734 | EXPECT_EQ("hello!", response_data); |
| 14735 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14736 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14737 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14738 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14739 | |
| 14740 | HostPortPair host_port_pair_a1("www.a.com", 80); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 14741 | SpdySessionKey spdy_session_key_a1( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 14742 | host_port_pair_a1, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14743 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14744 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14745 | HttpRequestInfo request3; |
| 14746 | request3.method = "GET"; |
| 14747 | request3.url = GURL("http://www.a.com/"); |
| 14748 | request3.load_flags = 0; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14749 | trans = |
| 14750 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14751 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14752 | rv = trans->Start(&request3, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14753 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14754 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14755 | |
| 14756 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14757 | ASSERT_TRUE(response); |
| 14758 | ASSERT_TRUE(response->headers); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14759 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 14760 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14761 | EXPECT_FALSE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14762 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14763 | EXPECT_EQ("hello!", response_data); |
| 14764 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14765 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14766 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14767 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14768 | } |
| 14769 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14770 | TEST_F(HttpNetworkTransactionTest, HttpSyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14771 | HttpRequestInfo request; |
| 14772 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14773 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14774 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14775 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14776 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14777 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14778 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14779 | StaticSocketDataProvider data; |
| 14780 | data.set_connect_data(mock_connect); |
| 14781 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14782 | |
| 14783 | TestCompletionCallback callback; |
| 14784 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14785 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14786 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14787 | |
| 14788 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14789 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14790 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14791 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 14792 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14793 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 14794 | |
| 14795 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14796 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 14797 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14798 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14799 | |
| 14800 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14801 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14802 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14803 | } |
| 14804 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14805 | TEST_F(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14806 | HttpRequestInfo request; |
| 14807 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14808 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14809 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14810 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14811 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14812 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14813 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14814 | StaticSocketDataProvider data; |
| 14815 | data.set_connect_data(mock_connect); |
| 14816 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14817 | |
| 14818 | TestCompletionCallback callback; |
| 14819 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14820 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14821 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14822 | |
| 14823 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14824 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14825 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14826 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 14827 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14828 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 14829 | |
| 14830 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14831 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 14832 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14833 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14834 | |
| 14835 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14836 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14837 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14838 | } |
| 14839 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14840 | TEST_F(HttpNetworkTransactionTest, HttpSyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14841 | HttpRequestInfo request; |
| 14842 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14843 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14844 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14845 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14846 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14847 | |
| 14848 | MockWrite data_writes[] = { |
| 14849 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14850 | }; |
| 14851 | MockRead data_reads[] = { |
| 14852 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 14853 | }; |
| 14854 | |
| 14855 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14856 | data_writes, arraysize(data_writes)); |
| 14857 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14858 | |
| 14859 | TestCompletionCallback callback; |
| 14860 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14861 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14862 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14863 | |
| 14864 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14865 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14866 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14867 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14868 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14869 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 14870 | } |
| 14871 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14872 | TEST_F(HttpNetworkTransactionTest, HttpAsyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14873 | HttpRequestInfo request; |
| 14874 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14875 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14876 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14877 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14878 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14879 | |
| 14880 | MockWrite data_writes[] = { |
| 14881 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
| 14882 | }; |
| 14883 | MockRead data_reads[] = { |
| 14884 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 14885 | }; |
| 14886 | |
| 14887 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14888 | data_writes, arraysize(data_writes)); |
| 14889 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14890 | |
| 14891 | TestCompletionCallback callback; |
| 14892 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14893 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14894 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14895 | |
| 14896 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14897 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14898 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14899 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14900 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14901 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 14902 | } |
| 14903 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14904 | TEST_F(HttpNetworkTransactionTest, HttpSyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14905 | HttpRequestInfo request; |
| 14906 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14907 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14908 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14909 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14910 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14911 | |
| 14912 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14913 | MockWrite( |
| 14914 | "GET / HTTP/1.1\r\n" |
| 14915 | "Host: www.example.org\r\n" |
| 14916 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14917 | }; |
| 14918 | MockRead data_reads[] = { |
| 14919 | MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14920 | }; |
| 14921 | |
| 14922 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14923 | data_writes, arraysize(data_writes)); |
| 14924 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14925 | |
| 14926 | TestCompletionCallback callback; |
| 14927 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14928 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14929 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14930 | |
| 14931 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14932 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14933 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14934 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14935 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14936 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 14937 | } |
| 14938 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14939 | TEST_F(HttpNetworkTransactionTest, HttpAsyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14940 | HttpRequestInfo request; |
| 14941 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14942 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14943 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14944 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14945 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14946 | |
| 14947 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14948 | MockWrite( |
| 14949 | "GET / HTTP/1.1\r\n" |
| 14950 | "Host: www.example.org\r\n" |
| 14951 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14952 | }; |
| 14953 | MockRead data_reads[] = { |
| 14954 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 14955 | }; |
| 14956 | |
| 14957 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14958 | data_writes, arraysize(data_writes)); |
| 14959 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14960 | |
| 14961 | TestCompletionCallback callback; |
| 14962 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14963 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14964 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14965 | |
| 14966 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14967 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14968 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14969 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14970 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14971 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 14972 | } |
| 14973 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14974 | TEST_F(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14975 | HttpRequestInfo request; |
| 14976 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14977 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14978 | request.extra_headers.SetHeader("X-Foo", "bar"); |
| 14979 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14980 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14981 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14982 | |
| 14983 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14984 | MockWrite( |
| 14985 | "GET / HTTP/1.1\r\n" |
| 14986 | "Host: www.example.org\r\n" |
| 14987 | "Connection: keep-alive\r\n" |
| 14988 | "X-Foo: bar\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14989 | }; |
| 14990 | MockRead data_reads[] = { |
| 14991 | MockRead("HTTP/1.1 200 OK\r\n" |
| 14992 | "Content-Length: 5\r\n\r\n" |
| 14993 | "hello"), |
| 14994 | MockRead(ASYNC, ERR_UNEXPECTED), |
| 14995 | }; |
| 14996 | |
| 14997 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14998 | data_writes, arraysize(data_writes)); |
| 14999 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15000 | |
| 15001 | TestCompletionCallback callback; |
| 15002 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15003 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15004 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15005 | |
| 15006 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15007 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15008 | |
| 15009 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15010 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15011 | std::string foo; |
| 15012 | EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo)); |
| 15013 | EXPECT_EQ("bar", foo); |
| 15014 | } |
| 15015 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15016 | namespace { |
| 15017 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 15018 | // Fake HttpStream that simply records calls to SetPriority(). |
| 15019 | class FakeStream : public HttpStream, |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15020 | public base::SupportsWeakPtr<FakeStream> { |
| 15021 | public: |
| 15022 | explicit FakeStream(RequestPriority priority) : priority_(priority) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15023 | ~FakeStream() override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15024 | |
| 15025 | RequestPriority priority() const { return priority_; } |
| 15026 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15027 | int InitializeStream(const HttpRequestInfo* request_info, |
| 15028 | RequestPriority priority, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15029 | const NetLogWithSource& net_log, |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15030 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15031 | return ERR_IO_PENDING; |
| 15032 | } |
| 15033 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15034 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 15035 | HttpResponseInfo* response, |
| 15036 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15037 | ADD_FAILURE(); |
| 15038 | return ERR_UNEXPECTED; |
| 15039 | } |
| 15040 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15041 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15042 | ADD_FAILURE(); |
| 15043 | return ERR_UNEXPECTED; |
| 15044 | } |
| 15045 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15046 | int ReadResponseBody(IOBuffer* buf, |
| 15047 | int buf_len, |
| 15048 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15049 | ADD_FAILURE(); |
| 15050 | return ERR_UNEXPECTED; |
| 15051 | } |
| 15052 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15053 | void Close(bool not_reusable) override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15054 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15055 | bool IsResponseBodyComplete() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15056 | ADD_FAILURE(); |
| 15057 | return false; |
| 15058 | } |
| 15059 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15060 | bool IsConnectionReused() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15061 | ADD_FAILURE(); |
| 15062 | return false; |
| 15063 | } |
| 15064 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15065 | void SetConnectionReused() override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15066 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 15067 | bool CanReuseConnection() const override { return false; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15068 | |
sclittle | 4de1bab9 | 2015-09-22 21:28:24 | [diff] [blame] | 15069 | int64_t GetTotalReceivedBytes() const override { |
[email protected] | bc92bc97 | 2013-12-13 08:32:59 | [diff] [blame] | 15070 | ADD_FAILURE(); |
| 15071 | return 0; |
| 15072 | } |
| 15073 | |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 15074 | int64_t GetTotalSentBytes() const override { |
| 15075 | ADD_FAILURE(); |
| 15076 | return 0; |
| 15077 | } |
| 15078 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15079 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15080 | ADD_FAILURE(); |
| 15081 | return false; |
| 15082 | } |
| 15083 | |
rch | cd37901 | 2017-04-12 21:53:32 | [diff] [blame] | 15084 | bool GetAlternativeService( |
| 15085 | AlternativeService* alternative_service) const override { |
| 15086 | ADD_FAILURE(); |
| 15087 | return false; |
| 15088 | } |
| 15089 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15090 | void GetSSLInfo(SSLInfo* ssl_info) override { ADD_FAILURE(); } |
| 15091 | |
| 15092 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15093 | ADD_FAILURE(); |
| 15094 | } |
| 15095 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15096 | bool GetRemoteEndpoint(IPEndPoint* endpoint) override { return false; } |
| 15097 | |
nharper | 78e6d2b | 2016-09-21 05:42:35 | [diff] [blame] | 15098 | Error GetTokenBindingSignature(crypto::ECPrivateKey* key, |
| 15099 | TokenBindingType tb_type, |
| 15100 | std::vector<uint8_t>* out) override { |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 15101 | ADD_FAILURE(); |
| 15102 | return ERR_NOT_IMPLEMENTED; |
| 15103 | } |
| 15104 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15105 | void Drain(HttpNetworkSession* session) override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15106 | |
zhongyi | ca364fbb | 2015-12-12 03:39:12 | [diff] [blame] | 15107 | void PopulateNetErrorDetails(NetErrorDetails* details) override { return; } |
| 15108 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15109 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15110 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 15111 | HttpStream* RenewStreamForAuth() override { return NULL; } |
| 15112 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15113 | private: |
| 15114 | RequestPriority priority_; |
| 15115 | |
| 15116 | DISALLOW_COPY_AND_ASSIGN(FakeStream); |
| 15117 | }; |
| 15118 | |
| 15119 | // Fake HttpStreamRequest that simply records calls to SetPriority() |
| 15120 | // and vends FakeStreams with its current priority. |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15121 | class FakeStreamRequest : public HttpStreamRequest, |
| 15122 | public base::SupportsWeakPtr<FakeStreamRequest> { |
| 15123 | public: |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15124 | FakeStreamRequest(RequestPriority priority, |
| 15125 | HttpStreamRequest::Delegate* delegate) |
| 15126 | : priority_(priority), |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15127 | delegate_(delegate), |
| 15128 | websocket_stream_create_helper_(NULL) {} |
| 15129 | |
| 15130 | FakeStreamRequest(RequestPriority priority, |
| 15131 | HttpStreamRequest::Delegate* delegate, |
| 15132 | WebSocketHandshakeStreamBase::CreateHelper* create_helper) |
| 15133 | : priority_(priority), |
| 15134 | delegate_(delegate), |
| 15135 | websocket_stream_create_helper_(create_helper) {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15136 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15137 | ~FakeStreamRequest() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15138 | |
| 15139 | RequestPriority priority() const { return priority_; } |
| 15140 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15141 | const WebSocketHandshakeStreamBase::CreateHelper* |
| 15142 | websocket_stream_create_helper() const { |
| 15143 | return websocket_stream_create_helper_; |
| 15144 | } |
| 15145 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15146 | // Create a new FakeStream and pass it to the request's |
| 15147 | // delegate. Returns a weak pointer to the FakeStream. |
| 15148 | base::WeakPtr<FakeStream> FinishStreamRequest() { |
bnc | 5029f463 | 2017-06-08 16:19:00 | [diff] [blame] | 15149 | auto fake_stream = base::MakeUnique<FakeStream>(priority_); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15150 | // Do this before calling OnStreamReady() as OnStreamReady() may |
| 15151 | // immediately delete |fake_stream|. |
| 15152 | base::WeakPtr<FakeStream> weak_stream = fake_stream->AsWeakPtr(); |
bnc | 5029f463 | 2017-06-08 16:19:00 | [diff] [blame] | 15153 | delegate_->OnStreamReady(SSLConfig(), ProxyInfo(), std::move(fake_stream)); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15154 | return weak_stream; |
| 15155 | } |
| 15156 | |
asanka | 681f02d | 2017-02-22 17:06:39 | [diff] [blame] | 15157 | int RestartTunnelWithProxyAuth() override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15158 | ADD_FAILURE(); |
| 15159 | return ERR_UNEXPECTED; |
| 15160 | } |
| 15161 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15162 | LoadState GetLoadState() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15163 | ADD_FAILURE(); |
| 15164 | return LoadState(); |
| 15165 | } |
| 15166 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15167 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15168 | |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15169 | bool was_alpn_negotiated() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15170 | |
bnc | 6227b26e | 2016-08-12 02:00:43 | [diff] [blame] | 15171 | NextProto negotiated_protocol() const override { return kProtoUnknown; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15172 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15173 | bool using_spdy() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15174 | |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 15175 | const ConnectionAttempts& connection_attempts() const override { |
| 15176 | static ConnectionAttempts no_attempts; |
| 15177 | return no_attempts; |
| 15178 | } |
| 15179 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15180 | private: |
| 15181 | RequestPriority priority_; |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15182 | HttpStreamRequest::Delegate* const delegate_; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15183 | WebSocketHandshakeStreamBase::CreateHelper* websocket_stream_create_helper_; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15184 | |
| 15185 | DISALLOW_COPY_AND_ASSIGN(FakeStreamRequest); |
| 15186 | }; |
| 15187 | |
| 15188 | // Fake HttpStreamFactory that vends FakeStreamRequests. |
| 15189 | class FakeStreamFactory : public HttpStreamFactory { |
| 15190 | public: |
| 15191 | FakeStreamFactory() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15192 | ~FakeStreamFactory() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15193 | |
| 15194 | // Returns a WeakPtr<> to the last HttpStreamRequest returned by |
| 15195 | // RequestStream() (which may be NULL if it was destroyed already). |
| 15196 | base::WeakPtr<FakeStreamRequest> last_stream_request() { |
| 15197 | return last_stream_request_; |
| 15198 | } |
| 15199 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15200 | std::unique_ptr<HttpStreamRequest> RequestStream( |
| 15201 | const HttpRequestInfo& info, |
| 15202 | RequestPriority priority, |
| 15203 | const SSLConfig& server_ssl_config, |
| 15204 | const SSLConfig& proxy_ssl_config, |
| 15205 | HttpStreamRequest::Delegate* delegate, |
| 15206 | bool enable_ip_based_pooling, |
| 15207 | bool enable_alternative_services, |
| 15208 | const NetLogWithSource& net_log) override { |
| 15209 | auto fake_request = base::MakeUnique<FakeStreamRequest>(priority, delegate); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15210 | last_stream_request_ = fake_request->AsWeakPtr(); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15211 | return std::move(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15212 | } |
| 15213 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15214 | std::unique_ptr<HttpStreamRequest> RequestBidirectionalStreamImpl( |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 15215 | const HttpRequestInfo& info, |
| 15216 | RequestPriority priority, |
| 15217 | const SSLConfig& server_ssl_config, |
| 15218 | const SSLConfig& proxy_ssl_config, |
| 15219 | HttpStreamRequest::Delegate* delegate, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15220 | bool enable_ip_based_pooling, |
bnc | accd496 | 2017-04-06 21:00:26 | [diff] [blame] | 15221 | bool enable_alternative_services, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15222 | const NetLogWithSource& net_log) override { |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 15223 | NOTREACHED(); |
| 15224 | return nullptr; |
| 15225 | } |
| 15226 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15227 | std::unique_ptr<HttpStreamRequest> RequestWebSocketHandshakeStream( |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15228 | const HttpRequestInfo& info, |
| 15229 | RequestPriority priority, |
| 15230 | const SSLConfig& server_ssl_config, |
| 15231 | const SSLConfig& proxy_ssl_config, |
| 15232 | HttpStreamRequest::Delegate* delegate, |
[email protected] | 467086b | 2013-11-12 08:19:46 | [diff] [blame] | 15233 | WebSocketHandshakeStreamBase::CreateHelper* create_helper, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15234 | bool enable_ip_based_pooling, |
bnc | accd496 | 2017-04-06 21:00:26 | [diff] [blame] | 15235 | bool enable_alternative_services, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15236 | const NetLogWithSource& net_log) override { |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15237 | auto fake_request = |
| 15238 | base::MakeUnique<FakeStreamRequest>(priority, delegate, create_helper); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15239 | last_stream_request_ = fake_request->AsWeakPtr(); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15240 | return std::move(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15241 | } |
| 15242 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15243 | void PreconnectStreams(int num_streams, |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 15244 | const HttpRequestInfo& info) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15245 | ADD_FAILURE(); |
| 15246 | } |
| 15247 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15248 | const HostMappingRules* GetHostMappingRules() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15249 | ADD_FAILURE(); |
| 15250 | return NULL; |
| 15251 | } |
| 15252 | |
xunjieli | f5267de | 2017-01-20 21:18:57 | [diff] [blame] | 15253 | void DumpMemoryStats(base::trace_event::ProcessMemoryDump* pmd, |
| 15254 | const std::string& parent_absolute_name) const override { |
| 15255 | ADD_FAILURE(); |
| 15256 | } |
| 15257 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15258 | private: |
| 15259 | base::WeakPtr<FakeStreamRequest> last_stream_request_; |
| 15260 | |
| 15261 | DISALLOW_COPY_AND_ASSIGN(FakeStreamFactory); |
| 15262 | }; |
| 15263 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15264 | // TODO(ricea): Maybe unify this with the one in |
| 15265 | // url_request_http_job_unittest.cc ? |
| 15266 | class FakeWebSocketBasicHandshakeStream : public WebSocketHandshakeStreamBase { |
| 15267 | public: |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15268 | FakeWebSocketBasicHandshakeStream( |
| 15269 | std::unique_ptr<ClientSocketHandle> connection, |
| 15270 | bool using_proxy) |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 15271 | : state_(std::move(connection), using_proxy, false) {} |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15272 | |
| 15273 | // Fake implementation of HttpStreamBase methods. |
| 15274 | // This ends up being quite "real" because this object has to really send data |
| 15275 | // on the mock socket. It might be easier to use the real implementation, but |
| 15276 | // the fact that the WebSocket code is not compiled on iOS makes that |
| 15277 | // difficult. |
| 15278 | int InitializeStream(const HttpRequestInfo* request_info, |
| 15279 | RequestPriority priority, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15280 | const NetLogWithSource& net_log, |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15281 | const CompletionCallback& callback) override { |
| 15282 | state_.Initialize(request_info, priority, net_log, callback); |
| 15283 | return OK; |
| 15284 | } |
| 15285 | |
| 15286 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 15287 | HttpResponseInfo* response, |
| 15288 | const CompletionCallback& callback) override { |
| 15289 | return parser()->SendRequest(state_.GenerateRequestLine(), request_headers, |
| 15290 | response, callback); |
| 15291 | } |
| 15292 | |
| 15293 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
| 15294 | return parser()->ReadResponseHeaders(callback); |
| 15295 | } |
| 15296 | |
| 15297 | int ReadResponseBody(IOBuffer* buf, |
| 15298 | int buf_len, |
| 15299 | const CompletionCallback& callback) override { |
| 15300 | NOTREACHED(); |
| 15301 | return ERR_IO_PENDING; |
| 15302 | } |
| 15303 | |
| 15304 | void Close(bool not_reusable) override { |
| 15305 | if (parser()) |
| 15306 | parser()->Close(true); |
| 15307 | } |
| 15308 | |
| 15309 | bool IsResponseBodyComplete() const override { |
| 15310 | NOTREACHED(); |
| 15311 | return false; |
| 15312 | } |
| 15313 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15314 | bool IsConnectionReused() const override { |
| 15315 | NOTREACHED(); |
| 15316 | return false; |
| 15317 | } |
| 15318 | void SetConnectionReused() override { NOTREACHED(); } |
| 15319 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 15320 | bool CanReuseConnection() const override { return false; } |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15321 | |
sclittle | 4de1bab9 | 2015-09-22 21:28:24 | [diff] [blame] | 15322 | int64_t GetTotalReceivedBytes() const override { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15323 | NOTREACHED(); |
| 15324 | return 0; |
| 15325 | } |
| 15326 | |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 15327 | int64_t GetTotalSentBytes() const override { |
| 15328 | NOTREACHED(); |
| 15329 | return 0; |
| 15330 | } |
| 15331 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15332 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
| 15333 | NOTREACHED(); |
| 15334 | return false; |
| 15335 | } |
| 15336 | |
rch | cd37901 | 2017-04-12 21:53:32 | [diff] [blame] | 15337 | bool GetAlternativeService( |
| 15338 | AlternativeService* alternative_service) const override { |
| 15339 | ADD_FAILURE(); |
| 15340 | return false; |
| 15341 | } |
| 15342 | |
Adam Rice | cb76ac6 | 2015-02-20 05:33:25 | [diff] [blame] | 15343 | void GetSSLInfo(SSLInfo* ssl_info) override {} |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15344 | |
| 15345 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
| 15346 | NOTREACHED(); |
| 15347 | } |
| 15348 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15349 | bool GetRemoteEndpoint(IPEndPoint* endpoint) override { return false; } |
| 15350 | |
nharper | 78e6d2b | 2016-09-21 05:42:35 | [diff] [blame] | 15351 | Error GetTokenBindingSignature(crypto::ECPrivateKey* key, |
| 15352 | TokenBindingType tb_type, |
| 15353 | std::vector<uint8_t>* out) override { |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 15354 | ADD_FAILURE(); |
| 15355 | return ERR_NOT_IMPLEMENTED; |
| 15356 | } |
| 15357 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15358 | void Drain(HttpNetworkSession* session) override { NOTREACHED(); } |
| 15359 | |
zhongyi | ca364fbb | 2015-12-12 03:39:12 | [diff] [blame] | 15360 | void PopulateNetErrorDetails(NetErrorDetails* details) override { return; } |
| 15361 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15362 | void SetPriority(RequestPriority priority) override { NOTREACHED(); } |
| 15363 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15364 | HttpStream* RenewStreamForAuth() override { |
| 15365 | NOTREACHED(); |
| 15366 | return nullptr; |
| 15367 | } |
| 15368 | |
| 15369 | // Fake implementation of WebSocketHandshakeStreamBase method(s) |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15370 | std::unique_ptr<WebSocketStream> Upgrade() override { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15371 | NOTREACHED(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15372 | return std::unique_ptr<WebSocketStream>(); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15373 | } |
| 15374 | |
| 15375 | private: |
| 15376 | HttpStreamParser* parser() const { return state_.parser(); } |
| 15377 | HttpBasicState state_; |
| 15378 | |
| 15379 | DISALLOW_COPY_AND_ASSIGN(FakeWebSocketBasicHandshakeStream); |
| 15380 | }; |
| 15381 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15382 | // TODO(yhirano): Split this class out into a net/websockets file, if it is |
| 15383 | // worth doing. |
| 15384 | class FakeWebSocketStreamCreateHelper : |
| 15385 | public WebSocketHandshakeStreamBase::CreateHelper { |
| 15386 | public: |
bnc | 615cf2f | 2017-05-19 18:53:26 | [diff] [blame] | 15387 | std::unique_ptr<WebSocketHandshakeStreamBase> CreateBasicStream( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15388 | std::unique_ptr<ClientSocketHandle> connection, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 15389 | bool using_proxy) override { |
bnc | 615cf2f | 2017-05-19 18:53:26 | [diff] [blame] | 15390 | return base::MakeUnique<FakeWebSocketBasicHandshakeStream>( |
| 15391 | std::move(connection), using_proxy); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15392 | } |
| 15393 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15394 | ~FakeWebSocketStreamCreateHelper() override {} |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15395 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15396 | virtual std::unique_ptr<WebSocketStream> Upgrade() { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15397 | NOTREACHED(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15398 | return std::unique_ptr<WebSocketStream>(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15399 | } |
| 15400 | }; |
| 15401 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15402 | } // namespace |
| 15403 | |
| 15404 | // Make sure that HttpNetworkTransaction passes on its priority to its |
| 15405 | // stream request on start. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15406 | TEST_F(HttpNetworkTransactionTest, SetStreamRequestPriorityOnStart) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15407 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15408 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15409 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15410 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15411 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15412 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15413 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15414 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15415 | ASSERT_FALSE(fake_factory->last_stream_request()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15416 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15417 | TestCompletionCallback callback; |
| 15418 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15419 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15420 | |
| 15421 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 15422 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15423 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15424 | EXPECT_EQ(LOW, fake_request->priority()); |
| 15425 | } |
| 15426 | |
| 15427 | // Make sure that HttpNetworkTransaction passes on its priority |
| 15428 | // updates to its stream request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15429 | TEST_F(HttpNetworkTransactionTest, SetStreamRequestPriority) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15430 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15431 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15432 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15433 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15434 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15435 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15436 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15437 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15438 | TestCompletionCallback callback; |
| 15439 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15440 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15441 | |
| 15442 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 15443 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15444 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15445 | EXPECT_EQ(LOW, fake_request->priority()); |
| 15446 | |
| 15447 | trans.SetPriority(LOWEST); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15448 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15449 | EXPECT_EQ(LOWEST, fake_request->priority()); |
| 15450 | } |
| 15451 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15452 | // Make sure that HttpNetworkTransaction passes on its priority |
| 15453 | // updates to its stream. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15454 | TEST_F(HttpNetworkTransactionTest, SetStreamPriority) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15455 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15456 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15457 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15458 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15459 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15460 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15461 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15462 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15463 | TestCompletionCallback callback; |
| 15464 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15465 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15466 | |
| 15467 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 15468 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15469 | ASSERT_TRUE(fake_request); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15470 | base::WeakPtr<FakeStream> fake_stream = fake_request->FinishStreamRequest(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15471 | ASSERT_TRUE(fake_stream); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15472 | EXPECT_EQ(LOW, fake_stream->priority()); |
| 15473 | |
| 15474 | trans.SetPriority(LOWEST); |
| 15475 | EXPECT_EQ(LOWEST, fake_stream->priority()); |
| 15476 | } |
| 15477 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15478 | TEST_F(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15479 | // The same logic needs to be tested for both ws: and wss: schemes, but this |
| 15480 | // test is already parameterised on NextProto, so it uses a loop to verify |
| 15481 | // that the different schemes work. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15482 | std::string test_cases[] = {"ws://www.example.org/", |
| 15483 | "wss://www.example.org/"}; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15484 | for (size_t i = 0; i < arraysize(test_cases); ++i) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15485 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15486 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15487 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
| 15488 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
[email protected] | 0191b51c | 2013-11-18 10:55:23 | [diff] [blame] | 15489 | peer.SetHttpStreamFactoryForWebSocket( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15490 | std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15491 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15492 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15493 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15494 | trans.SetWebSocketHandshakeStreamCreateHelper( |
| 15495 | &websocket_stream_create_helper); |
| 15496 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15497 | TestCompletionCallback callback; |
| 15498 | request.method = "GET"; |
| 15499 | request.url = GURL(test_cases[i]); |
| 15500 | |
| 15501 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15502 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15503 | |
| 15504 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 15505 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15506 | ASSERT_TRUE(fake_request); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15507 | EXPECT_EQ(&websocket_stream_create_helper, |
| 15508 | fake_request->websocket_stream_create_helper()); |
| 15509 | } |
| 15510 | } |
| 15511 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15512 | // Tests that when a used socket is returned to the SSL socket pool, it's closed |
| 15513 | // if the transport socket pool is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15514 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15515 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 15516 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15517 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 15518 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15519 | |
| 15520 | // Set up SSL request. |
| 15521 | |
| 15522 | HttpRequestInfo ssl_request; |
| 15523 | ssl_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15524 | ssl_request.url = GURL("https://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15525 | |
| 15526 | MockWrite ssl_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15527 | MockWrite( |
| 15528 | "GET / HTTP/1.1\r\n" |
| 15529 | "Host: www.example.org\r\n" |
| 15530 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15531 | }; |
| 15532 | MockRead ssl_reads[] = { |
| 15533 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15534 | MockRead("Content-Length: 11\r\n\r\n"), |
| 15535 | MockRead("hello world"), |
| 15536 | MockRead(SYNCHRONOUS, OK), |
| 15537 | }; |
| 15538 | StaticSocketDataProvider ssl_data(ssl_reads, arraysize(ssl_reads), |
| 15539 | ssl_writes, arraysize(ssl_writes)); |
| 15540 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 15541 | |
| 15542 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 15543 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15544 | |
| 15545 | // Set up HTTP request. |
| 15546 | |
| 15547 | HttpRequestInfo http_request; |
| 15548 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15549 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15550 | |
| 15551 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15552 | MockWrite( |
| 15553 | "GET / HTTP/1.1\r\n" |
| 15554 | "Host: www.example.org\r\n" |
| 15555 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15556 | }; |
| 15557 | MockRead http_reads[] = { |
| 15558 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15559 | MockRead("Content-Length: 7\r\n\r\n"), |
| 15560 | MockRead("falafel"), |
| 15561 | MockRead(SYNCHRONOUS, OK), |
| 15562 | }; |
| 15563 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 15564 | http_writes, arraysize(http_writes)); |
| 15565 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 15566 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15567 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15568 | |
| 15569 | // Start the SSL request. |
| 15570 | TestCompletionCallback ssl_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15571 | HttpNetworkTransaction ssl_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15572 | ASSERT_EQ(ERR_IO_PENDING, |
| 15573 | ssl_trans.Start(&ssl_request, ssl_callback.callback(), |
| 15574 | NetLogWithSource())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15575 | |
| 15576 | // Start the HTTP request. Pool should stall. |
| 15577 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15578 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15579 | ASSERT_EQ(ERR_IO_PENDING, |
| 15580 | http_trans.Start(&http_request, http_callback.callback(), |
| 15581 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15582 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15583 | |
| 15584 | // Wait for response from SSL request. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15585 | ASSERT_THAT(ssl_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15586 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15587 | ASSERT_THAT(ReadTransaction(&ssl_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15588 | EXPECT_EQ("hello world", response_data); |
| 15589 | |
| 15590 | // The SSL socket should automatically be closed, so the HTTP request can |
| 15591 | // start. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15592 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 15593 | ASSERT_FALSE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15594 | |
| 15595 | // The HTTP request can now complete. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15596 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15597 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15598 | EXPECT_EQ("falafel", response_data); |
| 15599 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15600 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15601 | } |
| 15602 | |
| 15603 | // Tests that when a SSL connection is established but there's no corresponding |
| 15604 | // request that needs it, the new socket is closed if the transport socket pool |
| 15605 | // is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15606 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15607 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 15608 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15609 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 15610 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15611 | |
| 15612 | // Set up an ssl request. |
| 15613 | |
| 15614 | HttpRequestInfo ssl_request; |
| 15615 | ssl_request.method = "GET"; |
| 15616 | ssl_request.url = GURL("https://www.foopy.com/"); |
| 15617 | |
| 15618 | // No data will be sent on the SSL socket. |
| 15619 | StaticSocketDataProvider ssl_data; |
| 15620 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 15621 | |
| 15622 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 15623 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15624 | |
| 15625 | // Set up HTTP request. |
| 15626 | |
| 15627 | HttpRequestInfo http_request; |
| 15628 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15629 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15630 | |
| 15631 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15632 | MockWrite( |
| 15633 | "GET / HTTP/1.1\r\n" |
| 15634 | "Host: www.example.org\r\n" |
| 15635 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15636 | }; |
| 15637 | MockRead http_reads[] = { |
| 15638 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15639 | MockRead("Content-Length: 7\r\n\r\n"), |
| 15640 | MockRead("falafel"), |
| 15641 | MockRead(SYNCHRONOUS, OK), |
| 15642 | }; |
| 15643 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 15644 | http_writes, arraysize(http_writes)); |
| 15645 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 15646 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15647 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15648 | |
| 15649 | // Preconnect an SSL socket. A preconnect is needed because connect jobs are |
| 15650 | // cancelled when a normal transaction is cancelled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15651 | HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 15652 | http_stream_factory->PreconnectStreams(1, ssl_request); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15653 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15654 | |
| 15655 | // Start the HTTP request. Pool should stall. |
| 15656 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15657 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15658 | ASSERT_EQ(ERR_IO_PENDING, |
| 15659 | http_trans.Start(&http_request, http_callback.callback(), |
| 15660 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15661 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15662 | |
| 15663 | // The SSL connection will automatically be closed once the connection is |
| 15664 | // established, to let the HTTP request start. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15665 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15666 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15667 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15668 | EXPECT_EQ("falafel", response_data); |
| 15669 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15670 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15671 | } |
| 15672 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15673 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15674 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15675 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 15676 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15677 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15678 | |
| 15679 | HttpRequestInfo request; |
| 15680 | request.method = "POST"; |
| 15681 | request.url = GURL("http://www.foo.com/"); |
| 15682 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15683 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15684 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15685 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15686 | // Send headers successfully, but get an error while sending the body. |
| 15687 | MockWrite data_writes[] = { |
| 15688 | MockWrite("POST / HTTP/1.1\r\n" |
| 15689 | "Host: www.foo.com\r\n" |
| 15690 | "Connection: keep-alive\r\n" |
| 15691 | "Content-Length: 3\r\n\r\n"), |
| 15692 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15693 | }; |
| 15694 | |
| 15695 | MockRead data_reads[] = { |
| 15696 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 15697 | MockRead("hello world"), |
| 15698 | MockRead(SYNCHRONOUS, OK), |
| 15699 | }; |
| 15700 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15701 | arraysize(data_writes)); |
| 15702 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15703 | |
| 15704 | TestCompletionCallback callback; |
| 15705 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15706 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15707 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15708 | |
| 15709 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15710 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15711 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15712 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15713 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15714 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15715 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15716 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 15717 | |
| 15718 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15719 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15720 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15721 | EXPECT_EQ("hello world", response_data); |
| 15722 | } |
| 15723 | |
| 15724 | // This test makes sure the retry logic doesn't trigger when reading an error |
| 15725 | // response from a server that rejected a POST with a CONNECTION_RESET. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15726 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15727 | PostReadsErrorResponseAfterResetOnReusedSocket) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15728 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15729 | MockWrite data_writes[] = { |
| 15730 | MockWrite("GET / HTTP/1.1\r\n" |
| 15731 | "Host: www.foo.com\r\n" |
| 15732 | "Connection: keep-alive\r\n\r\n"), |
| 15733 | MockWrite("POST / HTTP/1.1\r\n" |
| 15734 | "Host: www.foo.com\r\n" |
| 15735 | "Connection: keep-alive\r\n" |
| 15736 | "Content-Length: 3\r\n\r\n"), |
| 15737 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15738 | }; |
| 15739 | |
| 15740 | MockRead data_reads[] = { |
| 15741 | MockRead("HTTP/1.1 200 Peachy\r\n" |
| 15742 | "Content-Length: 14\r\n\r\n"), |
| 15743 | MockRead("first response"), |
| 15744 | MockRead("HTTP/1.1 400 Not OK\r\n" |
| 15745 | "Content-Length: 15\r\n\r\n"), |
| 15746 | MockRead("second response"), |
| 15747 | MockRead(SYNCHRONOUS, OK), |
| 15748 | }; |
| 15749 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15750 | arraysize(data_writes)); |
| 15751 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15752 | |
| 15753 | TestCompletionCallback callback; |
| 15754 | HttpRequestInfo request1; |
| 15755 | request1.method = "GET"; |
| 15756 | request1.url = GURL("http://www.foo.com/"); |
| 15757 | request1.load_flags = 0; |
| 15758 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15759 | auto trans1 = |
| 15760 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15761 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15762 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15763 | |
| 15764 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15765 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15766 | |
| 15767 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15768 | ASSERT_TRUE(response1); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15769 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15770 | EXPECT_TRUE(response1->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15771 | EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine()); |
| 15772 | |
| 15773 | std::string response_data1; |
| 15774 | rv = ReadTransaction(trans1.get(), &response_data1); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15775 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15776 | EXPECT_EQ("first response", response_data1); |
| 15777 | // Delete the transaction to release the socket back into the socket pool. |
| 15778 | trans1.reset(); |
| 15779 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15780 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15781 | element_readers.push_back( |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15782 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15783 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15784 | |
| 15785 | HttpRequestInfo request2; |
| 15786 | request2.method = "POST"; |
| 15787 | request2.url = GURL("http://www.foo.com/"); |
| 15788 | request2.upload_data_stream = &upload_data_stream; |
| 15789 | request2.load_flags = 0; |
| 15790 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15791 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15792 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15793 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15794 | |
| 15795 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15796 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15797 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15798 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15799 | ASSERT_TRUE(response2); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15800 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15801 | EXPECT_TRUE(response2->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15802 | EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine()); |
| 15803 | |
| 15804 | std::string response_data2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15805 | rv = ReadTransaction(&trans2, &response_data2); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15806 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15807 | EXPECT_EQ("second response", response_data2); |
| 15808 | } |
| 15809 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15810 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15811 | PostReadsErrorResponseAfterResetPartialBodySent) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15812 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15813 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 15814 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15815 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15816 | |
| 15817 | HttpRequestInfo request; |
| 15818 | request.method = "POST"; |
| 15819 | request.url = GURL("http://www.foo.com/"); |
| 15820 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15821 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15822 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15823 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15824 | // Send headers successfully, but get an error while sending the body. |
| 15825 | MockWrite data_writes[] = { |
| 15826 | MockWrite("POST / HTTP/1.1\r\n" |
| 15827 | "Host: www.foo.com\r\n" |
| 15828 | "Connection: keep-alive\r\n" |
| 15829 | "Content-Length: 3\r\n\r\n" |
| 15830 | "fo"), |
| 15831 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15832 | }; |
| 15833 | |
| 15834 | MockRead data_reads[] = { |
| 15835 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 15836 | MockRead("hello world"), |
| 15837 | MockRead(SYNCHRONOUS, OK), |
| 15838 | }; |
| 15839 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15840 | arraysize(data_writes)); |
| 15841 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15842 | |
| 15843 | TestCompletionCallback callback; |
| 15844 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15845 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15846 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15847 | |
| 15848 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15849 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15850 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15851 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15852 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15853 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15854 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15855 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 15856 | |
| 15857 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15858 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15859 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15860 | EXPECT_EQ("hello world", response_data); |
| 15861 | } |
| 15862 | |
| 15863 | // This tests the more common case than the previous test, where headers and |
| 15864 | // body are not merged into a single request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15865 | TEST_F(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) { |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 15866 | ChunkedUploadDataStream upload_data_stream(0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15867 | |
| 15868 | HttpRequestInfo request; |
| 15869 | request.method = "POST"; |
| 15870 | request.url = GURL("http://www.foo.com/"); |
| 15871 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15872 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15873 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15874 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15875 | // Send headers successfully, but get an error while sending the body. |
| 15876 | MockWrite data_writes[] = { |
| 15877 | MockWrite("POST / HTTP/1.1\r\n" |
| 15878 | "Host: www.foo.com\r\n" |
| 15879 | "Connection: keep-alive\r\n" |
| 15880 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 15881 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15882 | }; |
| 15883 | |
| 15884 | MockRead data_reads[] = { |
| 15885 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 15886 | MockRead("hello world"), |
| 15887 | MockRead(SYNCHRONOUS, OK), |
| 15888 | }; |
| 15889 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15890 | arraysize(data_writes)); |
| 15891 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15892 | |
| 15893 | TestCompletionCallback callback; |
| 15894 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15895 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15896 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15897 | // Make sure the headers are sent before adding a chunk. This ensures that |
| 15898 | // they can't be merged with the body in a single send. Not currently |
| 15899 | // necessary since a chunked body is never merged with headers, but this makes |
| 15900 | // the test more future proof. |
| 15901 | base::RunLoop().RunUntilIdle(); |
| 15902 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 15903 | upload_data_stream.AppendData("last chunk", 10, true); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15904 | |
| 15905 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15906 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15907 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15908 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15909 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15910 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15911 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15912 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 15913 | |
| 15914 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15915 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15916 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15917 | EXPECT_EQ("hello world", response_data); |
| 15918 | } |
| 15919 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15920 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15921 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15922 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 15923 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15924 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15925 | |
| 15926 | HttpRequestInfo request; |
| 15927 | request.method = "POST"; |
| 15928 | request.url = GURL("http://www.foo.com/"); |
| 15929 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15930 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15931 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15932 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15933 | |
| 15934 | MockWrite data_writes[] = { |
| 15935 | MockWrite("POST / HTTP/1.1\r\n" |
| 15936 | "Host: www.foo.com\r\n" |
| 15937 | "Connection: keep-alive\r\n" |
| 15938 | "Content-Length: 3\r\n\r\n"), |
| 15939 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15940 | }; |
| 15941 | |
| 15942 | MockRead data_reads[] = { |
| 15943 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 15944 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 15945 | MockRead("hello world"), |
| 15946 | MockRead(SYNCHRONOUS, OK), |
| 15947 | }; |
| 15948 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15949 | arraysize(data_writes)); |
| 15950 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15951 | |
| 15952 | TestCompletionCallback callback; |
| 15953 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15954 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15955 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15956 | |
| 15957 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15958 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15959 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15960 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15961 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15962 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15963 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15964 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 15965 | |
| 15966 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15967 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15968 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15969 | EXPECT_EQ("hello world", response_data); |
| 15970 | } |
| 15971 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15972 | TEST_F(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15973 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15974 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 15975 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15976 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15977 | |
| 15978 | HttpRequestInfo request; |
| 15979 | request.method = "POST"; |
| 15980 | request.url = GURL("http://www.foo.com/"); |
| 15981 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15982 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15983 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15984 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15985 | // Send headers successfully, but get an error while sending the body. |
| 15986 | MockWrite data_writes[] = { |
| 15987 | MockWrite("POST / HTTP/1.1\r\n" |
| 15988 | "Host: www.foo.com\r\n" |
| 15989 | "Connection: keep-alive\r\n" |
| 15990 | "Content-Length: 3\r\n\r\n"), |
| 15991 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15992 | }; |
| 15993 | |
| 15994 | MockRead data_reads[] = { |
| 15995 | MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"), |
| 15996 | MockRead("hello world"), |
| 15997 | MockRead(SYNCHRONOUS, OK), |
| 15998 | }; |
| 15999 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16000 | arraysize(data_writes)); |
| 16001 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16002 | |
| 16003 | TestCompletionCallback callback; |
| 16004 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16005 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16006 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16007 | |
| 16008 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16009 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16010 | } |
| 16011 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16012 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16013 | PostIgnoresNonErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16014 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16015 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 16016 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16017 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16018 | |
| 16019 | HttpRequestInfo request; |
| 16020 | request.method = "POST"; |
| 16021 | request.url = GURL("http://www.foo.com/"); |
| 16022 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16023 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16024 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16025 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16026 | // Send headers successfully, but get an error while sending the body. |
| 16027 | MockWrite data_writes[] = { |
| 16028 | MockWrite("POST / HTTP/1.1\r\n" |
| 16029 | "Host: www.foo.com\r\n" |
| 16030 | "Connection: keep-alive\r\n" |
| 16031 | "Content-Length: 3\r\n\r\n"), |
| 16032 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16033 | }; |
| 16034 | |
| 16035 | MockRead data_reads[] = { |
| 16036 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 16037 | MockRead("HTTP/1.0 302 Redirect\r\n"), |
| 16038 | MockRead("Location: http://somewhere-else.com/\r\n"), |
| 16039 | MockRead("Content-Length: 0\r\n\r\n"), |
| 16040 | MockRead(SYNCHRONOUS, OK), |
| 16041 | }; |
| 16042 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16043 | arraysize(data_writes)); |
| 16044 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16045 | |
| 16046 | TestCompletionCallback callback; |
| 16047 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16048 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16049 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16050 | |
| 16051 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16052 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16053 | } |
| 16054 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16055 | TEST_F(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16056 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16057 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 16058 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16059 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16060 | |
| 16061 | HttpRequestInfo request; |
| 16062 | request.method = "POST"; |
| 16063 | request.url = GURL("http://www.foo.com/"); |
| 16064 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16065 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16066 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16067 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16068 | // Send headers successfully, but get an error while sending the body. |
| 16069 | MockWrite data_writes[] = { |
| 16070 | MockWrite("POST / HTTP/1.1\r\n" |
| 16071 | "Host: www.foo.com\r\n" |
| 16072 | "Connection: keep-alive\r\n" |
| 16073 | "Content-Length: 3\r\n\r\n"), |
| 16074 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16075 | }; |
| 16076 | |
| 16077 | MockRead data_reads[] = { |
| 16078 | MockRead("HTTP 0.9 rocks!"), |
| 16079 | MockRead(SYNCHRONOUS, OK), |
| 16080 | }; |
| 16081 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16082 | arraysize(data_writes)); |
| 16083 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16084 | |
| 16085 | TestCompletionCallback callback; |
| 16086 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16087 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16088 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16089 | |
| 16090 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16091 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16092 | } |
| 16093 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16094 | TEST_F(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16095 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16096 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 16097 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16098 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16099 | |
| 16100 | HttpRequestInfo request; |
| 16101 | request.method = "POST"; |
| 16102 | request.url = GURL("http://www.foo.com/"); |
| 16103 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16104 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16105 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16106 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16107 | // Send headers successfully, but get an error while sending the body. |
| 16108 | MockWrite data_writes[] = { |
| 16109 | MockWrite("POST / HTTP/1.1\r\n" |
| 16110 | "Host: www.foo.com\r\n" |
| 16111 | "Connection: keep-alive\r\n" |
| 16112 | "Content-Length: 3\r\n\r\n"), |
| 16113 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16114 | }; |
| 16115 | |
| 16116 | MockRead data_reads[] = { |
| 16117 | MockRead("HTTP/1.0 400 Not a Full Response\r\n"), |
| 16118 | MockRead(SYNCHRONOUS, OK), |
| 16119 | }; |
| 16120 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16121 | arraysize(data_writes)); |
| 16122 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16123 | |
| 16124 | TestCompletionCallback callback; |
| 16125 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16126 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16127 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16128 | |
| 16129 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16130 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16131 | } |
| 16132 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16133 | // Verify that proxy headers are not sent to the destination server when |
| 16134 | // establishing a tunnel for a secure WebSocket connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16135 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWssTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16136 | HttpRequestInfo request; |
| 16137 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16138 | request.url = GURL("wss://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16139 | AddWebSocketHeaders(&request.extra_headers); |
| 16140 | |
| 16141 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 16142 | session_deps_.proxy_service = |
| 16143 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16144 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16145 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16146 | |
| 16147 | // Since a proxy is configured, try to establish a tunnel. |
| 16148 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16149 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 16150 | "Host: www.example.org:443\r\n" |
| 16151 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16152 | |
| 16153 | // After calling trans->RestartWithAuth(), this is the request we should |
| 16154 | // be issuing -- the final header line contains the credentials. |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16155 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 16156 | "Host: www.example.org:443\r\n" |
| 16157 | "Proxy-Connection: keep-alive\r\n" |
| 16158 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16159 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16160 | MockWrite("GET / HTTP/1.1\r\n" |
| 16161 | "Host: www.example.org\r\n" |
| 16162 | "Connection: Upgrade\r\n" |
| 16163 | "Upgrade: websocket\r\n" |
| 16164 | "Origin: http://www.example.org\r\n" |
| 16165 | "Sec-WebSocket-Version: 13\r\n" |
| 16166 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16167 | }; |
| 16168 | |
| 16169 | // The proxy responds to the connect with a 407, using a persistent |
| 16170 | // connection. |
| 16171 | MockRead data_reads[] = { |
| 16172 | // No credentials. |
| 16173 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 16174 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 16175 | MockRead("Content-Length: 0\r\n"), |
| 16176 | MockRead("Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16177 | |
| 16178 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 16179 | |
| 16180 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 16181 | MockRead("Upgrade: websocket\r\n"), |
| 16182 | MockRead("Connection: Upgrade\r\n"), |
| 16183 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 16184 | }; |
| 16185 | |
| 16186 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16187 | arraysize(data_writes)); |
| 16188 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16189 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 16190 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16191 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16192 | auto trans = |
| 16193 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16194 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 16195 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 16196 | &websocket_stream_create_helper); |
| 16197 | |
| 16198 | { |
| 16199 | TestCompletionCallback callback; |
| 16200 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16201 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16202 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16203 | |
| 16204 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16205 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16206 | } |
| 16207 | |
| 16208 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 16209 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16210 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16211 | EXPECT_EQ(407, response->headers->response_code()); |
| 16212 | |
| 16213 | { |
| 16214 | TestCompletionCallback callback; |
| 16215 | |
| 16216 | int rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 16217 | callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16218 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16219 | |
| 16220 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16221 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16222 | } |
| 16223 | |
| 16224 | response = trans->GetResponseInfo(); |
| 16225 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16226 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16227 | |
| 16228 | EXPECT_EQ(101, response->headers->response_code()); |
| 16229 | |
| 16230 | trans.reset(); |
| 16231 | session->CloseAllConnections(); |
| 16232 | } |
| 16233 | |
| 16234 | // Verify that proxy headers are not sent to the destination server when |
| 16235 | // establishing a tunnel for an insecure WebSocket connection. |
| 16236 | // This requires the authentication info to be injected into the auth cache |
| 16237 | // due to crbug.com/395064 |
| 16238 | // TODO(ricea): Change to use a 407 response once issue 395064 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16239 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWsTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16240 | HttpRequestInfo request; |
| 16241 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16242 | request.url = GURL("ws://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16243 | AddWebSocketHeaders(&request.extra_headers); |
| 16244 | |
| 16245 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 16246 | session_deps_.proxy_service = |
| 16247 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16248 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16249 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16250 | |
| 16251 | MockWrite data_writes[] = { |
| 16252 | // Try to establish a tunnel for the WebSocket connection, with |
| 16253 | // credentials. Because WebSockets have a separate set of socket pools, |
| 16254 | // they cannot and will not use the same TCP/IP connection as the |
| 16255 | // preflight HTTP request. |
| 16256 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16257 | "CONNECT www.example.org:80 HTTP/1.1\r\n" |
| 16258 | "Host: www.example.org:80\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16259 | "Proxy-Connection: keep-alive\r\n" |
| 16260 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 16261 | |
| 16262 | MockWrite( |
| 16263 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16264 | "Host: www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16265 | "Connection: Upgrade\r\n" |
| 16266 | "Upgrade: websocket\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16267 | "Origin: http://www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16268 | "Sec-WebSocket-Version: 13\r\n" |
| 16269 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
| 16270 | }; |
| 16271 | |
| 16272 | MockRead data_reads[] = { |
| 16273 | // HTTP CONNECT with credentials. |
| 16274 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 16275 | |
| 16276 | // WebSocket connection established inside tunnel. |
| 16277 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 16278 | MockRead("Upgrade: websocket\r\n"), |
| 16279 | MockRead("Connection: Upgrade\r\n"), |
| 16280 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 16281 | }; |
| 16282 | |
| 16283 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16284 | arraysize(data_writes)); |
| 16285 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16286 | |
| 16287 | session->http_auth_cache()->Add( |
| 16288 | GURL("http://myproxy:70/"), "MyRealm1", HttpAuth::AUTH_SCHEME_BASIC, |
| 16289 | "Basic realm=MyRealm1", AuthCredentials(kFoo, kBar), "/"); |
| 16290 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16291 | auto trans = |
| 16292 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16293 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 16294 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 16295 | &websocket_stream_create_helper); |
| 16296 | |
| 16297 | TestCompletionCallback callback; |
| 16298 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16299 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16300 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16301 | |
| 16302 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16303 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16304 | |
| 16305 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 16306 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16307 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16308 | |
| 16309 | EXPECT_EQ(101, response->headers->response_code()); |
| 16310 | |
| 16311 | trans.reset(); |
| 16312 | session->CloseAllConnections(); |
| 16313 | } |
| 16314 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16315 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16316 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16317 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 16318 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16319 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16320 | |
| 16321 | HttpRequestInfo request; |
| 16322 | request.method = "POST"; |
| 16323 | request.url = GURL("http://www.foo.com/"); |
| 16324 | request.upload_data_stream = &upload_data_stream; |
| 16325 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16326 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16327 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16328 | MockWrite data_writes[] = { |
| 16329 | MockWrite("POST / HTTP/1.1\r\n" |
| 16330 | "Host: www.foo.com\r\n" |
| 16331 | "Connection: keep-alive\r\n" |
| 16332 | "Content-Length: 3\r\n\r\n"), |
| 16333 | MockWrite("foo"), |
| 16334 | }; |
| 16335 | |
| 16336 | MockRead data_reads[] = { |
| 16337 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16338 | MockRead(SYNCHRONOUS, OK), |
| 16339 | }; |
| 16340 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16341 | arraysize(data_writes)); |
| 16342 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16343 | |
| 16344 | TestCompletionCallback callback; |
| 16345 | |
| 16346 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16347 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16348 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16349 | |
| 16350 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16351 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16352 | |
| 16353 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16354 | trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16355 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16356 | trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16357 | } |
| 16358 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16359 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost100Continue) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16360 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16361 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 16362 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16363 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16364 | |
| 16365 | HttpRequestInfo request; |
| 16366 | request.method = "POST"; |
| 16367 | request.url = GURL("http://www.foo.com/"); |
| 16368 | request.upload_data_stream = &upload_data_stream; |
| 16369 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16370 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16371 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16372 | MockWrite data_writes[] = { |
| 16373 | MockWrite("POST / HTTP/1.1\r\n" |
| 16374 | "Host: www.foo.com\r\n" |
| 16375 | "Connection: keep-alive\r\n" |
| 16376 | "Content-Length: 3\r\n\r\n"), |
| 16377 | MockWrite("foo"), |
| 16378 | }; |
| 16379 | |
| 16380 | MockRead data_reads[] = { |
| 16381 | MockRead("HTTP/1.1 100 Continue\r\n\r\n"), |
| 16382 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16383 | MockRead(SYNCHRONOUS, OK), |
| 16384 | }; |
| 16385 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16386 | arraysize(data_writes)); |
| 16387 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16388 | |
| 16389 | TestCompletionCallback callback; |
| 16390 | |
| 16391 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16392 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16393 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16394 | |
| 16395 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16396 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16397 | |
| 16398 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16399 | trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16400 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16401 | trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16402 | } |
| 16403 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16404 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesChunkedPost) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16405 | ChunkedUploadDataStream upload_data_stream(0); |
| 16406 | |
| 16407 | HttpRequestInfo request; |
| 16408 | request.method = "POST"; |
| 16409 | request.url = GURL("http://www.foo.com/"); |
| 16410 | request.upload_data_stream = &upload_data_stream; |
| 16411 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16412 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16413 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16414 | // Send headers successfully, but get an error while sending the body. |
| 16415 | MockWrite data_writes[] = { |
| 16416 | MockWrite("POST / HTTP/1.1\r\n" |
| 16417 | "Host: www.foo.com\r\n" |
| 16418 | "Connection: keep-alive\r\n" |
| 16419 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 16420 | MockWrite("1\r\nf\r\n"), MockWrite("2\r\noo\r\n"), MockWrite("0\r\n\r\n"), |
| 16421 | }; |
| 16422 | |
| 16423 | MockRead data_reads[] = { |
| 16424 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16425 | MockRead(SYNCHRONOUS, OK), |
| 16426 | }; |
| 16427 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16428 | arraysize(data_writes)); |
| 16429 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16430 | |
| 16431 | TestCompletionCallback callback; |
| 16432 | |
| 16433 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16434 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16435 | |
| 16436 | base::RunLoop().RunUntilIdle(); |
| 16437 | upload_data_stream.AppendData("f", 1, false); |
| 16438 | |
| 16439 | base::RunLoop().RunUntilIdle(); |
| 16440 | upload_data_stream.AppendData("oo", 2, true); |
| 16441 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16442 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16443 | |
| 16444 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16445 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16446 | |
| 16447 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16448 | trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16449 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16450 | trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16451 | } |
| 16452 | |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16453 | // Confirm that transactions whose throttle is created in (and stays in) |
| 16454 | // the unthrottled state are not blocked. |
| 16455 | TEST_F(HttpNetworkTransactionTest, ThrottlingUnthrottled) { |
| 16456 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16457 | std::unique_ptr<HttpNetworkSession> session( |
| 16458 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16459 | |
| 16460 | // Send a simple request and make sure it goes through. |
| 16461 | HttpRequestInfo request; |
| 16462 | request.method = "GET"; |
| 16463 | request.url = GURL("http://www.example.org/"); |
| 16464 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16465 | auto trans = |
| 16466 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16467 | |
| 16468 | MockWrite data_writes[] = { |
| 16469 | MockWrite("GET / HTTP/1.1\r\n" |
| 16470 | "Host: www.example.org\r\n" |
| 16471 | "Connection: keep-alive\r\n\r\n"), |
| 16472 | }; |
| 16473 | MockRead data_reads[] = { |
| 16474 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16475 | MockRead(SYNCHRONOUS, OK), |
| 16476 | }; |
| 16477 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16478 | arraysize(data_writes)); |
| 16479 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16480 | |
| 16481 | TestCompletionCallback callback; |
| 16482 | trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16483 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 16484 | } |
| 16485 | |
| 16486 | // Confirm requests can be blocked by a throttler, and are resumed |
| 16487 | // when the throttle is unblocked. |
| 16488 | TEST_F(HttpNetworkTransactionTest, ThrottlingBasic) { |
| 16489 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16490 | std::unique_ptr<HttpNetworkSession> session( |
| 16491 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16492 | |
| 16493 | // Send a simple request and make sure it goes through. |
| 16494 | HttpRequestInfo request; |
| 16495 | request.method = "GET"; |
| 16496 | request.url = GURL("http://www.example.org/"); |
| 16497 | |
| 16498 | MockWrite data_writes[] = { |
| 16499 | MockWrite("GET / HTTP/1.1\r\n" |
| 16500 | "Host: www.example.org\r\n" |
| 16501 | "Connection: keep-alive\r\n\r\n"), |
| 16502 | }; |
| 16503 | MockRead data_reads[] = { |
| 16504 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16505 | MockRead(SYNCHRONOUS, OK), |
| 16506 | }; |
| 16507 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16508 | arraysize(data_writes)); |
| 16509 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16510 | |
| 16511 | // Start a request that will be throttled at start; confirm it |
| 16512 | // doesn't complete. |
| 16513 | throttler->set_throttle_new_requests(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16514 | auto trans = |
| 16515 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16516 | |
| 16517 | TestCompletionCallback callback; |
| 16518 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16519 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16520 | |
| 16521 | base::RunLoop().RunUntilIdle(); |
| 16522 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 16523 | EXPECT_FALSE(callback.have_result()); |
| 16524 | |
| 16525 | // Confirm the request goes on to complete when unthrottled. |
| 16526 | throttler->UnthrottleAllRequests(); |
| 16527 | base::RunLoop().RunUntilIdle(); |
| 16528 | ASSERT_TRUE(callback.have_result()); |
| 16529 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 16530 | } |
| 16531 | |
| 16532 | // Destroy a request while it's throttled. |
| 16533 | TEST_F(HttpNetworkTransactionTest, ThrottlingDestruction) { |
| 16534 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16535 | std::unique_ptr<HttpNetworkSession> session( |
| 16536 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16537 | |
| 16538 | // Send a simple request and make sure it goes through. |
| 16539 | HttpRequestInfo request; |
| 16540 | request.method = "GET"; |
| 16541 | request.url = GURL("http://www.example.org/"); |
| 16542 | |
| 16543 | MockWrite data_writes[] = { |
| 16544 | MockWrite("GET / HTTP/1.1\r\n" |
| 16545 | "Host: www.example.org\r\n" |
| 16546 | "Connection: keep-alive\r\n\r\n"), |
| 16547 | }; |
| 16548 | MockRead data_reads[] = { |
| 16549 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16550 | MockRead(SYNCHRONOUS, OK), |
| 16551 | }; |
| 16552 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16553 | arraysize(data_writes)); |
| 16554 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16555 | |
| 16556 | // Start a request that will be throttled at start; confirm it |
| 16557 | // doesn't complete. |
| 16558 | throttler->set_throttle_new_requests(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16559 | auto trans = |
| 16560 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16561 | |
| 16562 | TestCompletionCallback callback; |
| 16563 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16564 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16565 | |
| 16566 | base::RunLoop().RunUntilIdle(); |
| 16567 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 16568 | EXPECT_FALSE(callback.have_result()); |
| 16569 | |
| 16570 | EXPECT_EQ(1u, throttler->num_outstanding_requests()); |
| 16571 | trans.reset(); |
| 16572 | EXPECT_EQ(0u, throttler->num_outstanding_requests()); |
| 16573 | } |
| 16574 | |
| 16575 | // Confirm the throttler receives SetPriority calls. |
| 16576 | TEST_F(HttpNetworkTransactionTest, ThrottlingPrioritySet) { |
| 16577 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16578 | std::unique_ptr<HttpNetworkSession> session( |
| 16579 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16580 | |
| 16581 | // Send a simple request and make sure it goes through. |
| 16582 | HttpRequestInfo request; |
| 16583 | request.method = "GET"; |
| 16584 | request.url = GURL("http://www.example.org/"); |
| 16585 | |
| 16586 | MockWrite data_writes[] = { |
| 16587 | MockWrite("GET / HTTP/1.1\r\n" |
| 16588 | "Host: www.example.org\r\n" |
| 16589 | "Connection: keep-alive\r\n\r\n"), |
| 16590 | }; |
| 16591 | MockRead data_reads[] = { |
| 16592 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16593 | MockRead(SYNCHRONOUS, OK), |
| 16594 | }; |
| 16595 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16596 | arraysize(data_writes)); |
| 16597 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16598 | |
| 16599 | throttler->set_throttle_new_requests(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16600 | auto trans = base::MakeUnique<HttpNetworkTransaction>(IDLE, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16601 | // Start the transaction to associate a throttle with it. |
| 16602 | TestCompletionCallback callback; |
| 16603 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16604 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16605 | |
| 16606 | EXPECT_EQ(0, throttler->num_set_priority_calls()); |
| 16607 | trans->SetPriority(LOW); |
| 16608 | EXPECT_EQ(1, throttler->num_set_priority_calls()); |
| 16609 | EXPECT_EQ(LOW, throttler->last_priority_set()); |
| 16610 | |
| 16611 | throttler->UnthrottleAllRequests(); |
| 16612 | base::RunLoop().RunUntilIdle(); |
| 16613 | ASSERT_TRUE(callback.have_result()); |
| 16614 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 16615 | } |
| 16616 | |
| 16617 | // Confirm that unthrottling from a SetPriority call by the |
| 16618 | // throttler works properly. |
| 16619 | TEST_F(HttpNetworkTransactionTest, ThrottlingPrioritySetUnthrottle) { |
| 16620 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16621 | std::unique_ptr<HttpNetworkSession> session( |
| 16622 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16623 | |
| 16624 | // Send a simple request and make sure it goes through. |
| 16625 | HttpRequestInfo request; |
| 16626 | request.method = "GET"; |
| 16627 | request.url = GURL("http://www.example.org/"); |
| 16628 | |
| 16629 | MockWrite data_writes[] = { |
| 16630 | MockWrite("GET / HTTP/1.1\r\n" |
| 16631 | "Host: www.example.org\r\n" |
| 16632 | "Connection: keep-alive\r\n\r\n"), |
| 16633 | }; |
| 16634 | MockRead data_reads[] = { |
| 16635 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16636 | MockRead(SYNCHRONOUS, OK), |
| 16637 | }; |
| 16638 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16639 | arraysize(data_writes)); |
| 16640 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16641 | |
| 16642 | StaticSocketDataProvider reads1(data_reads, arraysize(data_reads), |
| 16643 | data_writes, arraysize(data_writes)); |
| 16644 | session_deps_.socket_factory->AddSocketDataProvider(&reads1); |
| 16645 | |
| 16646 | // Start a request that will be throttled at start; confirm it |
| 16647 | // doesn't complete. |
| 16648 | throttler->set_throttle_new_requests(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16649 | auto trans = |
| 16650 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16651 | |
| 16652 | TestCompletionCallback callback; |
| 16653 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16654 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16655 | |
| 16656 | base::RunLoop().RunUntilIdle(); |
| 16657 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 16658 | EXPECT_FALSE(callback.have_result()); |
| 16659 | |
| 16660 | // Create a new request, call SetPriority on it to unthrottle, |
| 16661 | // and make sure that allows the original request to complete. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16662 | auto trans1 = base::MakeUnique<HttpNetworkTransaction>(LOW, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16663 | throttler->set_priority_change_closure( |
| 16664 | base::Bind(&TestNetworkStreamThrottler::UnthrottleAllRequests, |
| 16665 | base::Unretained(throttler))); |
| 16666 | |
| 16667 | // Start the transaction to associate a throttle with it. |
| 16668 | TestCompletionCallback callback1; |
| 16669 | rv = trans1->Start(&request, callback1.callback(), NetLogWithSource()); |
| 16670 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16671 | |
| 16672 | trans1->SetPriority(IDLE); |
| 16673 | |
| 16674 | base::RunLoop().RunUntilIdle(); |
| 16675 | ASSERT_TRUE(callback.have_result()); |
| 16676 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 16677 | ASSERT_TRUE(callback1.have_result()); |
| 16678 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 16679 | } |
| 16680 | |
| 16681 | // Transaction will be destroyed when the unique_ptr goes out of scope. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16682 | void DestroyTransaction(std::unique_ptr<HttpNetworkTransaction> transaction) {} |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16683 | |
| 16684 | // Confirm that destroying a transaction from a SetPriority call by the |
| 16685 | // throttler works properly. |
| 16686 | TEST_F(HttpNetworkTransactionTest, ThrottlingPrioritySetDestroy) { |
| 16687 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16688 | std::unique_ptr<HttpNetworkSession> session( |
| 16689 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16690 | |
| 16691 | // Send a simple request and make sure it goes through. |
| 16692 | HttpRequestInfo request; |
| 16693 | request.method = "GET"; |
| 16694 | request.url = GURL("http://www.example.org/"); |
| 16695 | |
| 16696 | MockWrite data_writes[] = { |
| 16697 | MockWrite("GET / HTTP/1.1\r\n" |
| 16698 | "Host: www.example.org\r\n" |
| 16699 | "Connection: keep-alive\r\n\r\n"), |
| 16700 | }; |
| 16701 | MockRead data_reads[] = { |
| 16702 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16703 | MockRead(SYNCHRONOUS, OK), |
| 16704 | }; |
| 16705 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16706 | arraysize(data_writes)); |
| 16707 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16708 | |
| 16709 | StaticSocketDataProvider reads1(data_reads, arraysize(data_reads), |
| 16710 | data_writes, arraysize(data_writes)); |
| 16711 | session_deps_.socket_factory->AddSocketDataProvider(&reads1); |
| 16712 | |
| 16713 | // Start a request that will be throttled at start; confirm it |
| 16714 | // doesn't complete. |
| 16715 | throttler->set_throttle_new_requests(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16716 | auto trans = |
| 16717 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16718 | |
| 16719 | TestCompletionCallback callback; |
| 16720 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16721 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16722 | |
| 16723 | base::RunLoop().RunUntilIdle(); |
| 16724 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 16725 | EXPECT_FALSE(callback.have_result()); |
| 16726 | |
| 16727 | // Arrange for the set priority call on the above transaction to delete |
| 16728 | // the transaction. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16729 | HttpNetworkTransaction* trans_ptr(trans.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16730 | throttler->set_priority_change_closure( |
| 16731 | base::Bind(&DestroyTransaction, base::Passed(&trans))); |
| 16732 | |
| 16733 | // Call it and check results (partially a "doesn't crash" test). |
| 16734 | trans_ptr->SetPriority(IDLE); |
| 16735 | trans_ptr = nullptr; // No longer a valid pointer. |
| 16736 | |
| 16737 | base::RunLoop().RunUntilIdle(); |
| 16738 | ASSERT_FALSE(callback.have_result()); |
| 16739 | } |
| 16740 | |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16741 | #if !defined(OS_IOS) |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16742 | TEST_F(HttpNetworkTransactionTest, TokenBindingSpdy) { |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16743 | const std::string https_url = "https://www.example.com"; |
| 16744 | HttpRequestInfo request; |
| 16745 | request.url = GURL(https_url); |
| 16746 | request.method = "GET"; |
| 16747 | |
| 16748 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 16749 | ssl.token_binding_negotiated = true; |
| 16750 | ssl.token_binding_key_param = TB_PARAM_ECDSAP256; |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16751 | ssl.next_proto = kProtoHTTP2; |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16752 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16753 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16754 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16755 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 16756 | MockRead reads[] = {CreateMockRead(resp), CreateMockRead(body), |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16757 | MockRead(ASYNC, ERR_IO_PENDING)}; |
| 16758 | StaticSocketDataProvider data(reads, arraysize(reads), nullptr, 0); |
| 16759 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16760 | session_deps_.channel_id_service = |
| 16761 | base::MakeUnique<ChannelIDService>(new DefaultChannelIDStore(nullptr)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16762 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16763 | |
| 16764 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 16765 | TestCompletionCallback callback; |
| 16766 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16767 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
fdoray | f33fede | 2017-05-11 21:18:10 | [diff] [blame] | 16768 | |
| 16769 | NetTestSuite::GetScopedTaskEnvironment()->RunUntilIdle(); |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16770 | |
| 16771 | EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); |
| 16772 | HttpRequestHeaders headers; |
| 16773 | ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); |
| 16774 | EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); |
| 16775 | } |
| 16776 | #endif // !defined(OS_IOS) |
| 16777 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 16778 | void CheckContentEncodingMatching(SpdySessionDependencies* session_deps, |
| 16779 | const std::string& accept_encoding, |
| 16780 | const std::string& content_encoding, |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 16781 | const std::string& location, |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 16782 | bool should_match) { |
| 16783 | HttpRequestInfo request; |
| 16784 | request.method = "GET"; |
| 16785 | request.url = GURL("http://www.foo.com/"); |
| 16786 | request.extra_headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, |
| 16787 | accept_encoding); |
| 16788 | |
| 16789 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps)); |
| 16790 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 16791 | // Send headers successfully, but get an error while sending the body. |
| 16792 | MockWrite data_writes[] = { |
| 16793 | MockWrite("GET / HTTP/1.1\r\n" |
| 16794 | "Host: www.foo.com\r\n" |
| 16795 | "Connection: keep-alive\r\n" |
| 16796 | "Accept-Encoding: "), |
| 16797 | MockWrite(accept_encoding.data()), MockWrite("\r\n\r\n"), |
| 16798 | }; |
| 16799 | |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 16800 | std::string response_code = "200 OK"; |
| 16801 | std::string extra; |
| 16802 | if (!location.empty()) { |
| 16803 | response_code = "301 Redirect\r\nLocation: "; |
| 16804 | response_code.append(location); |
| 16805 | } |
| 16806 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 16807 | MockRead data_reads[] = { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 16808 | MockRead("HTTP/1.0 "), |
| 16809 | MockRead(response_code.data()), |
| 16810 | MockRead("\r\nContent-Encoding: "), |
| 16811 | MockRead(content_encoding.data()), |
| 16812 | MockRead("\r\n\r\n"), |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 16813 | MockRead(SYNCHRONOUS, OK), |
| 16814 | }; |
| 16815 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16816 | arraysize(data_writes)); |
| 16817 | session_deps->socket_factory->AddSocketDataProvider(&data); |
| 16818 | |
| 16819 | TestCompletionCallback callback; |
| 16820 | |
| 16821 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 16822 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16823 | |
| 16824 | rv = callback.WaitForResult(); |
| 16825 | if (should_match) { |
| 16826 | EXPECT_THAT(rv, IsOk()); |
| 16827 | } else { |
| 16828 | EXPECT_THAT(rv, IsError(ERR_CONTENT_DECODING_FAILED)); |
| 16829 | } |
| 16830 | } |
| 16831 | |
| 16832 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding1) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 16833 | CheckContentEncodingMatching(&session_deps_, "gzip,sdch", "br", "", false); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 16834 | } |
| 16835 | |
| 16836 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding2) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 16837 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "", "", |
| 16838 | true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 16839 | } |
| 16840 | |
| 16841 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding3) { |
| 16842 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 16843 | "", false); |
| 16844 | } |
| 16845 | |
| 16846 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding4) { |
| 16847 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
| 16848 | "www.foo.com/other", true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 16849 | } |
| 16850 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 16851 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsSync) { |
| 16852 | ProxyConfig proxy_config; |
| 16853 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 16854 | proxy_config.set_pac_mandatory(true); |
| 16855 | MockAsyncProxyResolver resolver; |
| 16856 | session_deps_.proxy_service.reset(new ProxyService( |
| 16857 | base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), |
| 16858 | base::WrapUnique(new FailingProxyResolverFactory), nullptr)); |
| 16859 | |
| 16860 | HttpRequestInfo request; |
| 16861 | request.method = "GET"; |
| 16862 | request.url = GURL("http://www.example.org/"); |
| 16863 | |
| 16864 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 16865 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 16866 | |
| 16867 | TestCompletionCallback callback; |
| 16868 | |
| 16869 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 16870 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16871 | EXPECT_THAT(callback.WaitForResult(), |
| 16872 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 16873 | } |
| 16874 | |
| 16875 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsAsync) { |
| 16876 | ProxyConfig proxy_config; |
| 16877 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 16878 | proxy_config.set_pac_mandatory(true); |
| 16879 | MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 16880 | new MockAsyncProxyResolverFactory(false); |
| 16881 | MockAsyncProxyResolver resolver; |
| 16882 | session_deps_.proxy_service.reset( |
| 16883 | new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), |
| 16884 | base::WrapUnique(proxy_resolver_factory), nullptr)); |
| 16885 | HttpRequestInfo request; |
| 16886 | request.method = "GET"; |
| 16887 | request.url = GURL("http://www.example.org/"); |
| 16888 | |
| 16889 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 16890 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 16891 | |
| 16892 | TestCompletionCallback callback; |
| 16893 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 16894 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16895 | |
| 16896 | proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder( |
| 16897 | ERR_FAILED, &resolver); |
| 16898 | EXPECT_THAT(callback.WaitForResult(), |
| 16899 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 16900 | } |
| 16901 | |
| 16902 | TEST_F(HttpNetworkTransactionTest, NoSupportedProxies) { |
| 16903 | session_deps_.proxy_service = |
| 16904 | ProxyService::CreateFixedFromPacResult("QUIC myproxy.org:443"); |
| 16905 | session_deps_.enable_quic = false; |
| 16906 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 16907 | |
| 16908 | HttpRequestInfo request; |
| 16909 | request.method = "GET"; |
| 16910 | request.url = GURL("http://www.example.org/"); |
| 16911 | |
| 16912 | TestCompletionCallback callback; |
| 16913 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 16914 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 16915 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16916 | |
| 16917 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_NO_SUPPORTED_PROXIES)); |
| 16918 | } |
| 16919 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 16920 | } // namespace net |