[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 */) |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 736 | : HttpProxyClientSocketPool(0, 0, NULL, NULL, NULL) { |
hashimoto | 0d3e4fb | 2015-01-09 05:02:50 | [diff] [blame] | 737 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 738 | |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 739 | template <> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 740 | CaptureGroupNameSSLSocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 741 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 742 | CertVerifier* cert_verifier) |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 743 | : SSLClientSocketPool(0, |
| 744 | 0, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 745 | cert_verifier, |
| 746 | NULL, |
| 747 | NULL, |
[email protected] | 284303b6 | 2013-11-28 15:11:54 | [diff] [blame] | 748 | NULL, |
eranm | 6571b2b | 2014-12-03 15:53:23 | [diff] [blame] | 749 | NULL, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 750 | std::string(), |
| 751 | NULL, |
| 752 | NULL, |
| 753 | NULL, |
| 754 | NULL, |
| 755 | NULL, |
[email protected] | 8e45855 | 2014-08-05 00:02:15 | [diff] [blame] | 756 | NULL) { |
| 757 | } |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 758 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 759 | //----------------------------------------------------------------------------- |
| 760 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 761 | // Helper functions for validating that AuthChallengeInfo's are correctly |
| 762 | // configured for common cases. |
| 763 | bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 764 | if (!auth_challenge) |
| 765 | return false; |
| 766 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 767 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 768 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 769 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 770 | return true; |
| 771 | } |
| 772 | |
| 773 | bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 774 | if (!auth_challenge) |
| 775 | return false; |
| 776 | EXPECT_TRUE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 777 | EXPECT_EQ("http://myproxy:70", auth_challenge->challenger.Serialize()); |
| 778 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 779 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
| 780 | return true; |
| 781 | } |
| 782 | |
| 783 | bool CheckBasicSecureProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 784 | if (!auth_challenge) |
| 785 | return false; |
| 786 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 787 | EXPECT_EQ("https://myproxy:70", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 788 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 789 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 790 | return true; |
| 791 | } |
| 792 | |
| 793 | bool CheckDigestServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 794 | if (!auth_challenge) |
| 795 | return false; |
| 796 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 797 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 798 | EXPECT_EQ("digestive", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 799 | EXPECT_EQ(kDigestAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 800 | return true; |
| 801 | } |
| 802 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 803 | #if defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 804 | bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 805 | if (!auth_challenge) |
| 806 | return false; |
| 807 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 808 | EXPECT_EQ("http://172.22.68.17", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 809 | EXPECT_EQ(std::string(), auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 810 | EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 811 | return true; |
| 812 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 813 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 814 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 815 | } // namespace |
| 816 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 817 | TEST_F(HttpNetworkTransactionTest, Basic) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 818 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 819 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 820 | } |
| 821 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 822 | TEST_F(HttpNetworkTransactionTest, SimpleGET) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 823 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 824 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 825 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 826 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 827 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 828 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 829 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 830 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 831 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 832 | EXPECT_EQ("hello world", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 833 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 834 | EXPECT_EQ(reads_size, out.total_received_bytes); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 835 | EXPECT_EQ(0u, out.connection_attempts.size()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 836 | |
| 837 | EXPECT_FALSE(out.remote_endpoint_after_start.address().empty()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 838 | } |
| 839 | |
| 840 | // Response with no status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 841 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeaders) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 842 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 843 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 844 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 845 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 846 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 847 | arraysize(data_reads)); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 848 | EXPECT_THAT(out.rv, IsOk()); |
| 849 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 850 | EXPECT_EQ("hello world", out.response_data); |
| 851 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 852 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 853 | } |
| 854 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 855 | // Response with no status line, and a weird port. Should fail by default. |
| 856 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPort) { |
| 857 | MockRead data_reads[] = { |
| 858 | MockRead("hello world"), MockRead(SYNCHRONOUS, OK), |
| 859 | }; |
| 860 | |
| 861 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 862 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 863 | |
| 864 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 865 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 866 | HttpRequestInfo request; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 867 | auto trans = |
| 868 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 869 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 870 | request.method = "GET"; |
| 871 | request.url = GURL("http://www.example.com:2000/"); |
| 872 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 873 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 874 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_INVALID_HTTP_RESPONSE)); |
| 875 | } |
| 876 | |
| 877 | // Response with no status line, and a weird port. Option to allow weird ports |
| 878 | // enabled. |
| 879 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPortAllowed) { |
| 880 | MockRead data_reads[] = { |
| 881 | MockRead("hello world"), MockRead(SYNCHRONOUS, OK), |
| 882 | }; |
| 883 | |
| 884 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 885 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 886 | session_deps_.http_09_on_non_default_ports_enabled = true; |
| 887 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 888 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 889 | HttpRequestInfo request; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 890 | auto trans = |
| 891 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 892 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 893 | request.method = "GET"; |
| 894 | request.url = GURL("http://www.example.com:2000/"); |
| 895 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 896 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 897 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 898 | |
| 899 | const HttpResponseInfo* info = trans->GetResponseInfo(); |
| 900 | ASSERT_TRUE(info->headers); |
| 901 | EXPECT_EQ("HTTP/0.9 200 OK", info->headers->GetStatusLine()); |
| 902 | |
| 903 | // Don't bother to read the body - that's verified elsewhere, important thing |
| 904 | // is that the option to allow HTTP/0.9 on non-default ports is respected. |
| 905 | } |
| 906 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 907 | // Allow up to 4 bytes of junk to precede status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 908 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk3Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 909 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 910 | MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 911 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 912 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 913 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 914 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 915 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 916 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 917 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 918 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 919 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 920 | } |
| 921 | |
| 922 | // Allow up to 4 bytes of junk to precede status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 923 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 924 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 925 | MockRead("\n\nQJHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 926 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 927 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 928 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 929 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 930 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 931 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 932 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 933 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 934 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 935 | } |
| 936 | |
| 937 | // Beyond 4 bytes of slop and it should fail to find a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 938 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk5Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 939 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 940 | MockRead("xxxxxHTTP/1.1 404 Not Found\nServer: blah"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 941 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 942 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 943 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 944 | arraysize(data_reads)); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 945 | EXPECT_THAT(out.rv, IsOk()); |
| 946 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 947 | EXPECT_EQ("xxxxxHTTP/1.1 404 Not Found\nServer: blah", out.response_data); |
| 948 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 949 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 950 | } |
| 951 | |
| 952 | // Same as StatusLineJunk4Bytes, except the read chunks are smaller. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 953 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes_Slow) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 954 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 955 | MockRead("\n"), |
| 956 | MockRead("\n"), |
| 957 | MockRead("Q"), |
| 958 | MockRead("J"), |
| 959 | MockRead("HTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 960 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 961 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 962 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 963 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 964 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 965 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 966 | EXPECT_EQ("DATA", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 967 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 968 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 969 | } |
| 970 | |
| 971 | // Close the connection before enough bytes to have a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 972 | TEST_F(HttpNetworkTransactionTest, StatusLinePartial) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 973 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 974 | MockRead("HTT"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 975 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 976 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 977 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 978 | arraysize(data_reads)); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 979 | EXPECT_THAT(out.rv, IsOk()); |
| 980 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 981 | EXPECT_EQ("HTT", out.response_data); |
| 982 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 983 | EXPECT_EQ(reads_size, out.total_received_bytes); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 984 | } |
| 985 | |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 986 | // Simulate a 204 response, lacking a Content-Length header, sent over a |
| 987 | // persistent connection. The response should still terminate since a 204 |
| 988 | // cannot have a response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 989 | TEST_F(HttpNetworkTransactionTest, StopsReading204) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 990 | char junk[] = "junk"; |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 991 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 992 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 993 | MockRead(junk), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 994 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 995 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 996 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 997 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 998 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 999 | EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); |
| 1000 | EXPECT_EQ("", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 1001 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 1002 | int64_t response_size = reads_size - strlen(junk); |
| 1003 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 1004 | } |
| 1005 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1006 | // A simple request using chunked encoding with some extra data after. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1007 | TEST_F(HttpNetworkTransactionTest, ChunkedEncoding) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1008 | std::string final_chunk = "0\r\n\r\n"; |
| 1009 | std::string extra_data = "HTTP/1.1 200 OK\r\n"; |
| 1010 | std::string last_read = final_chunk + extra_data; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1011 | MockRead data_reads[] = { |
| 1012 | MockRead("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"), |
| 1013 | MockRead("5\r\nHello\r\n"), |
| 1014 | MockRead("1\r\n"), |
| 1015 | MockRead(" \r\n"), |
| 1016 | MockRead("5\r\nworld\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1017 | MockRead(last_read.data()), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1018 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1019 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1020 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1021 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1022 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1023 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1024 | EXPECT_EQ("Hello world", out.response_data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 1025 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
| 1026 | int64_t response_size = reads_size - extra_data.size(); |
| 1027 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1028 | } |
| 1029 | |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1030 | // Next tests deal with http://crbug.com/56344. |
| 1031 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1032 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1033 | MultipleContentLengthHeadersNoTransferEncoding) { |
| 1034 | MockRead data_reads[] = { |
| 1035 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1036 | MockRead("Content-Length: 10\r\n"), |
| 1037 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1038 | }; |
| 1039 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1040 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1041 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1042 | } |
| 1043 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1044 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1045 | DuplicateContentLengthHeadersNoTransferEncoding) { |
| 1046 | MockRead data_reads[] = { |
| 1047 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1048 | MockRead("Content-Length: 5\r\n"), |
| 1049 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1050 | MockRead("Hello"), |
| 1051 | }; |
| 1052 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1053 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1054 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1055 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1056 | EXPECT_EQ("Hello", out.response_data); |
| 1057 | } |
| 1058 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1059 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1060 | ComplexContentLengthHeadersNoTransferEncoding) { |
| 1061 | // More than 2 dupes. |
| 1062 | { |
| 1063 | MockRead data_reads[] = { |
| 1064 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1065 | MockRead("Content-Length: 5\r\n"), |
| 1066 | MockRead("Content-Length: 5\r\n"), |
| 1067 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1068 | MockRead("Hello"), |
| 1069 | }; |
| 1070 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1071 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1072 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1073 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1074 | EXPECT_EQ("Hello", out.response_data); |
| 1075 | } |
| 1076 | // HTTP/1.0 |
| 1077 | { |
| 1078 | MockRead data_reads[] = { |
| 1079 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1080 | MockRead("Content-Length: 5\r\n"), |
| 1081 | MockRead("Content-Length: 5\r\n"), |
| 1082 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1083 | MockRead("Hello"), |
| 1084 | }; |
| 1085 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1086 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1087 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1088 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 1089 | EXPECT_EQ("Hello", out.response_data); |
| 1090 | } |
| 1091 | // 2 dupes and one mismatched. |
| 1092 | { |
| 1093 | MockRead data_reads[] = { |
| 1094 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1095 | MockRead("Content-Length: 10\r\n"), |
| 1096 | MockRead("Content-Length: 10\r\n"), |
| 1097 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1098 | }; |
| 1099 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1100 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1101 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1102 | } |
| 1103 | } |
| 1104 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1105 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1106 | MultipleContentLengthHeadersTransferEncoding) { |
| 1107 | MockRead data_reads[] = { |
| 1108 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1109 | MockRead("Content-Length: 666\r\n"), |
| 1110 | MockRead("Content-Length: 1337\r\n"), |
| 1111 | MockRead("Transfer-Encoding: chunked\r\n\r\n"), |
| 1112 | MockRead("5\r\nHello\r\n"), |
| 1113 | MockRead("1\r\n"), |
| 1114 | MockRead(" \r\n"), |
| 1115 | MockRead("5\r\nworld\r\n"), |
| 1116 | MockRead("0\r\n\r\nHTTP/1.1 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1117 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1118 | }; |
| 1119 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1120 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1121 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1122 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1123 | EXPECT_EQ("Hello world", out.response_data); |
| 1124 | } |
| 1125 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1126 | // Next tests deal with http://crbug.com/98895. |
| 1127 | |
| 1128 | // Checks that a single Content-Disposition header results in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1129 | TEST_F(HttpNetworkTransactionTest, SingleContentDispositionHeader) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1130 | MockRead data_reads[] = { |
| 1131 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1132 | MockRead("Content-Disposition: attachment;filename=\"salutations.txt\"r\n"), |
| 1133 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1134 | MockRead("Hello"), |
| 1135 | }; |
| 1136 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1137 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1138 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1139 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1140 | EXPECT_EQ("Hello", out.response_data); |
| 1141 | } |
| 1142 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1143 | // Checks that two identical Content-Disposition headers result in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1144 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1145 | MockRead data_reads[] = { |
| 1146 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1147 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1148 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1149 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1150 | MockRead("Hello"), |
| 1151 | }; |
| 1152 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1153 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1154 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1155 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1156 | EXPECT_EQ("Hello", out.response_data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1157 | } |
| 1158 | |
| 1159 | // Checks that two distinct Content-Disposition headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1160 | TEST_F(HttpNetworkTransactionTest, TwoDistinctContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1161 | MockRead data_reads[] = { |
| 1162 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1163 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1164 | MockRead("Content-Disposition: attachment;filename=\"hi.txt\"r\n"), |
| 1165 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1166 | MockRead("Hello"), |
| 1167 | }; |
| 1168 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1169 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1170 | EXPECT_THAT(out.rv, |
| 1171 | IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1172 | } |
| 1173 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1174 | // Checks that two identical Location headers result in no error. |
| 1175 | // Also tests Location header behavior. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1176 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1177 | MockRead data_reads[] = { |
| 1178 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1179 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1180 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1181 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1182 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1183 | }; |
| 1184 | |
| 1185 | HttpRequestInfo request; |
| 1186 | request.method = "GET"; |
| 1187 | request.url = GURL("http://redirect.com/"); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1188 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1189 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1190 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1191 | |
| 1192 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1193 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1194 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1195 | TestCompletionCallback callback; |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1196 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1197 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1198 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1199 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1200 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1201 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1202 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1203 | ASSERT_TRUE(response); |
| 1204 | ASSERT_TRUE(response->headers); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1205 | EXPECT_EQ("HTTP/1.1 302 Redirect", response->headers->GetStatusLine()); |
| 1206 | std::string url; |
| 1207 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 1208 | EXPECT_EQ("http://good.com/", url); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1209 | EXPECT_TRUE(response->proxy_server.is_direct()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1210 | } |
| 1211 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1212 | // Checks that two distinct Location headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1213 | TEST_F(HttpNetworkTransactionTest, TwoDistinctLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1214 | MockRead data_reads[] = { |
| 1215 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1216 | MockRead("Location: http://good.com/\r\n"), |
| 1217 | MockRead("Location: http://evil.com/\r\n"), |
| 1218 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1219 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1220 | }; |
| 1221 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1222 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1223 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1224 | } |
| 1225 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1226 | // Do a request using the HEAD method. Verify that we don't try to read the |
| 1227 | // message body (since HEAD has none). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1228 | TEST_F(HttpNetworkTransactionTest, Head) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1229 | HttpRequestInfo request; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1230 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1231 | request.url = GURL("http://www.example.org/"); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1232 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1233 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1234 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1235 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1236 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1237 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 1238 | base::Unretained(&headers_handler))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1239 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1240 | MockWrite data_writes1[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 1241 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 1242 | "Host: www.example.org\r\n" |
| 1243 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1244 | }; |
| 1245 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1246 | MockRead("HTTP/1.1 404 Not Found\r\n"), MockRead("Server: Blah\r\n"), |
| 1247 | MockRead("Content-Length: 1234\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1248 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1249 | // No response body because the test stops reading here. |
| 1250 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1251 | }; |
| 1252 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1253 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 1254 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1255 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1256 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1257 | TestCompletionCallback callback1; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1258 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1259 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1260 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1261 | |
| 1262 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1263 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1264 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1265 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1266 | ASSERT_TRUE(response); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1267 | |
| 1268 | // Check that the headers got parsed. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1269 | EXPECT_TRUE(response->headers); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1270 | EXPECT_EQ(1234, response->headers->GetContentLength()); |
| 1271 | EXPECT_EQ("HTTP/1.1 404 Not Found", response->headers->GetStatusLine()); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1272 | EXPECT_TRUE(response->proxy_server.is_direct()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1273 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 1274 | EXPECT_FALSE(headers_handler.observed_before_headers_sent_with_proxy()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1275 | |
| 1276 | std::string server_header; |
olli.raula | ee489a5 | 2016-01-25 08:37:10 | [diff] [blame] | 1277 | size_t iter = 0; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1278 | bool has_server_header = response->headers->EnumerateHeader( |
| 1279 | &iter, "Server", &server_header); |
| 1280 | EXPECT_TRUE(has_server_header); |
| 1281 | EXPECT_EQ("Blah", server_header); |
| 1282 | |
| 1283 | // Reading should give EOF right away, since there is no message body |
| 1284 | // (despite non-zero content-length). |
| 1285 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1286 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1287 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1288 | EXPECT_EQ("", response_data); |
| 1289 | } |
| 1290 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1291 | TEST_F(HttpNetworkTransactionTest, ReuseConnection) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1292 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1293 | |
| 1294 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1295 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1296 | MockRead("hello"), |
| 1297 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1298 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1299 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1300 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1301 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1302 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1303 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1304 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1305 | "hello", "world" |
| 1306 | }; |
| 1307 | |
| 1308 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1309 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1310 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1311 | request.url = GURL("http://www.example.org/"); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1312 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1313 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1314 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1315 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1316 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1317 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1318 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1319 | |
| 1320 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1321 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1322 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1323 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1324 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1325 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1326 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1327 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1328 | EXPECT_TRUE(response->proxy_server.is_direct()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1329 | |
| 1330 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1331 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1332 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1333 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1334 | } |
| 1335 | } |
| 1336 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1337 | TEST_F(HttpNetworkTransactionTest, Ignores100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1338 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1339 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 1340 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1341 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1342 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1343 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1344 | request.method = "POST"; |
| 1345 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1346 | request.upload_data_stream = &upload_data_stream; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1347 | |
shivanisha | b9a14395 | 2016-09-19 17:23:41 | [diff] [blame] | 1348 | // Check the upload progress returned before initialization is correct. |
| 1349 | UploadProgress progress = request.upload_data_stream->GetUploadProgress(); |
| 1350 | EXPECT_EQ(0u, progress.size()); |
| 1351 | EXPECT_EQ(0u, progress.position()); |
| 1352 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1353 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1354 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1355 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1356 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1357 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 1358 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 1359 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1360 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1361 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1362 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1363 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1364 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1365 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1366 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1367 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1368 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1369 | |
| 1370 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1371 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1372 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1373 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1374 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1375 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1376 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1377 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1378 | |
| 1379 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1380 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1381 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1382 | EXPECT_EQ("hello world", response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1383 | } |
| 1384 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1385 | // This test is almost the same as Ignores100 above, but the response contains |
| 1386 | // 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] | 1387 | // HTTP/1.1 and the two status headers are read in one read. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1388 | TEST_F(HttpNetworkTransactionTest, Ignores1xx) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1389 | HttpRequestInfo request; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1390 | request.method = "GET"; |
| 1391 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1392 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1393 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1394 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1395 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1396 | MockRead data_reads[] = { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1397 | MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n" |
| 1398 | "HTTP/1.1 200 OK\r\n\r\n"), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1399 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1400 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1401 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1402 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1403 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1404 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1405 | TestCompletionCallback callback; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1406 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1407 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1408 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1409 | |
| 1410 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1411 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1412 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1413 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1414 | ASSERT_TRUE(response); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1415 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1416 | EXPECT_TRUE(response->headers); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1417 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1418 | |
| 1419 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1420 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1421 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1422 | EXPECT_EQ("hello world", response_data); |
| 1423 | } |
| 1424 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1425 | TEST_F(HttpNetworkTransactionTest, Incomplete100ThenEOF) { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1426 | HttpRequestInfo request; |
| 1427 | request.method = "POST"; |
| 1428 | request.url = GURL("http://www.foo.com/"); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1429 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1430 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1431 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1432 | |
| 1433 | MockRead data_reads[] = { |
| 1434 | MockRead(SYNCHRONOUS, "HTTP/1.0 100 Continue\r\n"), |
| 1435 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1436 | }; |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1437 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 1438 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1439 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1440 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1441 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1442 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1443 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1444 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1445 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1446 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1447 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1448 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1449 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1450 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1451 | EXPECT_EQ("", response_data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1452 | } |
| 1453 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1454 | TEST_F(HttpNetworkTransactionTest, EmptyResponse) { |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1455 | HttpRequestInfo request; |
| 1456 | request.method = "POST"; |
| 1457 | request.url = GURL("http://www.foo.com/"); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1458 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1459 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1460 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1461 | |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1462 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1463 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1464 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1465 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1466 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1467 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1468 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1469 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1470 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1471 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1472 | |
| 1473 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1474 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1475 | } |
| 1476 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1477 | void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest( |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1478 | const MockWrite* write_failure, |
| 1479 | const MockRead* read_failure) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1480 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1481 | request.method = "GET"; |
| 1482 | request.url = GURL("http://www.foo.com/"); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1483 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1484 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1485 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1486 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1487 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1488 | // Written data for successfully sending both requests. |
| 1489 | MockWrite data1_writes[] = { |
| 1490 | MockWrite("GET / HTTP/1.1\r\n" |
| 1491 | "Host: www.foo.com\r\n" |
| 1492 | "Connection: keep-alive\r\n\r\n"), |
| 1493 | MockWrite("GET / HTTP/1.1\r\n" |
| 1494 | "Host: www.foo.com\r\n" |
| 1495 | "Connection: keep-alive\r\n\r\n") |
| 1496 | }; |
| 1497 | |
| 1498 | // Read results for the first request. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1499 | MockRead data1_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1500 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1501 | MockRead("hello"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1502 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1503 | }; |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1504 | |
| 1505 | if (write_failure) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1506 | ASSERT_FALSE(read_failure); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1507 | data1_writes[1] = *write_failure; |
| 1508 | } else { |
| 1509 | ASSERT_TRUE(read_failure); |
| 1510 | data1_reads[2] = *read_failure; |
| 1511 | } |
| 1512 | |
| 1513 | StaticSocketDataProvider data1(data1_reads, arraysize(data1_reads), |
| 1514 | data1_writes, arraysize(data1_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1515 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1516 | |
| 1517 | MockRead data2_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1518 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1519 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1520 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1521 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1522 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1523 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1524 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 1525 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1526 | "hello", "world" |
| 1527 | }; |
| 1528 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 1529 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1530 | for (int i = 0; i < 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1531 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1532 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1533 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1534 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1535 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1536 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1537 | |
| 1538 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1539 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1540 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1541 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1542 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1543 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1544 | if (i == 0) { |
| 1545 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1546 | } else { |
| 1547 | // The second request should be using a new socket. |
| 1548 | EXPECT_NE(first_socket_log_id, load_timing_info.socket_log_id); |
| 1549 | } |
| 1550 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1551 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1552 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1553 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1554 | EXPECT_TRUE(response->headers); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1555 | EXPECT_TRUE(response->proxy_server.is_direct()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1556 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1557 | |
| 1558 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1559 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1560 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1561 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1562 | } |
| 1563 | } |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1564 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1565 | void HttpNetworkTransactionTest::PreconnectErrorResendRequestTest( |
| 1566 | const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1567 | const MockRead* read_failure, |
| 1568 | bool use_spdy) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1569 | HttpRequestInfo request; |
| 1570 | request.method = "GET"; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1571 | request.url = GURL("https://www.foo.com/"); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1572 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1573 | TestNetLog net_log; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1574 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1575 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1576 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1577 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 1578 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 1579 | if (use_spdy) { |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 1580 | ssl1.next_proto = kProtoHTTP2; |
| 1581 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1582 | } |
| 1583 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 1584 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1585 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1586 | // SPDY versions of the request and response. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1587 | SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1588 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1589 | SpdySerializedFrame spdy_response( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1590 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1591 | SpdySerializedFrame spdy_data( |
| 1592 | spdy_util_.ConstructSpdyDataFrame(1, "hello", 5, true)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1593 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1594 | // HTTP/1.1 versions of the request and response. |
| 1595 | const char kHttpRequest[] = "GET / HTTP/1.1\r\n" |
| 1596 | "Host: www.foo.com\r\n" |
| 1597 | "Connection: keep-alive\r\n\r\n"; |
| 1598 | const char kHttpResponse[] = "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"; |
| 1599 | const char kHttpData[] = "hello"; |
| 1600 | |
| 1601 | std::vector<MockRead> data1_reads; |
| 1602 | std::vector<MockWrite> data1_writes; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1603 | if (write_failure) { |
| 1604 | ASSERT_FALSE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1605 | data1_writes.push_back(*write_failure); |
| 1606 | data1_reads.push_back(MockRead(ASYNC, OK)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1607 | } else { |
| 1608 | ASSERT_TRUE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1609 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1610 | data1_writes.push_back(CreateMockWrite(spdy_request)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1611 | } else { |
| 1612 | data1_writes.push_back(MockWrite(kHttpRequest)); |
| 1613 | } |
| 1614 | data1_reads.push_back(*read_failure); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1615 | } |
| 1616 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1617 | StaticSocketDataProvider data1(&data1_reads[0], data1_reads.size(), |
| 1618 | &data1_writes[0], data1_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1619 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1620 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1621 | std::vector<MockRead> data2_reads; |
| 1622 | std::vector<MockWrite> data2_writes; |
| 1623 | |
| 1624 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1625 | data2_writes.push_back(CreateMockWrite(spdy_request, 0, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1626 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1627 | data2_reads.push_back(CreateMockRead(spdy_response, 1, ASYNC)); |
| 1628 | data2_reads.push_back(CreateMockRead(spdy_data, 2, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1629 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1630 | } else { |
| 1631 | data2_writes.push_back( |
| 1632 | MockWrite(ASYNC, kHttpRequest, strlen(kHttpRequest), 0)); |
| 1633 | |
| 1634 | data2_reads.push_back( |
| 1635 | MockRead(ASYNC, kHttpResponse, strlen(kHttpResponse), 1)); |
| 1636 | data2_reads.push_back(MockRead(ASYNC, kHttpData, strlen(kHttpData), 2)); |
| 1637 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1638 | } |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 1639 | SequencedSocketData data2(&data2_reads[0], data2_reads.size(), |
| 1640 | &data2_writes[0], data2_writes.size()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1641 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1642 | |
| 1643 | // Preconnect a socket. |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 1644 | session->http_stream_factory()->PreconnectStreams(1, request); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1645 | // Wait for the preconnect to complete. |
| 1646 | // TODO(davidben): Some way to wait for an idle socket count might be handy. |
| 1647 | base::RunLoop().RunUntilIdle(); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1648 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1649 | |
| 1650 | // Make the request. |
| 1651 | TestCompletionCallback callback; |
| 1652 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1653 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1654 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1655 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1656 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1657 | |
| 1658 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1659 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1660 | |
| 1661 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1662 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1663 | TestLoadTimingNotReused( |
| 1664 | load_timing_info, |
| 1665 | CONNECT_TIMING_HAS_DNS_TIMES|CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1666 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1667 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1668 | ASSERT_TRUE(response); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1669 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1670 | EXPECT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1671 | if (response->was_fetched_via_spdy) { |
| 1672 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 1673 | } else { |
| 1674 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1675 | } |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1676 | |
| 1677 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1678 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1679 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1680 | EXPECT_EQ(kHttpData, response_data); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1681 | } |
| 1682 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1683 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionNotConnectedOnWrite) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1684 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1685 | KeepAliveConnectionResendRequestTest(&write_failure, NULL); |
| 1686 | } |
| 1687 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1688 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionReset) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1689 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1690 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1691 | } |
| 1692 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1693 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1694 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1695 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1696 | } |
| 1697 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1698 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1699 | // if the socket was a reused keep alive socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1700 | TEST_F(HttpNetworkTransactionTest, KeepAlive408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1701 | MockRead read_failure(SYNCHRONOUS, |
| 1702 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1703 | "Connection: Keep-Alive\r\n" |
| 1704 | "Content-Length: 6\r\n\r\n" |
| 1705 | "Pickle"); |
| 1706 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1707 | } |
| 1708 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1709 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorNotConnectedOnWrite) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1710 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1711 | PreconnectErrorResendRequestTest(&write_failure, NULL, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1712 | } |
| 1713 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1714 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorReset) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1715 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1716 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1717 | } |
| 1718 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1719 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorEOF) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1720 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1721 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1722 | } |
| 1723 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1724 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1725 | MockRead read_failure(ASYNC, OK); // EOF |
| 1726 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1727 | } |
| 1728 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1729 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1730 | // if the socket was a preconnected (UNUSED_IDLE) socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1731 | TEST_F(HttpNetworkTransactionTest, RetryOnIdle408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1732 | MockRead read_failure(SYNCHRONOUS, |
| 1733 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1734 | "Connection: Keep-Alive\r\n" |
| 1735 | "Content-Length: 6\r\n\r\n" |
| 1736 | "Pickle"); |
| 1737 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1738 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1739 | } |
| 1740 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1741 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorNotConnectedOnWrite) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1742 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
| 1743 | PreconnectErrorResendRequestTest(&write_failure, NULL, true); |
| 1744 | } |
| 1745 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1746 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorReset) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1747 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
| 1748 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1749 | } |
| 1750 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1751 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1752 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
| 1753 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1754 | } |
| 1755 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1756 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1757 | MockRead read_failure(ASYNC, OK); // EOF |
| 1758 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1759 | } |
| 1760 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1761 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1762 | HttpRequestInfo request; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1763 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1764 | request.url = GURL("http://www.example.org/"); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1765 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1766 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1767 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1768 | |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1769 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1770 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1771 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1772 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1773 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1774 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1775 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1776 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1777 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1778 | TestCompletionCallback callback; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1779 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1780 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1781 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1782 | |
| 1783 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1784 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 1785 | |
| 1786 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1787 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 1788 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1789 | } |
| 1790 | |
| 1791 | // What do various browsers do when the server closes a non-keepalive |
| 1792 | // connection without sending any response header or body? |
| 1793 | // |
| 1794 | // IE7: error page |
| 1795 | // Safari 3.1.2 (Windows): error page |
| 1796 | // Firefox 3.0.1: blank page |
| 1797 | // Opera 9.52: after five attempts, blank page |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1798 | // Us with WinHTTP: error page (ERR_INVALID_RESPONSE) |
| 1799 | // Us: error page (EMPTY_RESPONSE) |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1800 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionEOF) { |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1801 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1802 | MockRead(SYNCHRONOUS, OK), // EOF |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1803 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1804 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1805 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1806 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1807 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1808 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1809 | EXPECT_THAT(out.rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1810 | } |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1811 | |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1812 | // Next 2 cases (KeepAliveEarlyClose and KeepAliveEarlyClose2) are regression |
| 1813 | // tests. There was a bug causing HttpNetworkTransaction to hang in the |
| 1814 | // destructor in such situations. |
| 1815 | // See http://crbug.com/154712 and http://crbug.com/156609. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1816 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1817 | HttpRequestInfo request; |
| 1818 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1819 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1820 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1821 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 1822 | auto trans = |
| 1823 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1824 | |
| 1825 | MockRead data_reads[] = { |
| 1826 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1827 | MockRead("Connection: keep-alive\r\n"), |
| 1828 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1829 | MockRead("hello"), |
| 1830 | MockRead(SYNCHRONOUS, 0), |
| 1831 | }; |
| 1832 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1833 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1834 | |
| 1835 | TestCompletionCallback callback; |
| 1836 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1837 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1838 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1839 | |
| 1840 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1841 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1842 | |
| 1843 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1844 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1845 | if (rv == ERR_IO_PENDING) |
| 1846 | rv = callback.WaitForResult(); |
| 1847 | EXPECT_EQ(5, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1848 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1849 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1850 | |
| 1851 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 1852 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1853 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1854 | } |
| 1855 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1856 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose2) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1857 | HttpRequestInfo request; |
| 1858 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1859 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1860 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1861 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 1862 | auto trans = |
| 1863 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1864 | |
| 1865 | MockRead data_reads[] = { |
| 1866 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1867 | MockRead("Connection: keep-alive\r\n"), |
| 1868 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1869 | MockRead(SYNCHRONOUS, 0), |
| 1870 | }; |
| 1871 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1872 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1873 | |
| 1874 | TestCompletionCallback callback; |
| 1875 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1876 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1877 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1878 | |
| 1879 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1880 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1881 | |
| 1882 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1883 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1884 | if (rv == ERR_IO_PENDING) |
| 1885 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1886 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1887 | |
| 1888 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 1889 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1890 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1891 | } |
| 1892 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1893 | // Test that we correctly reuse a keep-alive connection after not explicitly |
| 1894 | // reading the body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1895 | TEST_F(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) { |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1896 | HttpRequestInfo request; |
| 1897 | request.method = "GET"; |
| 1898 | request.url = GURL("http://www.foo.com/"); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1899 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1900 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1901 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1902 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1903 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1904 | const char* request_data = |
| 1905 | "GET / HTTP/1.1\r\n" |
| 1906 | "Host: www.foo.com\r\n" |
| 1907 | "Connection: keep-alive\r\n\r\n"; |
| 1908 | MockWrite data_writes[] = { |
| 1909 | MockWrite(ASYNC, 0, request_data), MockWrite(ASYNC, 2, request_data), |
| 1910 | MockWrite(ASYNC, 4, request_data), MockWrite(ASYNC, 6, request_data), |
| 1911 | MockWrite(ASYNC, 8, request_data), MockWrite(ASYNC, 10, request_data), |
| 1912 | MockWrite(ASYNC, 12, request_data), MockWrite(ASYNC, 14, request_data), |
| 1913 | MockWrite(ASYNC, 17, request_data), MockWrite(ASYNC, 20, request_data), |
| 1914 | }; |
| 1915 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1916 | // Note that because all these reads happen in the same |
| 1917 | // StaticSocketDataProvider, it shows that the same socket is being reused for |
| 1918 | // all transactions. |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1919 | MockRead data_reads[] = { |
| 1920 | MockRead(ASYNC, 1, "HTTP/1.1 204 No Content\r\n\r\n"), |
| 1921 | MockRead(ASYNC, 3, "HTTP/1.1 205 Reset Content\r\n\r\n"), |
| 1922 | MockRead(ASYNC, 5, "HTTP/1.1 304 Not Modified\r\n\r\n"), |
| 1923 | MockRead(ASYNC, 7, |
| 1924 | "HTTP/1.1 302 Found\r\n" |
| 1925 | "Content-Length: 0\r\n\r\n"), |
| 1926 | MockRead(ASYNC, 9, |
| 1927 | "HTTP/1.1 302 Found\r\n" |
| 1928 | "Content-Length: 5\r\n\r\n" |
| 1929 | "hello"), |
| 1930 | MockRead(ASYNC, 11, |
| 1931 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 1932 | "Content-Length: 0\r\n\r\n"), |
| 1933 | MockRead(ASYNC, 13, |
| 1934 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 1935 | "Content-Length: 5\r\n\r\n" |
| 1936 | "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1937 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1938 | // In the next two rounds, IsConnectedAndIdle returns false, due to |
| 1939 | // the set_busy_before_sync_reads(true) call, while the |
| 1940 | // HttpNetworkTransaction is being shut down, but the socket is still |
| 1941 | // reuseable. See http://crbug.com/544255. |
| 1942 | MockRead(ASYNC, 15, |
| 1943 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 1944 | "Content-Length: 5\r\n\r\n"), |
| 1945 | MockRead(SYNCHRONOUS, 16, "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1946 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1947 | MockRead(ASYNC, 18, |
| 1948 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 1949 | "Content-Length: 5\r\n\r\n" |
| 1950 | "he"), |
| 1951 | MockRead(SYNCHRONOUS, 19, "llo"), |
| 1952 | |
| 1953 | // The body of the final request is actually read. |
| 1954 | MockRead(ASYNC, 21, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1955 | MockRead(ASYNC, 22, "hello"), |
| 1956 | }; |
| 1957 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 1958 | arraysize(data_writes)); |
| 1959 | data.set_busy_before_sync_reads(true); |
| 1960 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1961 | |
| 1962 | const int kNumUnreadBodies = arraysize(data_writes) - 1; |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1963 | std::string response_lines[kNumUnreadBodies]; |
| 1964 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 1965 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1966 | for (size_t i = 0; i < kNumUnreadBodies; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1967 | TestCompletionCallback callback; |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1968 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 1969 | auto trans = base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
| 1970 | session.get()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1971 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1972 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1973 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1974 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1975 | LoadTimingInfo load_timing_info; |
| 1976 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 1977 | if (i == 0) { |
| 1978 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1979 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1980 | } else { |
| 1981 | TestLoadTimingReused(load_timing_info); |
| 1982 | EXPECT_EQ(first_socket_log_id, load_timing_info.socket_log_id); |
| 1983 | } |
| 1984 | |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1985 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1986 | ASSERT_TRUE(response); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1987 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1988 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1989 | response_lines[i] = response->headers->GetStatusLine(); |
| 1990 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1991 | // Delete the transaction without reading the response bodies. Then spin |
| 1992 | // the message loop, so the response bodies are drained. |
| 1993 | trans.reset(); |
| 1994 | base::RunLoop().RunUntilIdle(); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1995 | } |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1996 | |
| 1997 | const char* const kStatusLines[] = { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1998 | "HTTP/1.1 204 No Content", |
| 1999 | "HTTP/1.1 205 Reset Content", |
| 2000 | "HTTP/1.1 304 Not Modified", |
| 2001 | "HTTP/1.1 302 Found", |
| 2002 | "HTTP/1.1 302 Found", |
| 2003 | "HTTP/1.1 301 Moved Permanently", |
| 2004 | "HTTP/1.1 301 Moved Permanently", |
| 2005 | "HTTP/1.1 200 Hunky-Dory", |
| 2006 | "HTTP/1.1 200 Hunky-Dory", |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2007 | }; |
| 2008 | |
mostynb | 91e0da98 | 2015-01-20 19:17:27 | [diff] [blame] | 2009 | static_assert(kNumUnreadBodies == arraysize(kStatusLines), |
| 2010 | "forgot to update kStatusLines"); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2011 | |
| 2012 | for (int i = 0; i < kNumUnreadBodies; ++i) |
| 2013 | EXPECT_EQ(kStatusLines[i], response_lines[i]); |
| 2014 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2015 | TestCompletionCallback callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2016 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2017 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2018 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2019 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2020 | ASSERT_TRUE(response); |
| 2021 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2022 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 2023 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2024 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2025 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2026 | EXPECT_EQ("hello", response_data); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2027 | } |
| 2028 | |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2029 | // Sockets that receive extra data after a response is complete should not be |
| 2030 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2031 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData1) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2032 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2033 | MockWrite data_writes1[] = { |
| 2034 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 2035 | "Host: www.borked.com\r\n" |
| 2036 | "Connection: keep-alive\r\n\r\n"), |
| 2037 | }; |
| 2038 | |
| 2039 | MockRead data_reads1[] = { |
| 2040 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2041 | "Connection: keep-alive\r\n" |
| 2042 | "Content-Length: 22\r\n\r\n" |
| 2043 | "This server is borked."), |
| 2044 | }; |
| 2045 | |
| 2046 | MockWrite data_writes2[] = { |
| 2047 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2048 | "Host: www.borked.com\r\n" |
| 2049 | "Connection: keep-alive\r\n\r\n"), |
| 2050 | }; |
| 2051 | |
| 2052 | MockRead data_reads2[] = { |
| 2053 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2054 | "Content-Length: 3\r\n\r\n" |
| 2055 | "foo"), |
| 2056 | }; |
| 2057 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2058 | data_writes1, arraysize(data_writes1)); |
| 2059 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2060 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2061 | data_writes2, arraysize(data_writes2)); |
| 2062 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2063 | |
| 2064 | TestCompletionCallback callback; |
| 2065 | HttpRequestInfo request1; |
| 2066 | request1.method = "HEAD"; |
| 2067 | request1.url = GURL("http://www.borked.com/"); |
| 2068 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2069 | auto trans1 = |
| 2070 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2071 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2072 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2073 | |
| 2074 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2075 | ASSERT_TRUE(response1); |
| 2076 | ASSERT_TRUE(response1->headers); |
| 2077 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2078 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2079 | |
| 2080 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2081 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2082 | EXPECT_EQ("", response_data1); |
| 2083 | // Deleting the transaction attempts to release the socket back into the |
| 2084 | // socket pool. |
| 2085 | trans1.reset(); |
| 2086 | |
| 2087 | HttpRequestInfo request2; |
| 2088 | request2.method = "GET"; |
| 2089 | request2.url = GURL("http://www.borked.com/foo"); |
| 2090 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2091 | auto trans2 = |
| 2092 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2093 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2094 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2095 | |
| 2096 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2097 | ASSERT_TRUE(response2); |
| 2098 | ASSERT_TRUE(response2->headers); |
| 2099 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2100 | |
| 2101 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2102 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2103 | EXPECT_EQ("foo", response_data2); |
| 2104 | } |
| 2105 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2106 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData2) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2107 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2108 | MockWrite data_writes1[] = { |
| 2109 | MockWrite("GET / HTTP/1.1\r\n" |
| 2110 | "Host: www.borked.com\r\n" |
| 2111 | "Connection: keep-alive\r\n\r\n"), |
| 2112 | }; |
| 2113 | |
| 2114 | MockRead data_reads1[] = { |
| 2115 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2116 | "Connection: keep-alive\r\n" |
| 2117 | "Content-Length: 22\r\n\r\n" |
| 2118 | "This server is borked." |
| 2119 | "Bonus data!"), |
| 2120 | }; |
| 2121 | |
| 2122 | MockWrite data_writes2[] = { |
| 2123 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2124 | "Host: www.borked.com\r\n" |
| 2125 | "Connection: keep-alive\r\n\r\n"), |
| 2126 | }; |
| 2127 | |
| 2128 | MockRead data_reads2[] = { |
| 2129 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2130 | "Content-Length: 3\r\n\r\n" |
| 2131 | "foo"), |
| 2132 | }; |
| 2133 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2134 | data_writes1, arraysize(data_writes1)); |
| 2135 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2136 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2137 | data_writes2, arraysize(data_writes2)); |
| 2138 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2139 | |
| 2140 | TestCompletionCallback callback; |
| 2141 | HttpRequestInfo request1; |
| 2142 | request1.method = "GET"; |
| 2143 | request1.url = GURL("http://www.borked.com/"); |
| 2144 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2145 | auto trans1 = |
| 2146 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2147 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2148 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2149 | |
| 2150 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2151 | ASSERT_TRUE(response1); |
| 2152 | ASSERT_TRUE(response1->headers); |
| 2153 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2154 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2155 | |
| 2156 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2157 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2158 | EXPECT_EQ("This server is borked.", response_data1); |
| 2159 | // Deleting the transaction attempts to release the socket back into the |
| 2160 | // socket pool. |
| 2161 | trans1.reset(); |
| 2162 | |
| 2163 | HttpRequestInfo request2; |
| 2164 | request2.method = "GET"; |
| 2165 | request2.url = GURL("http://www.borked.com/foo"); |
| 2166 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2167 | auto trans2 = |
| 2168 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2169 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2170 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2171 | |
| 2172 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2173 | ASSERT_TRUE(response2); |
| 2174 | ASSERT_TRUE(response2->headers); |
| 2175 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2176 | |
| 2177 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2178 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2179 | EXPECT_EQ("foo", response_data2); |
| 2180 | } |
| 2181 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2182 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData3) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2183 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2184 | MockWrite data_writes1[] = { |
| 2185 | MockWrite("GET / HTTP/1.1\r\n" |
| 2186 | "Host: www.borked.com\r\n" |
| 2187 | "Connection: keep-alive\r\n\r\n"), |
| 2188 | }; |
| 2189 | |
| 2190 | MockRead data_reads1[] = { |
| 2191 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2192 | "Connection: keep-alive\r\n" |
| 2193 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2194 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2195 | MockRead("0\r\n\r\nBonus data!"), |
| 2196 | }; |
| 2197 | |
| 2198 | MockWrite data_writes2[] = { |
| 2199 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2200 | "Host: www.borked.com\r\n" |
| 2201 | "Connection: keep-alive\r\n\r\n"), |
| 2202 | }; |
| 2203 | |
| 2204 | MockRead data_reads2[] = { |
| 2205 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2206 | "Content-Length: 3\r\n\r\n" |
| 2207 | "foo"), |
| 2208 | }; |
| 2209 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2210 | data_writes1, arraysize(data_writes1)); |
| 2211 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2212 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2213 | data_writes2, arraysize(data_writes2)); |
| 2214 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2215 | |
| 2216 | TestCompletionCallback callback; |
| 2217 | HttpRequestInfo request1; |
| 2218 | request1.method = "GET"; |
| 2219 | request1.url = GURL("http://www.borked.com/"); |
| 2220 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2221 | auto trans1 = |
| 2222 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2223 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2224 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2225 | |
| 2226 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2227 | ASSERT_TRUE(response1); |
| 2228 | ASSERT_TRUE(response1->headers); |
| 2229 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2230 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2231 | |
| 2232 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2233 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2234 | EXPECT_EQ("This server is borked.", response_data1); |
| 2235 | // Deleting the transaction attempts to release the socket back into the |
| 2236 | // socket pool. |
| 2237 | trans1.reset(); |
| 2238 | |
| 2239 | HttpRequestInfo request2; |
| 2240 | request2.method = "GET"; |
| 2241 | request2.url = GURL("http://www.borked.com/foo"); |
| 2242 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2243 | auto trans2 = |
| 2244 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2245 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2246 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2247 | |
| 2248 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2249 | ASSERT_TRUE(response2); |
| 2250 | ASSERT_TRUE(response2->headers); |
| 2251 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2252 | |
| 2253 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2254 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2255 | EXPECT_EQ("foo", response_data2); |
| 2256 | } |
| 2257 | |
| 2258 | // This is a little different from the others - it tests the case that the |
| 2259 | // HttpStreamParser doesn't know if there's extra data on a socket or not when |
| 2260 | // the HttpNetworkTransaction is torn down, because the response body hasn't |
| 2261 | // been read from yet, but the request goes through the HttpResponseBodyDrainer. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2262 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData4) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2263 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2264 | MockWrite data_writes1[] = { |
| 2265 | MockWrite("GET / HTTP/1.1\r\n" |
| 2266 | "Host: www.borked.com\r\n" |
| 2267 | "Connection: keep-alive\r\n\r\n"), |
| 2268 | }; |
| 2269 | |
| 2270 | MockRead data_reads1[] = { |
| 2271 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2272 | "Connection: keep-alive\r\n" |
| 2273 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2274 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2275 | MockRead("0\r\n\r\nBonus data!"), |
| 2276 | }; |
| 2277 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2278 | data_writes1, arraysize(data_writes1)); |
| 2279 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2280 | |
| 2281 | TestCompletionCallback callback; |
| 2282 | HttpRequestInfo request1; |
| 2283 | request1.method = "GET"; |
| 2284 | request1.url = GURL("http://www.borked.com/"); |
| 2285 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2286 | auto trans = |
| 2287 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 2288 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2289 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2290 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2291 | const HttpResponseInfo* response1 = trans->GetResponseInfo(); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2292 | ASSERT_TRUE(response1); |
| 2293 | ASSERT_TRUE(response1->headers); |
| 2294 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2295 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2296 | |
| 2297 | // Deleting the transaction creates an HttpResponseBodyDrainer to read the |
| 2298 | // response body. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2299 | trans.reset(); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2300 | |
| 2301 | // Let the HttpResponseBodyDrainer drain the socket. It should determine the |
| 2302 | // socket can't be reused, rather than returning it to the socket pool. |
| 2303 | base::RunLoop().RunUntilIdle(); |
| 2304 | |
| 2305 | // There should be no idle sockets in the pool. |
| 2306 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2307 | } |
| 2308 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2309 | // Test the request-challenge-retry sequence for basic auth. |
| 2310 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2311 | TEST_F(HttpNetworkTransactionTest, BasicAuth) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2312 | HttpRequestInfo request; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2313 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2314 | request.url = GURL("http://www.example.org/"); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2315 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2316 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2317 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2318 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2319 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2320 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2321 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2322 | MockWrite( |
| 2323 | "GET / HTTP/1.1\r\n" |
| 2324 | "Host: www.example.org\r\n" |
| 2325 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2326 | }; |
| 2327 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2328 | MockRead data_reads1[] = { |
| 2329 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2330 | // Give a couple authenticate options (only the middle one is actually |
| 2331 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 2332 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2333 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2334 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2335 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2336 | // Large content-length -- won't matter, as connection will be reset. |
| 2337 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2338 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2339 | }; |
| 2340 | |
| 2341 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2342 | // be issuing -- the final header line contains the credentials. |
| 2343 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2344 | MockWrite( |
| 2345 | "GET / HTTP/1.1\r\n" |
| 2346 | "Host: www.example.org\r\n" |
| 2347 | "Connection: keep-alive\r\n" |
| 2348 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2349 | }; |
| 2350 | |
| 2351 | // Lastly, the server responds with the actual content. |
| 2352 | MockRead data_reads2[] = { |
| 2353 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2354 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2355 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2356 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2357 | }; |
| 2358 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2359 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2360 | data_writes1, arraysize(data_writes1)); |
| 2361 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2362 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2363 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2364 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2365 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2366 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2367 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2368 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2369 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2370 | |
| 2371 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2372 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2373 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2374 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2375 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2376 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2377 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2378 | int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2379 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2380 | int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2381 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2382 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2383 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2384 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2385 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2386 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2387 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2388 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2389 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2390 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2391 | |
| 2392 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2393 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2394 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2395 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2396 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2397 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2398 | // The load timing after restart should have a new socket ID, and times after |
| 2399 | // those of the first load timing. |
| 2400 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2401 | load_timing_info2.connect_timing.connect_start); |
| 2402 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2403 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2404 | int64_t writes_size2 = CountWriteBytes(data_writes2, arraysize(data_writes2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2405 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2406 | int64_t reads_size2 = CountReadBytes(data_reads2, arraysize(data_reads2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2407 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2408 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2409 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2410 | ASSERT_TRUE(response); |
| 2411 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2412 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2413 | } |
| 2414 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2415 | // Test the request-challenge-retry sequence for basic auth. |
| 2416 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2417 | TEST_F(HttpNetworkTransactionTest, BasicAuthWithAddressChange) { |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2418 | HttpRequestInfo request; |
| 2419 | request.method = "GET"; |
| 2420 | request.url = GURL("http://www.example.org/"); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2421 | |
| 2422 | TestNetLog log; |
| 2423 | MockHostResolver* resolver = new MockHostResolver(); |
| 2424 | session_deps_.net_log = &log; |
| 2425 | session_deps_.host_resolver.reset(resolver); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2426 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2427 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2428 | |
| 2429 | resolver->rules()->ClearRules(); |
| 2430 | resolver->rules()->AddRule("www.example.org", "127.0.0.1"); |
| 2431 | |
| 2432 | MockWrite data_writes1[] = { |
| 2433 | MockWrite("GET / HTTP/1.1\r\n" |
| 2434 | "Host: www.example.org\r\n" |
| 2435 | "Connection: keep-alive\r\n\r\n"), |
| 2436 | }; |
| 2437 | |
| 2438 | MockRead data_reads1[] = { |
| 2439 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2440 | // Give a couple authenticate options (only the middle one is actually |
| 2441 | // supported). |
| 2442 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 2443 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2444 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2445 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2446 | // Large content-length -- won't matter, as connection will be reset. |
| 2447 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 2448 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 2449 | }; |
| 2450 | |
| 2451 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2452 | // be issuing -- the final header line contains the credentials. |
| 2453 | MockWrite data_writes2[] = { |
| 2454 | MockWrite("GET / HTTP/1.1\r\n" |
| 2455 | "Host: www.example.org\r\n" |
| 2456 | "Connection: keep-alive\r\n" |
| 2457 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2458 | }; |
| 2459 | |
| 2460 | // Lastly, the server responds with the actual content. |
| 2461 | MockRead data_reads2[] = { |
| 2462 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2463 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2464 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, OK), |
| 2465 | }; |
| 2466 | |
| 2467 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2468 | data_writes1, arraysize(data_writes1)); |
| 2469 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2470 | data_writes2, arraysize(data_writes2)); |
| 2471 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2472 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2473 | |
| 2474 | TestCompletionCallback callback1; |
| 2475 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2476 | EXPECT_EQ(OK, callback1.GetResult(trans.Start(&request, callback1.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2477 | NetLogWithSource()))); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2478 | |
| 2479 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2480 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2481 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2482 | |
| 2483 | int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2484 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2485 | int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2486 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2487 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2488 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2489 | ASSERT_TRUE(response); |
| 2490 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 2491 | |
| 2492 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2493 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2494 | ASSERT_FALSE(endpoint.address().empty()); |
| 2495 | EXPECT_EQ("127.0.0.1:80", endpoint.ToString()); |
| 2496 | |
| 2497 | resolver->rules()->ClearRules(); |
| 2498 | resolver->rules()->AddRule("www.example.org", "127.0.0.2"); |
| 2499 | |
| 2500 | TestCompletionCallback callback2; |
| 2501 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2502 | EXPECT_EQ(OK, callback2.GetResult(trans.RestartWithAuth( |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2503 | AuthCredentials(kFoo, kBar), callback2.callback()))); |
| 2504 | |
| 2505 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2506 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2507 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2508 | // The load timing after restart should have a new socket ID, and times after |
| 2509 | // those of the first load timing. |
| 2510 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2511 | load_timing_info2.connect_timing.connect_start); |
| 2512 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2513 | |
| 2514 | int64_t writes_size2 = CountWriteBytes(data_writes2, arraysize(data_writes2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2515 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2516 | int64_t reads_size2 = CountReadBytes(data_reads2, arraysize(data_reads2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2517 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2518 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2519 | response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2520 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2521 | EXPECT_FALSE(response->auth_challenge); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2522 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 2523 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2524 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2525 | ASSERT_FALSE(endpoint.address().empty()); |
| 2526 | EXPECT_EQ("127.0.0.2:80", endpoint.ToString()); |
| 2527 | } |
| 2528 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2529 | TEST_F(HttpNetworkTransactionTest, DoNotSendAuth) { |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2530 | HttpRequestInfo request; |
| 2531 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2532 | request.url = GURL("http://www.example.org/"); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2533 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2534 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2535 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2536 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2537 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2538 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2539 | MockWrite( |
| 2540 | "GET / HTTP/1.1\r\n" |
| 2541 | "Host: www.example.org\r\n" |
| 2542 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2543 | }; |
| 2544 | |
| 2545 | MockRead data_reads[] = { |
| 2546 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2547 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2548 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2549 | // Large content-length -- won't matter, as connection will be reset. |
| 2550 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2551 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2552 | }; |
| 2553 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2554 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 2555 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2556 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2557 | TestCompletionCallback callback; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2558 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2559 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2560 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2561 | |
| 2562 | rv = callback.WaitForResult(); |
| 2563 | EXPECT_EQ(0, rv); |
| 2564 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2565 | int64_t writes_size = CountWriteBytes(data_writes, arraysize(data_writes)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2566 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2567 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2568 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2569 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2570 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2571 | ASSERT_TRUE(response); |
| 2572 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2573 | } |
| 2574 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2575 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2576 | // connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2577 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAlive) { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2578 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 2579 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 2580 | // reused. See http://crbug.com/544255. |
| 2581 | for (int i = 0; i < 2; ++i) { |
| 2582 | HttpRequestInfo request; |
| 2583 | request.method = "GET"; |
| 2584 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2585 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2586 | TestNetLog log; |
| 2587 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2588 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2589 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2590 | MockWrite data_writes[] = { |
| 2591 | MockWrite(ASYNC, 0, |
| 2592 | "GET / HTTP/1.1\r\n" |
| 2593 | "Host: www.example.org\r\n" |
| 2594 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2595 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2596 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2597 | // be issuing -- the final header line contains the credentials. |
| 2598 | MockWrite(ASYNC, 6, |
| 2599 | "GET / HTTP/1.1\r\n" |
| 2600 | "Host: www.example.org\r\n" |
| 2601 | "Connection: keep-alive\r\n" |
| 2602 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2603 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2604 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2605 | MockRead data_reads[] = { |
| 2606 | MockRead(ASYNC, 1, "HTTP/1.1 401 Unauthorized\r\n"), |
| 2607 | MockRead(ASYNC, 2, "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2608 | MockRead(ASYNC, 3, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2609 | MockRead(ASYNC, 4, "Content-Length: 14\r\n\r\n"), |
| 2610 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 5, "Unauthorized\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2611 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2612 | // Lastly, the server responds with the actual content. |
| 2613 | MockRead(ASYNC, 7, "HTTP/1.1 200 OK\r\n"), |
| 2614 | MockRead(ASYNC, 8, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2615 | MockRead(ASYNC, 9, "Content-Length: 5\r\n\r\n"), |
| 2616 | MockRead(ASYNC, 10, "Hello"), |
| 2617 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2618 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2619 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 2620 | arraysize(data_writes)); |
| 2621 | data.set_busy_before_sync_reads(true); |
| 2622 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2623 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2624 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2625 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2626 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2627 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2628 | ASSERT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2629 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2630 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2631 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2632 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2633 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2634 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2635 | ASSERT_TRUE(response); |
| 2636 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2637 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2638 | TestCompletionCallback callback2; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2639 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2640 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 2641 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2642 | ASSERT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2643 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2644 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2645 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2646 | TestLoadTimingReused(load_timing_info2); |
| 2647 | // The load timing after restart should have the same socket ID, and times |
| 2648 | // those of the first load timing. |
| 2649 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2650 | load_timing_info2.send_start); |
| 2651 | 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] | 2652 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2653 | response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2654 | ASSERT_TRUE(response); |
| 2655 | EXPECT_FALSE(response->auth_challenge); |
| 2656 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2657 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2658 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2659 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2660 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2661 | int64_t writes_size = CountWriteBytes(data_writes, arraysize(data_writes)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2662 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2663 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2664 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2665 | } |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2666 | } |
| 2667 | |
| 2668 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2669 | // connection and with no response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2670 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2671 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2672 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2673 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2674 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2675 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2676 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2677 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2678 | MockWrite("GET / HTTP/1.1\r\n" |
| 2679 | "Host: www.example.org\r\n" |
| 2680 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2681 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2682 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2683 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2684 | MockWrite("GET / HTTP/1.1\r\n" |
| 2685 | "Host: www.example.org\r\n" |
| 2686 | "Connection: keep-alive\r\n" |
| 2687 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2688 | }; |
| 2689 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2690 | MockRead data_reads1[] = { |
| 2691 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2692 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2693 | MockRead("Content-Length: 0\r\n\r\n"), // No response body. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2694 | |
| 2695 | // Lastly, the server responds with the actual content. |
| 2696 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2697 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2698 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2699 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2700 | }; |
| 2701 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2702 | // An incorrect reconnect would cause this to be read. |
| 2703 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2704 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2705 | }; |
| 2706 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2707 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2708 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2709 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2710 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2711 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2712 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2713 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2714 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2715 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2716 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2717 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2718 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2719 | |
| 2720 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2721 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2722 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2723 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2724 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2725 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2726 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2727 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2728 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2729 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2730 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2731 | |
| 2732 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2733 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2734 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2735 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2736 | ASSERT_TRUE(response); |
| 2737 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2738 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2739 | } |
| 2740 | |
| 2741 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2742 | // connection and with a large response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2743 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2744 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2745 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2746 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2747 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2748 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2749 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2750 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2751 | MockWrite("GET / HTTP/1.1\r\n" |
| 2752 | "Host: www.example.org\r\n" |
| 2753 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2754 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2755 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2756 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2757 | MockWrite("GET / HTTP/1.1\r\n" |
| 2758 | "Host: www.example.org\r\n" |
| 2759 | "Connection: keep-alive\r\n" |
| 2760 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2761 | }; |
| 2762 | |
| 2763 | // Respond with 5 kb of response body. |
| 2764 | std::string large_body_string("Unauthorized"); |
| 2765 | large_body_string.append(5 * 1024, ' '); |
| 2766 | large_body_string.append("\r\n"); |
| 2767 | |
| 2768 | MockRead data_reads1[] = { |
| 2769 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2770 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2771 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2772 | // 5134 = 12 + 5 * 1024 + 2 |
| 2773 | MockRead("Content-Length: 5134\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2774 | MockRead(ASYNC, large_body_string.data(), large_body_string.size()), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2775 | |
| 2776 | // Lastly, the server responds with the actual content. |
| 2777 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2778 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2779 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2780 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2781 | }; |
| 2782 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2783 | // An incorrect reconnect would cause this to be read. |
| 2784 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2785 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2786 | }; |
| 2787 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2788 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2789 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2790 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2791 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2792 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2793 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2794 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2795 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2796 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2797 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2798 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2799 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2800 | |
| 2801 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2802 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2803 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2804 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2805 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2806 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2807 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2808 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2809 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2810 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2811 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2812 | |
| 2813 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2814 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2815 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2816 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2817 | ASSERT_TRUE(response); |
| 2818 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2819 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2820 | } |
| 2821 | |
| 2822 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2823 | // connection, but the server gets impatient and closes the connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2824 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) { |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2825 | HttpRequestInfo request; |
| 2826 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2827 | request.url = GURL("http://www.example.org/"); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2828 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2829 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2830 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2831 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2832 | MockWrite( |
| 2833 | "GET / HTTP/1.1\r\n" |
| 2834 | "Host: www.example.org\r\n" |
| 2835 | "Connection: keep-alive\r\n\r\n"), |
| 2836 | // This simulates the seemingly successful write to a closed connection |
| 2837 | // if the bug is not fixed. |
| 2838 | MockWrite( |
| 2839 | "GET / HTTP/1.1\r\n" |
| 2840 | "Host: www.example.org\r\n" |
| 2841 | "Connection: keep-alive\r\n" |
| 2842 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2843 | }; |
| 2844 | |
| 2845 | MockRead data_reads1[] = { |
| 2846 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2847 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2848 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2849 | MockRead("Content-Length: 14\r\n\r\n"), |
| 2850 | // Tell MockTCPClientSocket to simulate the server closing the connection. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2851 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2852 | MockRead("Unauthorized\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2853 | MockRead(SYNCHRONOUS, OK), // The server closes the connection. |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2854 | }; |
| 2855 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2856 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2857 | // be issuing -- the final header line contains the credentials. |
| 2858 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2859 | MockWrite( |
| 2860 | "GET / HTTP/1.1\r\n" |
| 2861 | "Host: www.example.org\r\n" |
| 2862 | "Connection: keep-alive\r\n" |
| 2863 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2864 | }; |
| 2865 | |
| 2866 | // Lastly, the server responds with the actual content. |
| 2867 | MockRead data_reads2[] = { |
| 2868 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2869 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2870 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2871 | MockRead("hello"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2872 | }; |
| 2873 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2874 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2875 | data_writes1, arraysize(data_writes1)); |
| 2876 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2877 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2878 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2879 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2880 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2881 | TestCompletionCallback callback1; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2882 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2883 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2884 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2885 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2886 | |
| 2887 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2888 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2889 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2890 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2891 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2892 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2893 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2894 | TestCompletionCallback callback2; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2895 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2896 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2897 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2898 | |
| 2899 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2900 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2901 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2902 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2903 | ASSERT_TRUE(response); |
| 2904 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2905 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2906 | } |
| 2907 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2908 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 2909 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2910 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp10) { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2911 | HttpRequestInfo request; |
| 2912 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2913 | request.url = GURL("https://www.example.org/"); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2914 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2915 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2916 | |
| 2917 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 2918 | session_deps_.proxy_service = |
| 2919 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2920 | BoundTestNetLog log; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2921 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2922 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2923 | |
| 2924 | // Since we have proxy, should try to establish tunnel. |
| 2925 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2926 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 2927 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2928 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2929 | }; |
| 2930 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2931 | // The proxy responds to the connect with a 407, using a non-persistent |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2932 | // connection. |
| 2933 | MockRead data_reads1[] = { |
| 2934 | // No credentials. |
| 2935 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 2936 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2937 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2938 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2939 | // Since the first connection couldn't be reused, need to establish another |
| 2940 | // once given credentials. |
| 2941 | MockWrite data_writes2[] = { |
| 2942 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2943 | // be issuing -- the final header line contains the credentials. |
| 2944 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 2945 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2946 | "Proxy-Connection: keep-alive\r\n" |
| 2947 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2948 | |
| 2949 | MockWrite("GET / HTTP/1.1\r\n" |
| 2950 | "Host: www.example.org\r\n" |
| 2951 | "Connection: keep-alive\r\n\r\n"), |
| 2952 | }; |
| 2953 | |
| 2954 | MockRead data_reads2[] = { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2955 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 2956 | |
| 2957 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2958 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2959 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2960 | MockRead(SYNCHRONOUS, "hello"), |
| 2961 | }; |
| 2962 | |
| 2963 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2964 | data_writes1, arraysize(data_writes1)); |
| 2965 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 2966 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2967 | data_writes2, arraysize(data_writes2)); |
| 2968 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2969 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 2970 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 2971 | |
| 2972 | TestCompletionCallback callback1; |
| 2973 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2974 | auto trans = |
| 2975 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2976 | |
| 2977 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2978 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2979 | |
| 2980 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2981 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 2982 | TestNetLogEntry::List entries; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2983 | log.GetEntries(&entries); |
| 2984 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 2985 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 2986 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2987 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 2988 | entries, pos, |
| 2989 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 2990 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2991 | |
| 2992 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2993 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2994 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2995 | ASSERT_TRUE(response->headers); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2996 | EXPECT_EQ(407, response->headers->response_code()); |
| 2997 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 2998 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 2999 | |
| 3000 | LoadTimingInfo load_timing_info; |
| 3001 | // CONNECT requests and responses are handled at the connect job level, so |
| 3002 | // the transaction does not yet have a connection. |
| 3003 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3004 | |
| 3005 | TestCompletionCallback callback2; |
| 3006 | |
| 3007 | rv = |
| 3008 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3009 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3010 | |
| 3011 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3012 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3013 | |
| 3014 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3015 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3016 | |
| 3017 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3018 | EXPECT_EQ(200, response->headers->response_code()); |
| 3019 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 3020 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3021 | |
| 3022 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3023 | EXPECT_FALSE(response->auth_challenge); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3024 | |
| 3025 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3026 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3027 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3028 | |
| 3029 | trans.reset(); |
| 3030 | session->CloseAllConnections(); |
| 3031 | } |
| 3032 | |
| 3033 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 3034 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3035 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp11) { |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3036 | HttpRequestInfo request; |
| 3037 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3038 | request.url = GURL("https://www.example.org/"); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3039 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3040 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3041 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3042 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3043 | session_deps_.proxy_service = |
| 3044 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3045 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3046 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3047 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3048 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3049 | // Since we have proxy, should try to establish tunnel. |
| 3050 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3051 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3052 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3053 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3054 | }; |
| 3055 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3056 | // The proxy responds to the connect with a 407, using a non-persistent |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3057 | // connection. |
| 3058 | MockRead data_reads1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3059 | // No credentials. |
| 3060 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3061 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3062 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3063 | }; |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3064 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3065 | MockWrite data_writes2[] = { |
| 3066 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3067 | // be issuing -- the final header line contains the credentials. |
| 3068 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3069 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3070 | "Proxy-Connection: keep-alive\r\n" |
| 3071 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3072 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3073 | MockWrite("GET / HTTP/1.1\r\n" |
| 3074 | "Host: www.example.org\r\n" |
| 3075 | "Connection: keep-alive\r\n\r\n"), |
| 3076 | }; |
| 3077 | |
| 3078 | MockRead data_reads2[] = { |
| 3079 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3080 | |
| 3081 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3082 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3083 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3084 | MockRead(SYNCHRONOUS, "hello"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3085 | }; |
| 3086 | |
| 3087 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3088 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3089 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3090 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3091 | data_writes2, arraysize(data_writes2)); |
| 3092 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3093 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3094 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3095 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3096 | TestCompletionCallback callback1; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3097 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3098 | auto trans = |
| 3099 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3100 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3101 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3102 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3103 | |
| 3104 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3105 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3106 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3107 | log.GetEntries(&entries); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3108 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3109 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3110 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3111 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3112 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3113 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3114 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3115 | |
| 3116 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3117 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3118 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3119 | ASSERT_TRUE(response->headers); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3120 | EXPECT_EQ(407, response->headers->response_code()); |
| 3121 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3122 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3123 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3124 | LoadTimingInfo load_timing_info; |
| 3125 | // CONNECT requests and responses are handled at the connect job level, so |
| 3126 | // the transaction does not yet have a connection. |
| 3127 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3128 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3129 | TestCompletionCallback callback2; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3130 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3131 | rv = trans->RestartWithAuth( |
| 3132 | AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3133 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3134 | |
| 3135 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3136 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3137 | |
| 3138 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3139 | ASSERT_TRUE(response); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3140 | |
| 3141 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3142 | EXPECT_EQ(200, response->headers->response_code()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3143 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3144 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3145 | |
| 3146 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3147 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3148 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3149 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3150 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3151 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3152 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3153 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3154 | session->CloseAllConnections(); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3155 | } |
| 3156 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3157 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3158 | // proxy connection with HTTP/1.0 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3159 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp10) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3160 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3161 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3162 | // reused. See http://crbug.com/544255. |
| 3163 | for (int i = 0; i < 2; ++i) { |
| 3164 | HttpRequestInfo request; |
| 3165 | request.method = "GET"; |
| 3166 | request.url = GURL("https://www.example.org/"); |
| 3167 | // Ensure that proxy authentication is attempted even |
| 3168 | // when the no authentication data flag is set. |
| 3169 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3170 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3171 | // Configure against proxy server "myproxy:70". |
| 3172 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
| 3173 | BoundTestNetLog log; |
| 3174 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3175 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3176 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3177 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3178 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3179 | // Since we have proxy, should try to establish tunnel. |
| 3180 | MockWrite data_writes1[] = { |
| 3181 | MockWrite(ASYNC, 0, |
| 3182 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3183 | "Host: www.example.org:443\r\n" |
| 3184 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3185 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3186 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3187 | // be issuing -- the final header line contains the credentials. |
| 3188 | MockWrite(ASYNC, 3, |
| 3189 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3190 | "Host: www.example.org:443\r\n" |
| 3191 | "Proxy-Connection: keep-alive\r\n" |
| 3192 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3193 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3194 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3195 | // The proxy responds to the connect with a 407, using a persistent |
| 3196 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3197 | MockRead data_reads1[] = { |
| 3198 | // No credentials. |
| 3199 | MockRead(ASYNC, 1, |
| 3200 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3201 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3202 | "Proxy-Connection: keep-alive\r\n" |
| 3203 | "Content-Length: 10\r\n\r\n"), |
| 3204 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3205 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3206 | // Wrong credentials (wrong password). |
| 3207 | MockRead(ASYNC, 4, |
| 3208 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3209 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3210 | "Proxy-Connection: keep-alive\r\n" |
| 3211 | "Content-Length: 10\r\n\r\n"), |
| 3212 | // No response body because the test stops reading here. |
| 3213 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3214 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3215 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3216 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3217 | arraysize(data_writes1)); |
| 3218 | data1.set_busy_before_sync_reads(true); |
| 3219 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3220 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3221 | TestCompletionCallback callback1; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3222 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3223 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3224 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3225 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3226 | TestNetLogEntry::List entries; |
| 3227 | log.GetEntries(&entries); |
| 3228 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3229 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3230 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3231 | ExpectLogContainsSomewhere( |
| 3232 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3233 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3234 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3235 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3236 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3237 | ASSERT_TRUE(response); |
| 3238 | ASSERT_TRUE(response->headers); |
| 3239 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3240 | EXPECT_EQ(407, response->headers->response_code()); |
| 3241 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3242 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3243 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3244 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3245 | TestCompletionCallback callback2; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3246 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3247 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3248 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3249 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3250 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3251 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3252 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3253 | ASSERT_TRUE(response); |
| 3254 | ASSERT_TRUE(response->headers); |
| 3255 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3256 | EXPECT_EQ(407, response->headers->response_code()); |
| 3257 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3258 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3259 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3260 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3261 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3262 | // out of scope. |
| 3263 | session->CloseAllConnections(); |
| 3264 | } |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3265 | } |
| 3266 | |
| 3267 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3268 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3269 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp11) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3270 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3271 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3272 | // reused. See http://crbug.com/544255. |
| 3273 | for (int i = 0; i < 2; ++i) { |
| 3274 | HttpRequestInfo request; |
| 3275 | request.method = "GET"; |
| 3276 | request.url = GURL("https://www.example.org/"); |
| 3277 | // Ensure that proxy authentication is attempted even |
| 3278 | // when the no authentication data flag is set. |
| 3279 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
| 3280 | |
| 3281 | // Configure against proxy server "myproxy:70". |
| 3282 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
| 3283 | BoundTestNetLog log; |
| 3284 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3285 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3286 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3287 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3288 | |
| 3289 | // Since we have proxy, should try to establish tunnel. |
| 3290 | MockWrite data_writes1[] = { |
| 3291 | MockWrite(ASYNC, 0, |
| 3292 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3293 | "Host: www.example.org:443\r\n" |
| 3294 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3295 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3296 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3297 | // be issuing -- the final header line contains the credentials. |
| 3298 | MockWrite(ASYNC, 3, |
| 3299 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3300 | "Host: www.example.org:443\r\n" |
| 3301 | "Proxy-Connection: keep-alive\r\n" |
| 3302 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3303 | }; |
| 3304 | |
| 3305 | // The proxy responds to the connect with a 407, using a persistent |
| 3306 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3307 | MockRead data_reads1[] = { |
| 3308 | // No credentials. |
| 3309 | MockRead(ASYNC, 1, |
| 3310 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3311 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3312 | "Content-Length: 10\r\n\r\n"), |
| 3313 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
| 3314 | |
| 3315 | // Wrong credentials (wrong password). |
| 3316 | MockRead(ASYNC, 4, |
| 3317 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3318 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3319 | "Content-Length: 10\r\n\r\n"), |
| 3320 | // No response body because the test stops reading here. |
| 3321 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3322 | }; |
| 3323 | |
| 3324 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3325 | arraysize(data_writes1)); |
| 3326 | data1.set_busy_before_sync_reads(true); |
| 3327 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3328 | |
| 3329 | TestCompletionCallback callback1; |
| 3330 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3331 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3332 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3333 | |
| 3334 | TestNetLogEntry::List entries; |
| 3335 | log.GetEntries(&entries); |
| 3336 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3337 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3338 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3339 | ExpectLogContainsSomewhere( |
| 3340 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3341 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3342 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3343 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3344 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3345 | ASSERT_TRUE(response); |
| 3346 | ASSERT_TRUE(response->headers); |
| 3347 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3348 | EXPECT_EQ(407, response->headers->response_code()); |
| 3349 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3350 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3351 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3352 | |
| 3353 | TestCompletionCallback callback2; |
| 3354 | |
| 3355 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3356 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3357 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3358 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3359 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3360 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3361 | ASSERT_TRUE(response); |
| 3362 | ASSERT_TRUE(response->headers); |
| 3363 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3364 | EXPECT_EQ(407, response->headers->response_code()); |
| 3365 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3366 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3367 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3368 | |
| 3369 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3370 | // out of scope. |
| 3371 | session->CloseAllConnections(); |
| 3372 | } |
| 3373 | } |
| 3374 | |
| 3375 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3376 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel, in |
| 3377 | // the case the server sends extra data on the original socket, so it can't be |
| 3378 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3379 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveExtraData) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3380 | HttpRequestInfo request; |
| 3381 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3382 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3383 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3384 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3385 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3386 | // Configure against proxy server "myproxy:70". |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3387 | session_deps_.proxy_service = |
| 3388 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3389 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3390 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3391 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3392 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3393 | // Since we have proxy, should try to establish tunnel. |
| 3394 | MockWrite data_writes1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3395 | MockWrite(ASYNC, 0, |
| 3396 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3397 | "Host: www.example.org:443\r\n" |
| 3398 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3399 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3400 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3401 | // The proxy responds to the connect with a 407, using a persistent, but sends |
| 3402 | // extra data, so the socket cannot be reused. |
| 3403 | MockRead data_reads1[] = { |
| 3404 | // No credentials. |
| 3405 | MockRead(ASYNC, 1, |
| 3406 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3407 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3408 | "Content-Length: 10\r\n\r\n"), |
| 3409 | MockRead(SYNCHRONOUS, 2, "0123456789"), |
| 3410 | MockRead(SYNCHRONOUS, 3, "I'm broken!"), |
| 3411 | }; |
| 3412 | |
| 3413 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3414 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3415 | // be issuing -- the final header line contains the credentials. |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3416 | MockWrite(ASYNC, 0, |
| 3417 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3418 | "Host: www.example.org:443\r\n" |
| 3419 | "Proxy-Connection: keep-alive\r\n" |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3420 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3421 | |
| 3422 | MockWrite(ASYNC, 2, |
| 3423 | "GET / HTTP/1.1\r\n" |
| 3424 | "Host: www.example.org\r\n" |
| 3425 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3426 | }; |
| 3427 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3428 | MockRead data_reads2[] = { |
| 3429 | MockRead(ASYNC, 1, "HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3430 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3431 | MockRead(ASYNC, 3, |
| 3432 | "HTTP/1.1 200 OK\r\n" |
| 3433 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 3434 | "Content-Length: 5\r\n\r\n"), |
| 3435 | // No response body because the test stops reading here. |
| 3436 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 4), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3437 | }; |
| 3438 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3439 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3440 | arraysize(data_writes1)); |
| 3441 | data1.set_busy_before_sync_reads(true); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3442 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3443 | SequencedSocketData data2(data_reads2, arraysize(data_reads2), data_writes2, |
| 3444 | arraysize(data_writes2)); |
| 3445 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3446 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3447 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3448 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3449 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3450 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3451 | auto trans = |
| 3452 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3453 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3454 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3455 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3456 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3457 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3458 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3459 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3460 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3461 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3462 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3463 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3464 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3465 | NetLogEventPhase::NONE); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3466 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3467 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3468 | ASSERT_TRUE(response); |
| 3469 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3470 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3471 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3472 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3473 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3474 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3475 | LoadTimingInfo load_timing_info; |
| 3476 | // CONNECT requests and responses are handled at the connect job level, so |
| 3477 | // the transaction does not yet have a connection. |
| 3478 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3479 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3480 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3481 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3482 | rv = |
| 3483 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3484 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3485 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3486 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3487 | EXPECT_EQ(200, response->headers->response_code()); |
| 3488 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3489 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 3490 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3491 | // The password prompt info should not be set. |
| 3492 | EXPECT_FALSE(response->auth_challenge); |
| 3493 | |
| 3494 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3495 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3496 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3497 | |
| 3498 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3499 | session->CloseAllConnections(); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3500 | } |
| 3501 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3502 | // Test the case a proxy closes a socket while the challenge body is being |
| 3503 | // drained. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3504 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHangupDuringBody) { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3505 | HttpRequestInfo request; |
| 3506 | request.method = "GET"; |
| 3507 | request.url = GURL("https://www.example.org/"); |
| 3508 | // Ensure that proxy authentication is attempted even |
| 3509 | // when the no authentication data flag is set. |
| 3510 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
| 3511 | |
| 3512 | // Configure against proxy server "myproxy:70". |
| 3513 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3514 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3515 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3516 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3517 | |
| 3518 | // Since we have proxy, should try to establish tunnel. |
| 3519 | MockWrite data_writes1[] = { |
| 3520 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3521 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3522 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3523 | }; |
| 3524 | |
| 3525 | // The proxy responds to the connect with a 407, using a persistent |
| 3526 | // connection. |
| 3527 | MockRead data_reads1[] = { |
| 3528 | // No credentials. |
| 3529 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3530 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3531 | MockRead("Content-Length: 10\r\n\r\n"), MockRead("spam!"), |
| 3532 | // Server hands up in the middle of the body. |
| 3533 | MockRead(ASYNC, ERR_CONNECTION_CLOSED), |
| 3534 | }; |
| 3535 | |
| 3536 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3537 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3538 | // be issuing -- the final header line contains the credentials. |
| 3539 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3540 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3541 | "Proxy-Connection: keep-alive\r\n" |
| 3542 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3543 | |
| 3544 | MockWrite("GET / HTTP/1.1\r\n" |
| 3545 | "Host: www.example.org\r\n" |
| 3546 | "Connection: keep-alive\r\n\r\n"), |
| 3547 | }; |
| 3548 | |
| 3549 | MockRead data_reads2[] = { |
| 3550 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3551 | |
| 3552 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3553 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3554 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3555 | MockRead(SYNCHRONOUS, "hello"), |
| 3556 | }; |
| 3557 | |
| 3558 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3559 | data_writes1, arraysize(data_writes1)); |
| 3560 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3561 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3562 | data_writes2, arraysize(data_writes2)); |
| 3563 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3564 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3565 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3566 | |
| 3567 | TestCompletionCallback callback; |
| 3568 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3569 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3570 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3571 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3572 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3573 | ASSERT_TRUE(response); |
| 3574 | ASSERT_TRUE(response->headers); |
| 3575 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3576 | EXPECT_EQ(407, response->headers->response_code()); |
| 3577 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3578 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3579 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3580 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3581 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3582 | response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3583 | ASSERT_TRUE(response); |
| 3584 | ASSERT_TRUE(response->headers); |
| 3585 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3586 | EXPECT_EQ(200, response->headers->response_code()); |
| 3587 | std::string body; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3588 | EXPECT_THAT(ReadTransaction(&trans, &body), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3589 | EXPECT_EQ("hello", body); |
| 3590 | } |
| 3591 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3592 | // Test that we don't read the response body when we fail to establish a tunnel, |
| 3593 | // even if the user cancels the proxy's auth attempt. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3594 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3595 | HttpRequestInfo request; |
| 3596 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3597 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3598 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3599 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3600 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3601 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3602 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3603 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3604 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3605 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3606 | // Since we have proxy, should try to establish tunnel. |
| 3607 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3608 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3609 | "Host: www.example.org:443\r\n" |
| 3610 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3611 | }; |
| 3612 | |
| 3613 | // The proxy responds to the connect with a 407. |
| 3614 | MockRead data_reads[] = { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3615 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3616 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3617 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3618 | MockRead("0123456789"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3619 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3620 | }; |
| 3621 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 3622 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 3623 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3624 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3625 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3626 | TestCompletionCallback callback; |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3627 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3628 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3629 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3630 | |
| 3631 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3632 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3633 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3634 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3635 | ASSERT_TRUE(response); |
| 3636 | ASSERT_TRUE(response->headers); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3637 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3638 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3639 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3640 | |
| 3641 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3642 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3643 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 3644 | |
| 3645 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3646 | session->CloseAllConnections(); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3647 | } |
| 3648 | |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3649 | // Test that we don't pass extraneous headers from the proxy's response to the |
| 3650 | // caller when the proxy responds to CONNECT with 407. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3651 | TEST_F(HttpNetworkTransactionTest, SanitizeProxyAuthHeaders) { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3652 | HttpRequestInfo request; |
| 3653 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3654 | request.url = GURL("https://www.example.org/"); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3655 | |
| 3656 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3657 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3658 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3659 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3660 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3661 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3662 | |
| 3663 | // Since we have proxy, should try to establish tunnel. |
| 3664 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3665 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3666 | "Host: www.example.org:443\r\n" |
| 3667 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3668 | }; |
| 3669 | |
| 3670 | // The proxy responds to the connect with a 407. |
| 3671 | MockRead data_reads[] = { |
| 3672 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3673 | MockRead("X-Foo: bar\r\n"), |
| 3674 | MockRead("Set-Cookie: foo=bar\r\n"), |
| 3675 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3676 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3677 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3678 | }; |
| 3679 | |
| 3680 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 3681 | arraysize(data_writes)); |
| 3682 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 3683 | |
| 3684 | TestCompletionCallback callback; |
| 3685 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3686 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3687 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3688 | |
| 3689 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3690 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3691 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3692 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3693 | ASSERT_TRUE(response); |
| 3694 | ASSERT_TRUE(response->headers); |
| 3695 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3696 | EXPECT_EQ(407, response->headers->response_code()); |
| 3697 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3698 | EXPECT_FALSE(response->headers->HasHeader("X-Foo")); |
| 3699 | EXPECT_FALSE(response->headers->HasHeader("Set-Cookie")); |
| 3700 | |
| 3701 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3702 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3703 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3704 | |
| 3705 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
| 3706 | session->CloseAllConnections(); |
| 3707 | } |
| 3708 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3709 | // Test when a server (non-proxy) returns a 407 (proxy-authenticate). |
| 3710 | // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3711 | TEST_F(HttpNetworkTransactionTest, UnexpectedProxyAuth) { |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3712 | HttpRequestInfo request; |
| 3713 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3714 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3715 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3716 | // We are using a DIRECT connection (i.e. no proxy) for this session. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3717 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3718 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3719 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3720 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3721 | MockWrite( |
| 3722 | "GET / HTTP/1.1\r\n" |
| 3723 | "Host: www.example.org\r\n" |
| 3724 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3725 | }; |
| 3726 | |
| 3727 | MockRead data_reads1[] = { |
| 3728 | MockRead("HTTP/1.0 407 Proxy Auth required\r\n"), |
| 3729 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3730 | // Large content-length -- won't matter, as connection will be reset. |
| 3731 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3732 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3733 | }; |
| 3734 | |
| 3735 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3736 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3737 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3738 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3739 | TestCompletionCallback callback; |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3740 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3741 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3742 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3743 | |
| 3744 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3745 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3746 | } |
| 3747 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3748 | // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) |
| 3749 | // through a non-authenticating proxy. The request should fail with |
| 3750 | // ERR_UNEXPECTED_PROXY_AUTH. |
| 3751 | // Note that it is impossible to detect if an HTTP server returns a 407 through |
| 3752 | // a non-authenticating proxy - there is nothing to indicate whether the |
| 3753 | // response came from the proxy or the server, so it is treated as if the proxy |
| 3754 | // issued the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3755 | TEST_F(HttpNetworkTransactionTest, HttpsServerRequestsProxyAuthThroughProxy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3756 | HttpRequestInfo request; |
| 3757 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3758 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3759 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3760 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3761 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3762 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3763 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3764 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3765 | // Since we have proxy, should try to establish tunnel. |
| 3766 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3767 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3768 | "Host: www.example.org:443\r\n" |
| 3769 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3770 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3771 | MockWrite("GET / HTTP/1.1\r\n" |
| 3772 | "Host: www.example.org\r\n" |
| 3773 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3774 | }; |
| 3775 | |
| 3776 | MockRead data_reads1[] = { |
| 3777 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3778 | |
| 3779 | MockRead("HTTP/1.1 407 Unauthorized\r\n"), |
| 3780 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3781 | MockRead("\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3782 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3783 | }; |
| 3784 | |
| 3785 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3786 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3787 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3788 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3789 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3790 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3791 | TestCompletionCallback callback1; |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3792 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3793 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3794 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3795 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3796 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3797 | |
| 3798 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3799 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3800 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3801 | log.GetEntries(&entries); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3802 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3803 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3804 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3805 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3806 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3807 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3808 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3809 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3810 | |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3811 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 3812 | // that uses non-persistent connections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3813 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3814 | AuthAllowsDefaultCredentialsTunnelConnectionClose) { |
| 3815 | HttpRequestInfo request; |
| 3816 | request.method = "GET"; |
| 3817 | request.url = GURL("https://www.example.org/"); |
| 3818 | |
| 3819 | // Configure against proxy server "myproxy:70". |
| 3820 | session_deps_.proxy_service = |
| 3821 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 3822 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3823 | auto auth_handler_factory = base::MakeUnique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3824 | auth_handler_factory->set_do_init_from_challenge(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3825 | auto mock_handler = base::MakeUnique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3826 | mock_handler->set_allows_default_credentials(true); |
| 3827 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3828 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 3829 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3830 | |
| 3831 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 3832 | NetLog net_log; |
| 3833 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3834 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3835 | |
| 3836 | // Since we have proxy, should try to establish tunnel. |
| 3837 | MockWrite data_writes1[] = { |
| 3838 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3839 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3840 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3841 | }; |
| 3842 | |
| 3843 | // The proxy responds to the connect with a 407, using a non-persistent |
| 3844 | // connection. |
| 3845 | MockRead data_reads1[] = { |
| 3846 | // No credentials. |
| 3847 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3848 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 3849 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3850 | }; |
| 3851 | |
| 3852 | // Since the first connection couldn't be reused, need to establish another |
| 3853 | // once given credentials. |
| 3854 | MockWrite data_writes2[] = { |
| 3855 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3856 | // be issuing -- the final header line contains the credentials. |
| 3857 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3858 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3859 | "Proxy-Connection: keep-alive\r\n" |
| 3860 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3861 | |
| 3862 | MockWrite("GET / HTTP/1.1\r\n" |
| 3863 | "Host: www.example.org\r\n" |
| 3864 | "Connection: keep-alive\r\n\r\n"), |
| 3865 | }; |
| 3866 | |
| 3867 | MockRead data_reads2[] = { |
| 3868 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3869 | |
| 3870 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3871 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3872 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3873 | MockRead(SYNCHRONOUS, "hello"), |
| 3874 | }; |
| 3875 | |
| 3876 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3877 | data_writes1, arraysize(data_writes1)); |
| 3878 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3879 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3880 | data_writes2, arraysize(data_writes2)); |
| 3881 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3882 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3883 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3884 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3885 | auto trans = |
| 3886 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3887 | |
| 3888 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3889 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3890 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3891 | |
| 3892 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3893 | ASSERT_TRUE(response); |
| 3894 | ASSERT_TRUE(response->headers); |
| 3895 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
| 3896 | EXPECT_EQ(407, response->headers->response_code()); |
| 3897 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3898 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3899 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3900 | |
| 3901 | LoadTimingInfo load_timing_info; |
| 3902 | // CONNECT requests and responses are handled at the connect job level, so |
| 3903 | // the transaction does not yet have a connection. |
| 3904 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3905 | |
| 3906 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3907 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3908 | response = trans->GetResponseInfo(); |
| 3909 | ASSERT_TRUE(response); |
| 3910 | ASSERT_TRUE(response->headers); |
| 3911 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3912 | EXPECT_EQ(200, response->headers->response_code()); |
| 3913 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 3914 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3915 | |
| 3916 | // The password prompt info should not be set. |
| 3917 | EXPECT_FALSE(response->auth_challenge); |
| 3918 | |
| 3919 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3920 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3921 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3922 | |
| 3923 | trans.reset(); |
| 3924 | session->CloseAllConnections(); |
| 3925 | } |
| 3926 | |
| 3927 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 3928 | // that hangs up when credentials are initially sent. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3929 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3930 | AuthAllowsDefaultCredentialsTunnelServerClosesConnection) { |
| 3931 | HttpRequestInfo request; |
| 3932 | request.method = "GET"; |
| 3933 | request.url = GURL("https://www.example.org/"); |
| 3934 | |
| 3935 | // Configure against proxy server "myproxy:70". |
| 3936 | session_deps_.proxy_service = |
| 3937 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 3938 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3939 | auto auth_handler_factory = base::MakeUnique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3940 | auth_handler_factory->set_do_init_from_challenge(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3941 | auto mock_handler = base::MakeUnique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3942 | mock_handler->set_allows_default_credentials(true); |
| 3943 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3944 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 3945 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3946 | |
| 3947 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 3948 | NetLog net_log; |
| 3949 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3950 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3951 | |
| 3952 | // Should try to establish tunnel. |
| 3953 | MockWrite data_writes1[] = { |
| 3954 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3955 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3956 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3957 | |
| 3958 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3959 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3960 | "Proxy-Connection: keep-alive\r\n" |
| 3961 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3962 | }; |
| 3963 | |
| 3964 | // The proxy responds to the connect with a 407, using a non-persistent |
| 3965 | // connection. |
| 3966 | MockRead data_reads1[] = { |
| 3967 | // No credentials. |
| 3968 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3969 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 3970 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 3971 | }; |
| 3972 | |
| 3973 | // Since the first connection was closed, need to establish another once given |
| 3974 | // credentials. |
| 3975 | MockWrite data_writes2[] = { |
| 3976 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3977 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3978 | "Proxy-Connection: keep-alive\r\n" |
| 3979 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3980 | |
| 3981 | MockWrite("GET / HTTP/1.1\r\n" |
| 3982 | "Host: www.example.org\r\n" |
| 3983 | "Connection: keep-alive\r\n\r\n"), |
| 3984 | }; |
| 3985 | |
| 3986 | MockRead data_reads2[] = { |
| 3987 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3988 | |
| 3989 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3990 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3991 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3992 | MockRead(SYNCHRONOUS, "hello"), |
| 3993 | }; |
| 3994 | |
| 3995 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3996 | data_writes1, arraysize(data_writes1)); |
| 3997 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3998 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3999 | data_writes2, arraysize(data_writes2)); |
| 4000 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4001 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4002 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4003 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4004 | auto trans = |
| 4005 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4006 | |
| 4007 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4008 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4009 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4010 | |
| 4011 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4012 | ASSERT_TRUE(response); |
| 4013 | ASSERT_TRUE(response->headers); |
| 4014 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4015 | EXPECT_EQ(407, response->headers->response_code()); |
| 4016 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4017 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4018 | EXPECT_FALSE(response->auth_challenge); |
| 4019 | |
| 4020 | LoadTimingInfo load_timing_info; |
| 4021 | // CONNECT requests and responses are handled at the connect job level, so |
| 4022 | // the transaction does not yet have a connection. |
| 4023 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4024 | |
| 4025 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4026 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4027 | |
| 4028 | response = trans->GetResponseInfo(); |
| 4029 | ASSERT_TRUE(response); |
| 4030 | ASSERT_TRUE(response->headers); |
| 4031 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4032 | EXPECT_EQ(200, response->headers->response_code()); |
| 4033 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 4034 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4035 | |
| 4036 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4037 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4038 | |
| 4039 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4040 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4041 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4042 | |
| 4043 | trans.reset(); |
| 4044 | session->CloseAllConnections(); |
| 4045 | } |
| 4046 | |
| 4047 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4048 | // that hangs up when credentials are initially sent, and hangs up again when |
| 4049 | // they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4050 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4051 | AuthAllowsDefaultCredentialsTunnelServerClosesConnectionTwice) { |
| 4052 | HttpRequestInfo request; |
| 4053 | request.method = "GET"; |
| 4054 | request.url = GURL("https://www.example.org/"); |
| 4055 | |
| 4056 | // Configure against proxy server "myproxy:70". |
| 4057 | session_deps_.proxy_service = |
| 4058 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 4059 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4060 | auto auth_handler_factory = base::MakeUnique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4061 | auth_handler_factory->set_do_init_from_challenge(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4062 | auto mock_handler = base::MakeUnique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4063 | mock_handler->set_allows_default_credentials(true); |
| 4064 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4065 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4066 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4067 | |
| 4068 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4069 | NetLog net_log; |
| 4070 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4071 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4072 | |
| 4073 | // Should try to establish tunnel. |
| 4074 | MockWrite data_writes1[] = { |
| 4075 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4076 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4077 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4078 | |
| 4079 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4080 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4081 | "Proxy-Connection: keep-alive\r\n" |
| 4082 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4083 | }; |
| 4084 | |
| 4085 | // The proxy responds to the connect with a 407, and then hangs up after the |
| 4086 | // second request is sent. |
| 4087 | MockRead data_reads1[] = { |
| 4088 | // No credentials. |
| 4089 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4090 | MockRead("Content-Length: 0\r\n"), |
| 4091 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4092 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4093 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4094 | }; |
| 4095 | |
| 4096 | // HttpNetworkTransaction sees a reused connection that was closed with |
| 4097 | // ERR_CONNECTION_CLOSED, realized it might have been a race, so retries the |
| 4098 | // request. |
| 4099 | MockWrite data_writes2[] = { |
| 4100 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4101 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4102 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4103 | }; |
| 4104 | |
| 4105 | // The proxy, having had more than enough of us, just hangs up. |
| 4106 | MockRead data_reads2[] = { |
| 4107 | // No credentials. |
| 4108 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4109 | }; |
| 4110 | |
| 4111 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4112 | data_writes1, arraysize(data_writes1)); |
| 4113 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4114 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4115 | data_writes2, arraysize(data_writes2)); |
| 4116 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4117 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4118 | auto trans = |
| 4119 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4120 | |
| 4121 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4122 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4123 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4124 | |
| 4125 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4126 | ASSERT_TRUE(response); |
| 4127 | ASSERT_TRUE(response->headers); |
| 4128 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4129 | EXPECT_EQ(407, response->headers->response_code()); |
| 4130 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4131 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4132 | EXPECT_FALSE(response->auth_challenge); |
| 4133 | |
| 4134 | LoadTimingInfo load_timing_info; |
| 4135 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4136 | |
| 4137 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4138 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4139 | |
| 4140 | trans.reset(); |
| 4141 | session->CloseAllConnections(); |
| 4142 | } |
| 4143 | |
| 4144 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4145 | // that hangs up when credentials are initially sent, and sends a challenge |
| 4146 | // again they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4147 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4148 | AuthAllowsDefaultCredentialsTunnelServerChallengesTwice) { |
| 4149 | HttpRequestInfo request; |
| 4150 | request.method = "GET"; |
| 4151 | request.url = GURL("https://www.example.org/"); |
| 4152 | |
| 4153 | // Configure against proxy server "myproxy:70". |
| 4154 | session_deps_.proxy_service = |
| 4155 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 4156 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4157 | auto auth_handler_factory = base::MakeUnique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4158 | auth_handler_factory->set_do_init_from_challenge(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4159 | auto mock_handler = base::MakeUnique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4160 | mock_handler->set_allows_default_credentials(true); |
| 4161 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4162 | HttpAuth::AUTH_PROXY); |
| 4163 | // Add another handler for the second challenge. It supports default |
| 4164 | // credentials, but they shouldn't be used, since they were already tried. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4165 | mock_handler = base::MakeUnique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4166 | mock_handler->set_allows_default_credentials(true); |
| 4167 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4168 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4169 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4170 | |
| 4171 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4172 | NetLog net_log; |
| 4173 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4174 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4175 | |
| 4176 | // Should try to establish tunnel. |
| 4177 | MockWrite data_writes1[] = { |
| 4178 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4179 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4180 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4181 | }; |
| 4182 | |
| 4183 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4184 | // connection. |
| 4185 | MockRead data_reads1[] = { |
| 4186 | // No credentials. |
| 4187 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4188 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4189 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4190 | }; |
| 4191 | |
| 4192 | // Since the first connection was closed, need to establish another once given |
| 4193 | // credentials. |
| 4194 | MockWrite data_writes2[] = { |
| 4195 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4196 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4197 | "Proxy-Connection: keep-alive\r\n" |
| 4198 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4199 | }; |
| 4200 | |
| 4201 | MockRead data_reads2[] = { |
| 4202 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4203 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4204 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4205 | }; |
| 4206 | |
| 4207 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4208 | data_writes1, arraysize(data_writes1)); |
| 4209 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4210 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4211 | data_writes2, arraysize(data_writes2)); |
| 4212 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4213 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4214 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4215 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4216 | auto trans = |
| 4217 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4218 | |
| 4219 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4220 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4221 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4222 | |
| 4223 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4224 | ASSERT_TRUE(response); |
| 4225 | ASSERT_TRUE(response->headers); |
| 4226 | EXPECT_EQ(407, response->headers->response_code()); |
| 4227 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4228 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4229 | EXPECT_FALSE(response->auth_challenge); |
| 4230 | |
| 4231 | LoadTimingInfo load_timing_info; |
| 4232 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4233 | |
| 4234 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4235 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4236 | response = trans->GetResponseInfo(); |
| 4237 | ASSERT_TRUE(response); |
| 4238 | ASSERT_TRUE(response->headers); |
| 4239 | EXPECT_EQ(407, response->headers->response_code()); |
| 4240 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4241 | EXPECT_TRUE(response->auth_challenge); |
| 4242 | |
| 4243 | trans.reset(); |
| 4244 | session->CloseAllConnections(); |
| 4245 | } |
| 4246 | |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4247 | // A more nuanced test than GenerateAuthToken test which asserts that |
| 4248 | // ERR_INVALID_AUTH_CREDENTIALS does not cause the auth scheme to be |
| 4249 | // unnecessarily invalidated, and that if the server co-operates, the |
| 4250 | // authentication handshake can continue with the same scheme but with a |
| 4251 | // different identity. |
| 4252 | TEST_F(HttpNetworkTransactionTest, NonPermanentGenerateAuthTokenError) { |
| 4253 | HttpRequestInfo request; |
| 4254 | request.method = "GET"; |
| 4255 | request.url = GURL("http://www.example.org/"); |
| 4256 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4257 | auto auth_handler_factory = base::MakeUnique<HttpAuthHandlerMock::Factory>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4258 | auth_handler_factory->set_do_init_from_challenge(true); |
| 4259 | |
| 4260 | // First handler. Uses default credentials, but barfs at generate auth token. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4261 | auto mock_handler = base::MakeUnique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4262 | mock_handler->set_allows_default_credentials(true); |
| 4263 | mock_handler->set_allows_explicit_credentials(true); |
| 4264 | mock_handler->set_connection_based(true); |
| 4265 | mock_handler->SetGenerateExpectation(true, ERR_INVALID_AUTH_CREDENTIALS); |
| 4266 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4267 | HttpAuth::AUTH_SERVER); |
| 4268 | |
| 4269 | // Add another handler for the second challenge. It supports default |
| 4270 | // credentials, but they shouldn't be used, since they were already tried. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4271 | mock_handler = base::MakeUnique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4272 | mock_handler->set_allows_default_credentials(true); |
| 4273 | mock_handler->set_allows_explicit_credentials(true); |
| 4274 | mock_handler->set_connection_based(true); |
| 4275 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4276 | HttpAuth::AUTH_SERVER); |
| 4277 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
| 4278 | |
| 4279 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4280 | |
| 4281 | MockWrite data_writes1[] = { |
| 4282 | MockWrite("GET / HTTP/1.1\r\n" |
| 4283 | "Host: www.example.org\r\n" |
| 4284 | "Connection: keep-alive\r\n\r\n"), |
| 4285 | }; |
| 4286 | |
| 4287 | MockRead data_reads1[] = { |
| 4288 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4289 | "WWW-Authenticate: Mock\r\n" |
| 4290 | "Connection: keep-alive\r\n\r\n"), |
| 4291 | }; |
| 4292 | |
| 4293 | // Identical to data_writes1[]. The AuthHandler encounters a |
| 4294 | // ERR_INVALID_AUTH_CREDENTIALS during the GenerateAuthToken stage, so the |
| 4295 | // transaction procceds without an authorization header. |
| 4296 | MockWrite data_writes2[] = { |
| 4297 | MockWrite("GET / HTTP/1.1\r\n" |
| 4298 | "Host: www.example.org\r\n" |
| 4299 | "Connection: keep-alive\r\n\r\n"), |
| 4300 | }; |
| 4301 | |
| 4302 | MockRead data_reads2[] = { |
| 4303 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4304 | "WWW-Authenticate: Mock\r\n" |
| 4305 | "Connection: keep-alive\r\n\r\n"), |
| 4306 | }; |
| 4307 | |
| 4308 | MockWrite data_writes3[] = { |
| 4309 | MockWrite("GET / HTTP/1.1\r\n" |
| 4310 | "Host: www.example.org\r\n" |
| 4311 | "Connection: keep-alive\r\n" |
| 4312 | "Authorization: auth_token\r\n\r\n"), |
| 4313 | }; |
| 4314 | |
| 4315 | MockRead data_reads3[] = { |
| 4316 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4317 | "Content-Length: 5\r\n" |
| 4318 | "Content-Type: text/plain\r\n" |
| 4319 | "Connection: keep-alive\r\n\r\n" |
| 4320 | "Hello"), |
| 4321 | }; |
| 4322 | |
| 4323 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4324 | data_writes1, arraysize(data_writes1)); |
| 4325 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4326 | |
| 4327 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4328 | data_writes2, arraysize(data_writes2)); |
| 4329 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4330 | |
| 4331 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 4332 | data_writes3, arraysize(data_writes3)); |
| 4333 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 4334 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4335 | auto trans = |
| 4336 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4337 | |
| 4338 | TestCompletionCallback callback; |
| 4339 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 4340 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4341 | |
| 4342 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4343 | ASSERT_TRUE(response); |
| 4344 | ASSERT_TRUE(response->headers); |
| 4345 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4346 | |
| 4347 | // The following three tests assert that an authentication challenge was |
| 4348 | // received and that the stack is ready to respond to the challenge using |
| 4349 | // ambient credentials. |
| 4350 | EXPECT_EQ(401, response->headers->response_code()); |
| 4351 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4352 | EXPECT_FALSE(response->auth_challenge); |
| 4353 | |
| 4354 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4355 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4356 | response = trans->GetResponseInfo(); |
| 4357 | ASSERT_TRUE(response); |
| 4358 | ASSERT_TRUE(response->headers); |
| 4359 | |
| 4360 | // The following three tests assert that an authentication challenge was |
| 4361 | // received and that the stack needs explicit credentials before it is ready |
| 4362 | // to respond to the challenge. |
| 4363 | EXPECT_EQ(401, response->headers->response_code()); |
| 4364 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4365 | EXPECT_TRUE(response->auth_challenge); |
| 4366 | |
| 4367 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4368 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4369 | response = trans->GetResponseInfo(); |
| 4370 | ASSERT_TRUE(response); |
| 4371 | ASSERT_TRUE(response->headers); |
| 4372 | EXPECT_EQ(200, response->headers->response_code()); |
| 4373 | |
| 4374 | trans.reset(); |
| 4375 | session->CloseAllConnections(); |
| 4376 | } |
| 4377 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4378 | // Test the load timing for HTTPS requests with an HTTP proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4379 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingNoPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4380 | HttpRequestInfo request1; |
| 4381 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4382 | request1.url = GURL("https://www.example.org/1"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4383 | |
| 4384 | HttpRequestInfo request2; |
| 4385 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4386 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4387 | |
| 4388 | // Configure against proxy server "myproxy:70". |
brettw | c1213d9 | 2016-11-12 03:41:13 | [diff] [blame] | 4389 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4390 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4391 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4392 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4393 | |
| 4394 | // Since we have proxy, should try to establish tunnel. |
| 4395 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4396 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4397 | "Host: www.example.org:443\r\n" |
| 4398 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4399 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4400 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 4401 | "Host: www.example.org\r\n" |
| 4402 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4403 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4404 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 4405 | "Host: www.example.org\r\n" |
| 4406 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4407 | }; |
| 4408 | |
| 4409 | // The proxy responds to the connect with a 407, using a persistent |
| 4410 | // connection. |
| 4411 | MockRead data_reads1[] = { |
| 4412 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4413 | |
| 4414 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4415 | MockRead("Content-Length: 1\r\n\r\n"), |
| 4416 | MockRead(SYNCHRONOUS, "1"), |
| 4417 | |
| 4418 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4419 | MockRead("Content-Length: 2\r\n\r\n"), |
| 4420 | MockRead(SYNCHRONOUS, "22"), |
| 4421 | }; |
| 4422 | |
| 4423 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4424 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4425 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4426 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4427 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4428 | |
| 4429 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4430 | auto trans1 = |
| 4431 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4432 | |
| 4433 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4434 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4435 | |
| 4436 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4437 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4438 | |
| 4439 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4440 | ASSERT_TRUE(response1); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4441 | EXPECT_TRUE(response1->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4442 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4443 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 4444 | |
| 4445 | LoadTimingInfo load_timing_info1; |
| 4446 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 4447 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4448 | |
| 4449 | trans1.reset(); |
| 4450 | |
| 4451 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4452 | auto trans2 = |
| 4453 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4454 | |
| 4455 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4456 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4457 | |
| 4458 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4459 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4460 | |
| 4461 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4462 | ASSERT_TRUE(response2); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4463 | EXPECT_TRUE(response2->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4464 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4465 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 4466 | |
| 4467 | LoadTimingInfo load_timing_info2; |
| 4468 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4469 | TestLoadTimingReused(load_timing_info2); |
| 4470 | |
| 4471 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 4472 | |
| 4473 | trans2.reset(); |
| 4474 | session->CloseAllConnections(); |
| 4475 | } |
| 4476 | |
| 4477 | // 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] | 4478 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingWithPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4479 | HttpRequestInfo request1; |
| 4480 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4481 | request1.url = GURL("https://www.example.org/1"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4482 | |
| 4483 | HttpRequestInfo request2; |
| 4484 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4485 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4486 | |
| 4487 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4488 | session_deps_.proxy_service = |
| 4489 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4490 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4491 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4492 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4493 | |
| 4494 | // Since we have proxy, should try to establish tunnel. |
| 4495 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4496 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4497 | "Host: www.example.org:443\r\n" |
| 4498 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4499 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4500 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 4501 | "Host: www.example.org\r\n" |
| 4502 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4503 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4504 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 4505 | "Host: www.example.org\r\n" |
| 4506 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4507 | }; |
| 4508 | |
| 4509 | // The proxy responds to the connect with a 407, using a persistent |
| 4510 | // connection. |
| 4511 | MockRead data_reads1[] = { |
| 4512 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4513 | |
| 4514 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4515 | MockRead("Content-Length: 1\r\n\r\n"), |
| 4516 | MockRead(SYNCHRONOUS, "1"), |
| 4517 | |
| 4518 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4519 | MockRead("Content-Length: 2\r\n\r\n"), |
| 4520 | MockRead(SYNCHRONOUS, "22"), |
| 4521 | }; |
| 4522 | |
| 4523 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4524 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4525 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4526 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4527 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4528 | |
| 4529 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4530 | auto trans1 = |
| 4531 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4532 | |
| 4533 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4534 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4535 | |
| 4536 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4537 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4538 | |
| 4539 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4540 | ASSERT_TRUE(response1); |
| 4541 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4542 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 4543 | |
| 4544 | LoadTimingInfo load_timing_info1; |
| 4545 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 4546 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 4547 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4548 | |
| 4549 | trans1.reset(); |
| 4550 | |
| 4551 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4552 | auto trans2 = |
| 4553 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4554 | |
| 4555 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4556 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4557 | |
| 4558 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4559 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4560 | |
| 4561 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4562 | ASSERT_TRUE(response2); |
| 4563 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4564 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 4565 | |
| 4566 | LoadTimingInfo load_timing_info2; |
| 4567 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4568 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 4569 | |
| 4570 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 4571 | |
| 4572 | trans2.reset(); |
| 4573 | session->CloseAllConnections(); |
| 4574 | } |
| 4575 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4576 | // Test a simple get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4577 | TEST_F(HttpNetworkTransactionTest, HttpsProxyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4578 | HttpRequestInfo request; |
| 4579 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4580 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4581 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4582 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4583 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4584 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4585 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4586 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4587 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4588 | // Since we have proxy, should use full url |
| 4589 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4590 | MockWrite( |
| 4591 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 4592 | "Host: www.example.org\r\n" |
| 4593 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4594 | }; |
| 4595 | |
| 4596 | MockRead data_reads1[] = { |
| 4597 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4598 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4599 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4600 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4601 | }; |
| 4602 | |
| 4603 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4604 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4605 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4606 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4607 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4608 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4609 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4610 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4611 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4612 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4613 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4614 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4615 | |
| 4616 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4617 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4618 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4619 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4620 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4621 | TestLoadTimingNotReused(load_timing_info, |
| 4622 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4623 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4624 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4625 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4626 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4627 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4628 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4629 | EXPECT_EQ(200, response->headers->response_code()); |
| 4630 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 4631 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4632 | |
| 4633 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4634 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4635 | } |
| 4636 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4637 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4638 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4639 | HttpRequestInfo request; |
| 4640 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4641 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4642 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4643 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4644 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4645 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4646 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4647 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4648 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4649 | // fetch http://www.example.org/ via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4650 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 4651 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4652 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4653 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4654 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4655 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4656 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4657 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4658 | }; |
| 4659 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4660 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4661 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4662 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4663 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4664 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4665 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4666 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4667 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4668 | TestCompletionCallback callback1; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4669 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4670 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4671 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4672 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4673 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4674 | |
| 4675 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4676 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4677 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4678 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4679 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4680 | TestLoadTimingNotReused(load_timing_info, |
| 4681 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4682 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4683 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4684 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4685 | EXPECT_TRUE(response->proxy_server.is_https()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4686 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4687 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4688 | |
| 4689 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4690 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 4691 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4692 | } |
| 4693 | |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4694 | // Verifies that a session which races and wins against the owning transaction |
| 4695 | // (completing prior to host resolution), doesn't fail the transaction. |
| 4696 | // Regression test for crbug.com/334413. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4697 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithSessionRace) { |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4698 | HttpRequestInfo request; |
| 4699 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4700 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4701 | |
| 4702 | // Configure SPDY proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4703 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4704 | BoundTestNetLog log; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4705 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4706 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4707 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4708 | // Fetch http://www.example.org/ through the SPDY proxy. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4709 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 4710 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4711 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4712 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4713 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4714 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4715 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4716 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4717 | }; |
| 4718 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4719 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4720 | arraysize(spdy_writes)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4721 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 4722 | |
| 4723 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4724 | ssl.next_proto = kProtoHTTP2; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4725 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4726 | |
| 4727 | TestCompletionCallback callback1; |
| 4728 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4729 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4730 | |
| 4731 | // Stall the hostname resolution begun by the transaction. |
| 4732 | session_deps_.host_resolver->set_synchronous_mode(false); |
| 4733 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 4734 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4735 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4736 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4737 | |
| 4738 | // Race a session to the proxy, which completes first. |
| 4739 | session_deps_.host_resolver->set_ondemand_mode(false); |
| 4740 | SpdySessionKey key( |
| 4741 | HostPortPair("proxy", 70), ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
| 4742 | base::WeakPtr<SpdySession> spdy_session = |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 4743 | CreateSecureSpdySession(session.get(), key, log.bound()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4744 | |
| 4745 | // Unstall the resolution begun by the transaction. |
| 4746 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 4747 | session_deps_.host_resolver->ResolveAllPending(); |
| 4748 | |
| 4749 | EXPECT_FALSE(callback1.have_result()); |
| 4750 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4751 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4752 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4753 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4754 | ASSERT_TRUE(response); |
| 4755 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4756 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4757 | |
| 4758 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4759 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4760 | EXPECT_EQ(kUploadData, response_data); |
| 4761 | } |
| 4762 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4763 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4764 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4765 | HttpRequestInfo request; |
| 4766 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4767 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4768 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4769 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4770 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4771 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4772 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4773 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4774 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4775 | // The first request will be a bare GET, the second request will be a |
| 4776 | // GET with a Proxy-Authorization header. |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 4777 | spdy_util_.set_default_url(request.url); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4778 | SpdySerializedFrame req_get( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4779 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, false)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4780 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4781 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4782 | "proxy-authorization", "Basic Zm9vOmJhcg==" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4783 | }; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4784 | SpdySerializedFrame req_get_authorization(spdy_util_.ConstructSpdyGet( |
| 4785 | kExtraAuthorizationHeaders, arraysize(kExtraAuthorizationHeaders) / 2, 3, |
| 4786 | LOWEST, false)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4787 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4788 | CreateMockWrite(req_get, 0), CreateMockWrite(req_get_authorization, 3), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4789 | }; |
| 4790 | |
| 4791 | // The first response is a 407 proxy authentication challenge, and the second |
| 4792 | // response will be a 200 response since the second request includes a valid |
| 4793 | // Authorization header. |
| 4794 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4795 | "proxy-authenticate", "Basic realm=\"MyRealm1\"" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4796 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4797 | SpdySerializedFrame resp_authentication(spdy_util_.ConstructSpdyReplyError( |
bnc | c9f762a | 2016-12-06 20:38:23 | [diff] [blame] | 4798 | "407", kExtraAuthenticationHeaders, |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4799 | arraysize(kExtraAuthenticationHeaders) / 2, 1)); |
| 4800 | SpdySerializedFrame body_authentication( |
| 4801 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4802 | SpdySerializedFrame resp_data(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4803 | SpdySerializedFrame body_data(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4804 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4805 | CreateMockRead(resp_authentication, 1), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 4806 | CreateMockRead(body_authentication, 2, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4807 | CreateMockRead(resp_data, 4), |
| 4808 | CreateMockRead(body_data, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4809 | MockRead(ASYNC, 0, 6), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4810 | }; |
| 4811 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4812 | SequencedSocketData data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4813 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4814 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4815 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4816 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4817 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4818 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4819 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4820 | TestCompletionCallback callback1; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4821 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4822 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4823 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4824 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4825 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4826 | |
| 4827 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4828 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4829 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4830 | const HttpResponseInfo* const response = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4831 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4832 | ASSERT_TRUE(response); |
| 4833 | ASSERT_TRUE(response->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4834 | EXPECT_EQ(407, response->headers->response_code()); |
| 4835 | EXPECT_TRUE(response->was_fetched_via_spdy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 4836 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4837 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4838 | TestCompletionCallback callback2; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4839 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4840 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4841 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4842 | |
| 4843 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4844 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4845 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4846 | const HttpResponseInfo* const response_restart = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4847 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4848 | ASSERT_TRUE(response_restart); |
| 4849 | ASSERT_TRUE(response_restart->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4850 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 4851 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4852 | EXPECT_FALSE(response_restart->auth_challenge); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4853 | } |
| 4854 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4855 | // Test a SPDY CONNECT through an HTTPS Proxy to an HTTPS (non-SPDY) Server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4856 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4857 | HttpRequestInfo request; |
| 4858 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4859 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4860 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4861 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4862 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4863 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4864 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4865 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4866 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4867 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4868 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4869 | // CONNECT to www.example.org:443 via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4870 | SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4871 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 4872 | // fetch https://www.example.org/ via HTTP |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4873 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4874 | const char get[] = |
| 4875 | "GET / HTTP/1.1\r\n" |
| 4876 | "Host: www.example.org\r\n" |
| 4877 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4878 | SpdySerializedFrame wrapped_get( |
| 4879 | spdy_util_.ConstructSpdyDataFrame(1, get, strlen(get), false)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4880 | SpdySerializedFrame conn_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4881 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 4882 | "Content-Length: 10\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4883 | SpdySerializedFrame wrapped_get_resp( |
| 4884 | spdy_util_.ConstructSpdyDataFrame(1, resp, strlen(resp), false)); |
| 4885 | SpdySerializedFrame wrapped_body( |
| 4886 | spdy_util_.ConstructSpdyDataFrame(1, "1234567890", 10, false)); |
| 4887 | SpdySerializedFrame window_update( |
| 4888 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4889 | |
| 4890 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4891 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 4892 | CreateMockWrite(window_update, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4893 | }; |
| 4894 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4895 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4896 | CreateMockRead(conn_resp, 1, ASYNC), |
| 4897 | CreateMockRead(wrapped_get_resp, 3, ASYNC), |
| 4898 | CreateMockRead(wrapped_body, 4, ASYNC), |
| 4899 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4900 | MockRead(ASYNC, 0, 7), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4901 | }; |
| 4902 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4903 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4904 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4905 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4906 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4907 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4908 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4909 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4910 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4911 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4912 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4913 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4914 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4915 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4916 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4917 | |
| 4918 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4919 | ASSERT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4920 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4921 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4922 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4923 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4924 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4925 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4926 | ASSERT_TRUE(response); |
| 4927 | ASSERT_TRUE(response->headers); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4928 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 4929 | |
| 4930 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4931 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4932 | EXPECT_EQ("1234567890", response_data); |
| 4933 | } |
| 4934 | |
| 4935 | // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4936 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) { |
| 4937 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4938 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4939 | HttpRequestInfo request; |
| 4940 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4941 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4942 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4943 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4944 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4945 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4946 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4947 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4948 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4949 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4950 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4951 | // CONNECT to www.example.org:443 via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4952 | SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4953 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 4954 | // fetch https://www.example.org/ via SPDY |
| 4955 | const char kMyUrl[] = "https://www.example.org/"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4956 | SpdySerializedFrame get( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4957 | spdy_util_wrapped.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4958 | SpdySerializedFrame wrapped_get(spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4959 | SpdySerializedFrame conn_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4960 | SpdySerializedFrame get_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4961 | spdy_util_wrapped.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4962 | SpdySerializedFrame wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4963 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4964 | SpdySerializedFrame body(spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 4965 | SpdySerializedFrame wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 4966 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4967 | SpdySerializedFrame window_update_get_resp( |
| 4968 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
| 4969 | SpdySerializedFrame window_update_body( |
| 4970 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4971 | |
| 4972 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4973 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 4974 | CreateMockWrite(window_update_get_resp, 6), |
| 4975 | CreateMockWrite(window_update_body, 7), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4976 | }; |
| 4977 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4978 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4979 | CreateMockRead(conn_resp, 1, ASYNC), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4980 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4981 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 4982 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4983 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4984 | }; |
| 4985 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 4986 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4987 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4988 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4989 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4990 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4991 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4992 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4993 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4994 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4995 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4996 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4997 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4998 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4999 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5000 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5001 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5002 | // Allow the SpdyProxyClientSocket's write callback to complete. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 5003 | base::RunLoop().RunUntilIdle(); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5004 | // Now allow the read of the response to complete. |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 5005 | spdy_data.Resume(); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5006 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5007 | EXPECT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5008 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5009 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5010 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5011 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5012 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5013 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5014 | ASSERT_TRUE(response); |
| 5015 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5016 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5017 | |
| 5018 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5019 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5020 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5021 | } |
| 5022 | |
| 5023 | // Test a SPDY CONNECT failure through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5024 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5025 | HttpRequestInfo request; |
| 5026 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5027 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5028 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5029 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5030 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5031 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5032 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5033 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5034 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5035 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5036 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5037 | // CONNECT to www.example.org:443 via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5038 | SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5039 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5040 | SpdySerializedFrame get( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 5041 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5042 | |
| 5043 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5044 | CreateMockWrite(connect, 0), CreateMockWrite(get, 2), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5045 | }; |
| 5046 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5047 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError(1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5048 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5049 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5050 | CreateMockRead(resp, 1, ASYNC), MockRead(ASYNC, 0, 3), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5051 | }; |
| 5052 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5053 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5054 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5055 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5056 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5057 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5058 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5059 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5060 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5061 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5062 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5063 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5064 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5065 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5066 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5067 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5068 | |
| 5069 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5070 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5071 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 5072 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5073 | } |
| 5074 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5075 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 5076 | // HTTPS Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5077 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5078 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) { |
| 5079 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5080 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5081 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5082 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5083 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5084 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5085 | |
| 5086 | HttpRequestInfo request1; |
| 5087 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5088 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5089 | request1.load_flags = 0; |
| 5090 | |
| 5091 | HttpRequestInfo request2; |
| 5092 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5093 | request2.url = GURL("https://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5094 | request2.load_flags = 0; |
| 5095 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5096 | // CONNECT to www.example.org:443 via SPDY. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5097 | SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5098 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5099 | SpdySerializedFrame conn_resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5100 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5101 | // Fetch https://www.example.org/ via HTTP. |
| 5102 | const char get1[] = |
| 5103 | "GET / HTTP/1.1\r\n" |
| 5104 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5105 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5106 | SpdySerializedFrame wrapped_get1( |
| 5107 | spdy_util_.ConstructSpdyDataFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5108 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 5109 | "Content-Length: 1\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5110 | SpdySerializedFrame wrapped_get_resp1( |
| 5111 | spdy_util_.ConstructSpdyDataFrame(1, resp1, strlen(resp1), false)); |
| 5112 | SpdySerializedFrame wrapped_body1( |
| 5113 | spdy_util_.ConstructSpdyDataFrame(1, "1", 1, false)); |
| 5114 | SpdySerializedFrame window_update( |
| 5115 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5116 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5117 | // CONNECT to mail.example.org:443 via SPDY. |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 5118 | SpdyHeaderBlock connect2_block; |
| 5119 | connect2_block[spdy_util_.GetMethodKey()] = "CONNECT"; |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 5120 | connect2_block[spdy_util_.GetHostKey()] = "mail.example.org:443"; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5121 | SpdySerializedFrame connect2(spdy_util_.ConstructSpdyHeaders( |
| 5122 | 3, std::move(connect2_block), LOWEST, false)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 5123 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5124 | SpdySerializedFrame conn_resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5125 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5126 | // Fetch https://mail.example.org/ via HTTP. |
| 5127 | const char get2[] = |
| 5128 | "GET / HTTP/1.1\r\n" |
| 5129 | "Host: mail.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5130 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5131 | SpdySerializedFrame wrapped_get2( |
| 5132 | spdy_util_.ConstructSpdyDataFrame(3, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5133 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 5134 | "Content-Length: 2\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5135 | SpdySerializedFrame wrapped_get_resp2( |
| 5136 | spdy_util_.ConstructSpdyDataFrame(3, resp2, strlen(resp2), false)); |
| 5137 | SpdySerializedFrame wrapped_body2( |
| 5138 | spdy_util_.ConstructSpdyDataFrame(3, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5139 | |
| 5140 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5141 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 5142 | CreateMockWrite(connect2, 5), CreateMockWrite(wrapped_get2, 7), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5143 | }; |
| 5144 | |
| 5145 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5146 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 5147 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
| 5148 | CreateMockRead(wrapped_body1, 4, ASYNC), |
| 5149 | CreateMockRead(conn_resp2, 6, ASYNC), |
| 5150 | CreateMockRead(wrapped_get_resp2, 8, ASYNC), |
| 5151 | CreateMockRead(wrapped_body2, 9, ASYNC), |
| 5152 | MockRead(ASYNC, 0, 10), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5153 | }; |
| 5154 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5155 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5156 | arraysize(spdy_writes)); |
| 5157 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5158 | |
| 5159 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5160 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5161 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5162 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5163 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5164 | SSLSocketDataProvider ssl3(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5165 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5166 | |
| 5167 | TestCompletionCallback callback; |
| 5168 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5169 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5170 | int rv = trans.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5171 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5172 | |
| 5173 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5174 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5175 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5176 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5177 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5178 | ASSERT_TRUE(response); |
| 5179 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5180 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5181 | |
| 5182 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5183 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5184 | rv = trans.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5185 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5186 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5187 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5188 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5189 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5190 | |
| 5191 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5192 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5193 | // Even though the SPDY connection is reused, a new tunnelled connection has |
| 5194 | // to be created, so the socket's load timing looks like a fresh connection. |
| 5195 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5196 | |
| 5197 | // The requests should have different IDs, since they each are using their own |
| 5198 | // separate stream. |
| 5199 | EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5200 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5201 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5202 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5203 | } |
| 5204 | |
| 5205 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 5206 | // HTTPS Proxy to the same server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5207 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5208 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) { |
| 5209 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5210 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5211 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5212 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5213 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5214 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5215 | |
| 5216 | HttpRequestInfo request1; |
| 5217 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5218 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5219 | request1.load_flags = 0; |
| 5220 | |
| 5221 | HttpRequestInfo request2; |
| 5222 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5223 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5224 | request2.load_flags = 0; |
| 5225 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5226 | // CONNECT to www.example.org:443 via SPDY. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5227 | SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5228 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5229 | SpdySerializedFrame conn_resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5230 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5231 | // Fetch https://www.example.org/ via HTTP. |
| 5232 | const char get1[] = |
| 5233 | "GET / HTTP/1.1\r\n" |
| 5234 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5235 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5236 | SpdySerializedFrame wrapped_get1( |
| 5237 | spdy_util_.ConstructSpdyDataFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5238 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 5239 | "Content-Length: 1\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5240 | SpdySerializedFrame wrapped_get_resp1( |
| 5241 | spdy_util_.ConstructSpdyDataFrame(1, resp1, strlen(resp1), false)); |
| 5242 | SpdySerializedFrame wrapped_body1( |
| 5243 | spdy_util_.ConstructSpdyDataFrame(1, "1", 1, false)); |
| 5244 | SpdySerializedFrame window_update( |
| 5245 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5246 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5247 | // Fetch https://www.example.org/2 via HTTP. |
| 5248 | const char get2[] = |
| 5249 | "GET /2 HTTP/1.1\r\n" |
| 5250 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5251 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5252 | SpdySerializedFrame wrapped_get2( |
| 5253 | spdy_util_.ConstructSpdyDataFrame(1, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5254 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 5255 | "Content-Length: 2\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5256 | SpdySerializedFrame wrapped_get_resp2( |
| 5257 | spdy_util_.ConstructSpdyDataFrame(1, resp2, strlen(resp2), false)); |
| 5258 | SpdySerializedFrame wrapped_body2( |
| 5259 | spdy_util_.ConstructSpdyDataFrame(1, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5260 | |
| 5261 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5262 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 5263 | CreateMockWrite(wrapped_get2, 5), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5264 | }; |
| 5265 | |
| 5266 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5267 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 5268 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5269 | CreateMockRead(wrapped_body1, 4, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5270 | CreateMockRead(wrapped_get_resp2, 6, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5271 | CreateMockRead(wrapped_body2, 7, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5272 | MockRead(ASYNC, 0, 8), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5273 | }; |
| 5274 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5275 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5276 | arraysize(spdy_writes)); |
| 5277 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5278 | |
| 5279 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5280 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5281 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5282 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5283 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5284 | |
| 5285 | TestCompletionCallback callback; |
| 5286 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5287 | auto trans = |
| 5288 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5289 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5290 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5291 | |
| 5292 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5293 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5294 | |
| 5295 | LoadTimingInfo load_timing_info; |
| 5296 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5297 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5298 | |
| 5299 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5300 | ASSERT_TRUE(response); |
| 5301 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5302 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5303 | |
| 5304 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5305 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5306 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5307 | trans.reset(); |
| 5308 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5309 | auto trans2 = |
| 5310 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5311 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5312 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5313 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5314 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5315 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5316 | |
| 5317 | LoadTimingInfo load_timing_info2; |
| 5318 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 5319 | TestLoadTimingReused(load_timing_info2); |
| 5320 | |
| 5321 | // The requests should have the same ID. |
| 5322 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5323 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5324 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5325 | } |
| 5326 | |
| 5327 | // Test load timing in the case of of two HTTP requests through a SPDY HTTPS |
| 5328 | // Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5329 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyLoadTimingTwoHttpRequests) { |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5330 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5331 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5332 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5333 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5334 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5335 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5336 | |
| 5337 | HttpRequestInfo request1; |
| 5338 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5339 | request1.url = GURL("http://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5340 | request1.load_flags = 0; |
| 5341 | |
| 5342 | HttpRequestInfo request2; |
| 5343 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5344 | request2.url = GURL("http://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5345 | request2.load_flags = 0; |
| 5346 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5347 | // http://www.example.org/ |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 5348 | SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5349 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5350 | SpdySerializedFrame get1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5351 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
| 5352 | SpdySerializedFrame get_resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5353 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, "1", 1, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5354 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5355 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5356 | // http://mail.example.org/ |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 5357 | SpdyHeaderBlock headers2( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5358 | spdy_util_.ConstructGetHeaderBlockForProxy("http://mail.example.org/")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5359 | SpdySerializedFrame get2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5360 | spdy_util_.ConstructSpdyHeaders(3, std::move(headers2), LOWEST, true)); |
| 5361 | SpdySerializedFrame get_resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5362 | SpdySerializedFrame body2( |
| 5363 | spdy_util_.ConstructSpdyDataFrame(3, "22", 2, true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5364 | |
| 5365 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5366 | CreateMockWrite(get1, 0), CreateMockWrite(get2, 3), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5367 | }; |
| 5368 | |
| 5369 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5370 | CreateMockRead(get_resp1, 1, ASYNC), |
| 5371 | CreateMockRead(body1, 2, ASYNC), |
| 5372 | CreateMockRead(get_resp2, 4, ASYNC), |
| 5373 | CreateMockRead(body2, 5, ASYNC), |
| 5374 | MockRead(ASYNC, 0, 6), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5375 | }; |
| 5376 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5377 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5378 | arraysize(spdy_writes)); |
| 5379 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5380 | |
| 5381 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5382 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5383 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5384 | |
| 5385 | TestCompletionCallback callback; |
| 5386 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5387 | auto trans = |
| 5388 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5389 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5390 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5391 | |
| 5392 | LoadTimingInfo load_timing_info; |
| 5393 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5394 | TestLoadTimingNotReused(load_timing_info, |
| 5395 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5396 | |
| 5397 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5398 | ASSERT_TRUE(response); |
| 5399 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5400 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5401 | |
| 5402 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5403 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5404 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 5405 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5406 | // Delete the first request, so the second one can reuse the socket. |
| 5407 | trans.reset(); |
| 5408 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5409 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5410 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5411 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5412 | |
| 5413 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5414 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5415 | TestLoadTimingReused(load_timing_info2); |
| 5416 | |
| 5417 | // The requests should have the same ID. |
| 5418 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5419 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5420 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5421 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5422 | } |
| 5423 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5424 | // Test the challenge-response-retry sequence through an HTTPS Proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5425 | TEST_F(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5426 | HttpRequestInfo request; |
| 5427 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5428 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5429 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5430 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5431 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5432 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5433 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5434 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5435 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5436 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5437 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5438 | // Since we have proxy, should use full url |
| 5439 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5440 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 5441 | "Host: www.example.org\r\n" |
| 5442 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5443 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5444 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5445 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5446 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 5447 | "Host: www.example.org\r\n" |
| 5448 | "Proxy-Connection: keep-alive\r\n" |
| 5449 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5450 | }; |
| 5451 | |
| 5452 | // The proxy responds to the GET with a 407, using a persistent |
| 5453 | // connection. |
| 5454 | MockRead data_reads1[] = { |
| 5455 | // No credentials. |
| 5456 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 5457 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5458 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 5459 | MockRead("Content-Length: 0\r\n\r\n"), |
| 5460 | |
| 5461 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5462 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5463 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5464 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5465 | }; |
| 5466 | |
| 5467 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5468 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5469 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5470 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5471 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5472 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5473 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5474 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5475 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5476 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5477 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5478 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5479 | |
| 5480 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5481 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5482 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5483 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5484 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5485 | TestLoadTimingNotReused(load_timing_info, |
| 5486 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5487 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5488 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5489 | ASSERT_TRUE(response); |
| 5490 | ASSERT_TRUE(response->headers); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5491 | EXPECT_EQ(407, response->headers->response_code()); |
| 5492 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 5493 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5494 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5495 | TestCompletionCallback callback2; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5496 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5497 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5498 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5499 | |
| 5500 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5501 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5502 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5503 | load_timing_info = LoadTimingInfo(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5504 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5505 | // Retrying with HTTP AUTH is considered to be reusing a socket. |
| 5506 | TestLoadTimingReused(load_timing_info); |
| 5507 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5508 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5509 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5510 | |
| 5511 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 5512 | EXPECT_EQ(200, response->headers->response_code()); |
| 5513 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5514 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5515 | |
| 5516 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5517 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5518 | } |
| 5519 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5520 | void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5521 | const MockRead& status, int expected_status) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5522 | HttpRequestInfo request; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5523 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5524 | request.url = GURL("https://www.example.org/"); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5525 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5526 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5527 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5528 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5529 | |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5530 | // Since we have proxy, should try to establish tunnel. |
| 5531 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5532 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5533 | "Host: www.example.org:443\r\n" |
| 5534 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5535 | }; |
| 5536 | |
| 5537 | MockRead data_reads[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 5538 | status, MockRead("Content-Length: 10\r\n\r\n"), |
| 5539 | // No response body because the test stops reading here. |
| 5540 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5541 | }; |
| 5542 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5543 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 5544 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5545 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5546 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5547 | TestCompletionCallback callback; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5548 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5549 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5550 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5551 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5552 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5553 | |
| 5554 | rv = callback.WaitForResult(); |
| 5555 | EXPECT_EQ(expected_status, rv); |
| 5556 | } |
| 5557 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5558 | void HttpNetworkTransactionTest::ConnectStatusHelper( |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5559 | const MockRead& status) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5560 | ConnectStatusHelperWithExpectedStatus( |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5561 | status, ERR_TUNNEL_CONNECTION_FAILED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5562 | } |
| 5563 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5564 | TEST_F(HttpNetworkTransactionTest, ConnectStatus100) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5565 | ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n")); |
| 5566 | } |
| 5567 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5568 | TEST_F(HttpNetworkTransactionTest, ConnectStatus101) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5569 | ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n")); |
| 5570 | } |
| 5571 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5572 | TEST_F(HttpNetworkTransactionTest, ConnectStatus201) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5573 | ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n")); |
| 5574 | } |
| 5575 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5576 | TEST_F(HttpNetworkTransactionTest, ConnectStatus202) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5577 | ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n")); |
| 5578 | } |
| 5579 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5580 | TEST_F(HttpNetworkTransactionTest, ConnectStatus203) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5581 | ConnectStatusHelper( |
| 5582 | MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n")); |
| 5583 | } |
| 5584 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5585 | TEST_F(HttpNetworkTransactionTest, ConnectStatus204) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5586 | ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n")); |
| 5587 | } |
| 5588 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5589 | TEST_F(HttpNetworkTransactionTest, ConnectStatus205) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5590 | ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n")); |
| 5591 | } |
| 5592 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5593 | TEST_F(HttpNetworkTransactionTest, ConnectStatus206) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5594 | ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n")); |
| 5595 | } |
| 5596 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5597 | TEST_F(HttpNetworkTransactionTest, ConnectStatus300) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5598 | ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n")); |
| 5599 | } |
| 5600 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5601 | TEST_F(HttpNetworkTransactionTest, ConnectStatus301) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5602 | ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n")); |
| 5603 | } |
| 5604 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5605 | TEST_F(HttpNetworkTransactionTest, ConnectStatus302) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5606 | ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n")); |
| 5607 | } |
| 5608 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5609 | TEST_F(HttpNetworkTransactionTest, ConnectStatus303) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5610 | ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n")); |
| 5611 | } |
| 5612 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5613 | TEST_F(HttpNetworkTransactionTest, ConnectStatus304) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5614 | ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n")); |
| 5615 | } |
| 5616 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5617 | TEST_F(HttpNetworkTransactionTest, ConnectStatus305) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5618 | ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n")); |
| 5619 | } |
| 5620 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5621 | TEST_F(HttpNetworkTransactionTest, ConnectStatus306) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5622 | ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n")); |
| 5623 | } |
| 5624 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5625 | TEST_F(HttpNetworkTransactionTest, ConnectStatus307) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5626 | ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n")); |
| 5627 | } |
| 5628 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5629 | TEST_F(HttpNetworkTransactionTest, ConnectStatus308) { |
[email protected] | 0a17aab3 | 2014-04-24 03:32:37 | [diff] [blame] | 5630 | ConnectStatusHelper(MockRead("HTTP/1.1 308 Permanent Redirect\r\n")); |
| 5631 | } |
| 5632 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5633 | TEST_F(HttpNetworkTransactionTest, ConnectStatus400) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5634 | ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n")); |
| 5635 | } |
| 5636 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5637 | TEST_F(HttpNetworkTransactionTest, ConnectStatus401) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5638 | ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n")); |
| 5639 | } |
| 5640 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5641 | TEST_F(HttpNetworkTransactionTest, ConnectStatus402) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5642 | ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n")); |
| 5643 | } |
| 5644 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5645 | TEST_F(HttpNetworkTransactionTest, ConnectStatus403) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5646 | ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n")); |
| 5647 | } |
| 5648 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5649 | TEST_F(HttpNetworkTransactionTest, ConnectStatus404) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5650 | ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n")); |
| 5651 | } |
| 5652 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5653 | TEST_F(HttpNetworkTransactionTest, ConnectStatus405) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5654 | ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n")); |
| 5655 | } |
| 5656 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5657 | TEST_F(HttpNetworkTransactionTest, ConnectStatus406) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5658 | ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n")); |
| 5659 | } |
| 5660 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5661 | TEST_F(HttpNetworkTransactionTest, ConnectStatus407) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5662 | ConnectStatusHelperWithExpectedStatus( |
| 5663 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
[email protected] | a7ea883 | 2010-07-12 17:54:54 | [diff] [blame] | 5664 | ERR_PROXY_AUTH_UNSUPPORTED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5665 | } |
| 5666 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5667 | TEST_F(HttpNetworkTransactionTest, ConnectStatus408) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5668 | ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n")); |
| 5669 | } |
| 5670 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5671 | TEST_F(HttpNetworkTransactionTest, ConnectStatus409) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5672 | ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n")); |
| 5673 | } |
| 5674 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5675 | TEST_F(HttpNetworkTransactionTest, ConnectStatus410) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5676 | ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n")); |
| 5677 | } |
| 5678 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5679 | TEST_F(HttpNetworkTransactionTest, ConnectStatus411) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5680 | ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n")); |
| 5681 | } |
| 5682 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5683 | TEST_F(HttpNetworkTransactionTest, ConnectStatus412) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5684 | ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n")); |
| 5685 | } |
| 5686 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5687 | TEST_F(HttpNetworkTransactionTest, ConnectStatus413) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5688 | ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n")); |
| 5689 | } |
| 5690 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5691 | TEST_F(HttpNetworkTransactionTest, ConnectStatus414) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5692 | ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n")); |
| 5693 | } |
| 5694 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5695 | TEST_F(HttpNetworkTransactionTest, ConnectStatus415) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5696 | ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n")); |
| 5697 | } |
| 5698 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5699 | TEST_F(HttpNetworkTransactionTest, ConnectStatus416) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5700 | ConnectStatusHelper( |
| 5701 | MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n")); |
| 5702 | } |
| 5703 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5704 | TEST_F(HttpNetworkTransactionTest, ConnectStatus417) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5705 | ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n")); |
| 5706 | } |
| 5707 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5708 | TEST_F(HttpNetworkTransactionTest, ConnectStatus500) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5709 | ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n")); |
| 5710 | } |
| 5711 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5712 | TEST_F(HttpNetworkTransactionTest, ConnectStatus501) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5713 | ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n")); |
| 5714 | } |
| 5715 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5716 | TEST_F(HttpNetworkTransactionTest, ConnectStatus502) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5717 | ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n")); |
| 5718 | } |
| 5719 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5720 | TEST_F(HttpNetworkTransactionTest, ConnectStatus503) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5721 | ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n")); |
| 5722 | } |
| 5723 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5724 | TEST_F(HttpNetworkTransactionTest, ConnectStatus504) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5725 | ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n")); |
| 5726 | } |
| 5727 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5728 | TEST_F(HttpNetworkTransactionTest, ConnectStatus505) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5729 | ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); |
| 5730 | } |
| 5731 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5732 | // Test the flow when both the proxy server AND origin server require |
| 5733 | // authentication. Again, this uses basic auth for both since that is |
| 5734 | // the simplest to mock. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5735 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5736 | HttpRequestInfo request; |
| 5737 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5738 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5739 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5740 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5741 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5742 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 5743 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5744 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5745 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5746 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5747 | MockWrite( |
| 5748 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5749 | "Host: www.example.org\r\n" |
| 5750 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5751 | }; |
| 5752 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5753 | MockRead data_reads1[] = { |
| 5754 | MockRead("HTTP/1.0 407 Unauthorized\r\n"), |
| 5755 | // Give a couple authenticate options (only the middle one is actually |
| 5756 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 5757 | MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5758 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5759 | MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 5760 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5761 | // Large content-length -- won't matter, as connection will be reset. |
| 5762 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5763 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5764 | }; |
| 5765 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5766 | // After calling trans.RestartWithAuth() the first time, this is the |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5767 | // request we should be issuing -- the final header line contains the |
| 5768 | // proxy's credentials. |
| 5769 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5770 | MockWrite( |
| 5771 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5772 | "Host: www.example.org\r\n" |
| 5773 | "Proxy-Connection: keep-alive\r\n" |
| 5774 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5775 | }; |
| 5776 | |
| 5777 | // Now the proxy server lets the request pass through to origin server. |
| 5778 | // The origin server responds with a 401. |
| 5779 | MockRead data_reads2[] = { |
| 5780 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5781 | // Note: We are using the same realm-name as the proxy server. This is |
| 5782 | // completely valid, as realms are unique across hosts. |
| 5783 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5784 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5785 | MockRead("Content-Length: 2000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5786 | MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5787 | }; |
| 5788 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5789 | // After calling trans.RestartWithAuth() the second time, we should send |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5790 | // the credentials for both the proxy and origin server. |
| 5791 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5792 | MockWrite( |
| 5793 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5794 | "Host: www.example.org\r\n" |
| 5795 | "Proxy-Connection: keep-alive\r\n" |
| 5796 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 5797 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5798 | }; |
| 5799 | |
| 5800 | // Lastly we get the desired content. |
| 5801 | MockRead data_reads3[] = { |
| 5802 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5803 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5804 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5805 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5806 | }; |
| 5807 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5808 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5809 | data_writes1, arraysize(data_writes1)); |
| 5810 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5811 | data_writes2, arraysize(data_writes2)); |
| 5812 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 5813 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5814 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5815 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 5816 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5817 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5818 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5819 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5820 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5821 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5822 | |
| 5823 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5824 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5825 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5826 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5827 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5828 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5829 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5830 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5831 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5832 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5833 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5834 | |
| 5835 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5836 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5837 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5838 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5839 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5840 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5841 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5842 | TestCompletionCallback callback3; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5843 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5844 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 5845 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5846 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5847 | |
| 5848 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5849 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5850 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5851 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5852 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5853 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5854 | } |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5855 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 5856 | // For the NTLM implementation using SSPI, we skip the NTLM tests since we |
| 5857 | // can't hook into its internals to cause it to generate predictable NTLM |
| 5858 | // authorization headers. |
| 5859 | #if defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5860 | // The NTLM authentication unit tests were generated by capturing the HTTP |
| 5861 | // requests and responses using Fiddler 2 and inspecting the generated random |
| 5862 | // bytes in the debugger. |
| 5863 | |
| 5864 | // Enter the correct password and authenticate successfully. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5865 | TEST_F(HttpNetworkTransactionTest, NTLMAuth1) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5866 | HttpRequestInfo request; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5867 | request.method = "GET"; |
| 5868 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5869 | |
| 5870 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 5871 | // to other auth schemes. |
| 5872 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5873 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5874 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom1, |
| 5875 | MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5876 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5877 | |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5878 | MockWrite data_writes1[] = { |
| 5879 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5880 | "Host: 172.22.68.17\r\n" |
| 5881 | "Connection: keep-alive\r\n\r\n"), |
| 5882 | }; |
| 5883 | |
| 5884 | MockRead data_reads1[] = { |
| 5885 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 5886 | // Negotiate and NTLM are often requested together. However, we only want |
| 5887 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 5888 | // the header that requests Negotiate for this test. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5889 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 5890 | MockRead("Connection: close\r\n"), |
| 5891 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5892 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5893 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5894 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5895 | }; |
| 5896 | |
| 5897 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5898 | // After restarting with a null identity, this is the |
| 5899 | // request we should be issuing -- the final header line contains a Type |
| 5900 | // 1 message. |
| 5901 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5902 | "Host: 172.22.68.17\r\n" |
| 5903 | "Connection: keep-alive\r\n" |
| 5904 | "Authorization: NTLM " |
| 5905 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5906 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5907 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 5908 | // (the credentials for the origin server). The second request continues |
| 5909 | // on the same connection. |
| 5910 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5911 | "Host: 172.22.68.17\r\n" |
| 5912 | "Connection: keep-alive\r\n" |
| 5913 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 5914 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 5915 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBVKW" |
| 5916 | "Yma5xzVAAAAAAAAAAAAAAAAAAAAACH+gWcm+YsP9Tqb9zCR3WAeZZX" |
| 5917 | "ahlhx5I=\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5918 | }; |
| 5919 | |
| 5920 | MockRead data_reads2[] = { |
| 5921 | // The origin server responds with a Type 2 message. |
| 5922 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 5923 | MockRead("WWW-Authenticate: NTLM " |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5924 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCjGpMpPGlYKkAAAAAAAAAALo" |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5925 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 5926 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 5927 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 5928 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 5929 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 5930 | "BtAAAAAAA=\r\n"), |
| 5931 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5932 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5933 | MockRead("You are not authorized to view this page\r\n"), |
| 5934 | |
| 5935 | // Lastly we get the desired content. |
| 5936 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5937 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 5938 | MockRead("Content-Length: 13\r\n\r\n"), |
| 5939 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5940 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5941 | }; |
| 5942 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5943 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5944 | data_writes1, arraysize(data_writes1)); |
| 5945 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5946 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5947 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5948 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5949 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5950 | TestCompletionCallback callback1; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5951 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5952 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5953 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5954 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5955 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5956 | |
| 5957 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5958 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5959 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5960 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5961 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5962 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5963 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5964 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5965 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5966 | TestCompletionCallback callback2; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5967 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5968 | rv = trans.RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
| 5969 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5970 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5971 | |
| 5972 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5973 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5974 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5975 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5976 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5977 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5978 | ASSERT_TRUE(response); |
| 5979 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 5980 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5981 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5982 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5983 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5984 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5985 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 5986 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5987 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5988 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5989 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5990 | ASSERT_TRUE(response); |
| 5991 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5992 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 5993 | } |
| 5994 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5995 | // Enter a wrong password, and then the correct one. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5996 | TEST_F(HttpNetworkTransactionTest, NTLMAuth2) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5997 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5998 | request.method = "GET"; |
| 5999 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6000 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6001 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom2, |
| 6002 | MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6003 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6004 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6005 | MockWrite data_writes1[] = { |
| 6006 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6007 | "Host: 172.22.68.17\r\n" |
| 6008 | "Connection: keep-alive\r\n\r\n"), |
| 6009 | }; |
| 6010 | |
| 6011 | MockRead data_reads1[] = { |
| 6012 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 6013 | // Negotiate and NTLM are often requested together. However, we only want |
| 6014 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 6015 | // the header that requests Negotiate for this test. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6016 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 6017 | MockRead("Connection: close\r\n"), |
| 6018 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6019 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6020 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6021 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6022 | }; |
| 6023 | |
| 6024 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6025 | // After restarting with a null identity, this is the |
| 6026 | // request we should be issuing -- the final header line contains a Type |
| 6027 | // 1 message. |
| 6028 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6029 | "Host: 172.22.68.17\r\n" |
| 6030 | "Connection: keep-alive\r\n" |
| 6031 | "Authorization: NTLM " |
| 6032 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6033 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6034 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 6035 | // (the credentials for the origin server). The second request continues |
| 6036 | // on the same connection. |
| 6037 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6038 | "Host: 172.22.68.17\r\n" |
| 6039 | "Connection: keep-alive\r\n" |
| 6040 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 6041 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 6042 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwCWeY" |
| 6043 | "XnSZNwoQAAAAAAAAAAAAAAAAAAAADLa34/phTTKzNTWdub+uyFleOj" |
| 6044 | "4Ww7b7E=\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6045 | }; |
| 6046 | |
| 6047 | MockRead data_reads2[] = { |
| 6048 | // The origin server responds with a Type 2 message. |
| 6049 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 6050 | MockRead("WWW-Authenticate: NTLM " |
| 6051 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCbVWUZezVGpAAAAAAAAAAALo" |
| 6052 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 6053 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 6054 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 6055 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 6056 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 6057 | "BtAAAAAAA=\r\n"), |
| 6058 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6059 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6060 | MockRead("You are not authorized to view this page\r\n"), |
| 6061 | |
| 6062 | // Wrong password. |
| 6063 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6064 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 6065 | MockRead("Connection: close\r\n"), |
| 6066 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6067 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6068 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6069 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6070 | }; |
| 6071 | |
| 6072 | MockWrite data_writes3[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6073 | // After restarting with a null identity, this is the |
| 6074 | // request we should be issuing -- the final header line contains a Type |
| 6075 | // 1 message. |
| 6076 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6077 | "Host: 172.22.68.17\r\n" |
| 6078 | "Connection: keep-alive\r\n" |
| 6079 | "Authorization: NTLM " |
| 6080 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6081 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6082 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 6083 | // (the credentials for the origin server). The second request continues |
| 6084 | // on the same connection. |
| 6085 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6086 | "Host: 172.22.68.17\r\n" |
| 6087 | "Connection: keep-alive\r\n" |
| 6088 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 6089 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 6090 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBO54" |
| 6091 | "dFMVvTHwAAAAAAAAAAAAAAAAAAAACS7sT6Uzw7L0L//WUqlIaVWpbI" |
| 6092 | "+4MUm7c=\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6093 | }; |
| 6094 | |
| 6095 | MockRead data_reads3[] = { |
| 6096 | // The origin server responds with a Type 2 message. |
| 6097 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 6098 | MockRead("WWW-Authenticate: NTLM " |
| 6099 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCL24VN8dgOR8AAAAAAAAAALo" |
| 6100 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 6101 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 6102 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 6103 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 6104 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 6105 | "BtAAAAAAA=\r\n"), |
| 6106 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6107 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6108 | MockRead("You are not authorized to view this page\r\n"), |
| 6109 | |
| 6110 | // Lastly we get the desired content. |
| 6111 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6112 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 6113 | MockRead("Content-Length: 13\r\n\r\n"), |
| 6114 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6115 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6116 | }; |
| 6117 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6118 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6119 | data_writes1, arraysize(data_writes1)); |
| 6120 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6121 | data_writes2, arraysize(data_writes2)); |
| 6122 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6123 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6124 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6125 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6126 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6127 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6128 | TestCompletionCallback callback1; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6129 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6130 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6131 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6132 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6133 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6134 | |
| 6135 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6136 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6137 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6138 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6139 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6140 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6141 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6142 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6143 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6144 | TestCompletionCallback callback2; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6145 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6146 | // Enter the wrong password. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6147 | rv = trans.RestartWithAuth(AuthCredentials(kTestingNTLM, kWrongPassword), |
| 6148 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6149 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6150 | |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6151 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6152 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6153 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6154 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6155 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6156 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6157 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6158 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6159 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6160 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6161 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6162 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6163 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6164 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6165 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6166 | TestCompletionCallback callback4; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6167 | |
| 6168 | // Now enter the right password. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6169 | rv = trans.RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
| 6170 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6171 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6172 | |
| 6173 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6174 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6175 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6176 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6177 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6178 | TestCompletionCallback callback5; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6179 | |
| 6180 | // One more roundtrip |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6181 | rv = trans.RestartWithAuth(AuthCredentials(), callback5.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6182 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6183 | |
| 6184 | rv = callback5.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6185 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6186 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6187 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6188 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6189 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 6190 | } |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6191 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6192 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6193 | // Test reading a server response which has only headers, and no body. |
| 6194 | // After some maximum number of bytes is consumed, the transaction should |
| 6195 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6196 | TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6197 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6198 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6199 | request.url = GURL("http://www.example.org/"); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6200 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6201 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6202 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6203 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 6204 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 6205 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 6206 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6207 | |
| 6208 | MockRead data_reads[] = { |
| 6209 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6210 | MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6211 | MockRead("\r\nBODY"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6212 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6213 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6214 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6215 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6216 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6217 | TestCompletionCallback callback; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6218 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6219 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6220 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6221 | |
| 6222 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6223 | EXPECT_THAT(rv, IsError(ERR_RESPONSE_HEADERS_TOO_BIG)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6224 | } |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6225 | |
| 6226 | // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 6227 | // establish tunnel. |
| 6228 | // http://code.google.com/p/chromium/issues/detail?id=3772 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6229 | TEST_F(HttpNetworkTransactionTest, DontRecycleTransportSocketForSSLTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6230 | HttpRequestInfo request; |
| 6231 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6232 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6233 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6234 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 6235 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 6236 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6237 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6238 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6239 | auto trans = |
| 6240 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6241 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6242 | // Since we have proxy, should try to establish tunnel. |
| 6243 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 6244 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6245 | "Host: www.example.org:443\r\n" |
| 6246 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6247 | }; |
| 6248 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 6249 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6250 | // connection. Usually a proxy would return 501 (not implemented), |
| 6251 | // or 200 (tunnel established). |
| 6252 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 6253 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 6254 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6255 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6256 | }; |
| 6257 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6258 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6259 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6260 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6261 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6262 | TestCompletionCallback callback1; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6263 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6264 | int rv = trans->Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6265 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6266 | |
| 6267 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6268 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6269 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6270 | // Empty the current queue. This is necessary because idle sockets are |
| 6271 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6272 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6273 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6274 | // We now check to make sure the TCPClientSocket was not added back to |
| 6275 | // the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6276 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6277 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6278 | base::RunLoop().RunUntilIdle(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6279 | // Make sure that the socket didn't get recycled after calling the destructor. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6280 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6281 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6282 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6283 | // Make sure that we recycle a socket after reading all of the response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6284 | TEST_F(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6285 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6286 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6287 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6288 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6289 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6290 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6291 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6292 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6293 | MockRead data_reads[] = { |
| 6294 | // A part of the response body is received with the response headers. |
| 6295 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 6296 | // The rest of the response body is received in two parts. |
| 6297 | MockRead("lo"), |
| 6298 | MockRead(" world"), |
| 6299 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6300 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6301 | }; |
| 6302 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6303 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6304 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6305 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6306 | TestCompletionCallback callback; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6307 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6308 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6309 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6310 | |
| 6311 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6312 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6313 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6314 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6315 | ASSERT_TRUE(response); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6316 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6317 | EXPECT_TRUE(response->headers); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6318 | std::string status_line = response->headers->GetStatusLine(); |
| 6319 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 6320 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6321 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6322 | |
| 6323 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6324 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6325 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6326 | EXPECT_EQ("hello world", response_data); |
| 6327 | |
| 6328 | // Empty the current queue. This is necessary because idle sockets are |
| 6329 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6330 | base::RunLoop().RunUntilIdle(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6331 | |
| 6332 | // 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] | 6333 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6334 | } |
| 6335 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6336 | // Make sure that we recycle a SSL socket after reading all of the response |
| 6337 | // body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6338 | TEST_F(HttpNetworkTransactionTest, RecycleSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6339 | HttpRequestInfo request; |
| 6340 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6341 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6342 | |
| 6343 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6344 | MockWrite( |
| 6345 | "GET / HTTP/1.1\r\n" |
| 6346 | "Host: www.example.org\r\n" |
| 6347 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6348 | }; |
| 6349 | |
| 6350 | MockRead data_reads[] = { |
| 6351 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6352 | MockRead("Content-Length: 11\r\n\r\n"), |
| 6353 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6354 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6355 | }; |
| 6356 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6357 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6358 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6359 | |
| 6360 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6361 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6362 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6363 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6364 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6365 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6366 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6367 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6368 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6369 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6370 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6371 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6372 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6373 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6374 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6375 | ASSERT_TRUE(response); |
| 6376 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6377 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6378 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6379 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6380 | |
| 6381 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6382 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6383 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6384 | EXPECT_EQ("hello world", response_data); |
| 6385 | |
| 6386 | // Empty the current queue. This is necessary because idle sockets are |
| 6387 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6388 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6389 | |
| 6390 | // 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] | 6391 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6392 | } |
| 6393 | |
| 6394 | // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it |
| 6395 | // from the pool and make sure that we recover okay. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6396 | TEST_F(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6397 | HttpRequestInfo request; |
| 6398 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6399 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6400 | |
| 6401 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6402 | MockWrite( |
| 6403 | "GET / HTTP/1.1\r\n" |
| 6404 | "Host: www.example.org\r\n" |
| 6405 | "Connection: keep-alive\r\n\r\n"), |
| 6406 | MockWrite( |
| 6407 | "GET / HTTP/1.1\r\n" |
| 6408 | "Host: www.example.org\r\n" |
| 6409 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6410 | }; |
| 6411 | |
| 6412 | MockRead data_reads[] = { |
mmenke | 911ee022 | 2015-12-04 03:58:42 | [diff] [blame] | 6413 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 6414 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6415 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6416 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6417 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6418 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6419 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6420 | |
| 6421 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6422 | data_writes, arraysize(data_writes)); |
| 6423 | StaticSocketDataProvider data2(data_reads, arraysize(data_reads), |
| 6424 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6425 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6426 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6427 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6428 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6429 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6430 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6431 | auto trans = |
| 6432 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6433 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6434 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6435 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6436 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6437 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6438 | |
| 6439 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6440 | ASSERT_TRUE(response); |
| 6441 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6442 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6443 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6444 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6445 | |
| 6446 | std::string response_data; |
| 6447 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6448 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6449 | EXPECT_EQ("hello world", response_data); |
| 6450 | |
| 6451 | // Empty the current queue. This is necessary because idle sockets are |
| 6452 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6453 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6454 | |
| 6455 | // 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] | 6456 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6457 | |
| 6458 | // Now start the second transaction, which should reuse the previous socket. |
| 6459 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6460 | trans = |
| 6461 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6462 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6463 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6464 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6465 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6466 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6467 | |
| 6468 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6469 | ASSERT_TRUE(response); |
| 6470 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6471 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6472 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6473 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6474 | |
| 6475 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6476 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6477 | EXPECT_EQ("hello world", response_data); |
| 6478 | |
| 6479 | // Empty the current queue. This is necessary because idle sockets are |
| 6480 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6481 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6482 | |
| 6483 | // 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] | 6484 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6485 | } |
| 6486 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6487 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 6488 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6489 | TEST_F(HttpNetworkTransactionTest, FlushSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6490 | HttpRequestInfo request; |
| 6491 | request.method = "GET"; |
| 6492 | request.url = GURL("http://www.example.org/"); |
| 6493 | request.load_flags = 0; |
| 6494 | |
| 6495 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6496 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6497 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6498 | |
| 6499 | MockRead data_reads[] = { |
| 6500 | // A part of the response body is received with the response headers. |
| 6501 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 6502 | // The rest of the response body is received in two parts. |
| 6503 | MockRead("lo"), MockRead(" world"), |
| 6504 | MockRead("junk"), // Should not be read!! |
| 6505 | MockRead(SYNCHRONOUS, OK), |
| 6506 | }; |
| 6507 | |
| 6508 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 6509 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6510 | |
| 6511 | TestCompletionCallback callback; |
| 6512 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6513 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6514 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6515 | |
| 6516 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6517 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6518 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6519 | ASSERT_TRUE(response); |
| 6520 | EXPECT_TRUE(response->headers); |
| 6521 | std::string status_line = response->headers->GetStatusLine(); |
| 6522 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 6523 | |
| 6524 | // Make memory critical notification and ensure the transaction still has been |
| 6525 | // operating right. |
| 6526 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 6527 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 6528 | base::RunLoop().RunUntilIdle(); |
| 6529 | |
| 6530 | // Socket should not be flushed as long as it is not idle. |
| 6531 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 6532 | |
| 6533 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6534 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6535 | EXPECT_THAT(rv, IsOk()); |
| 6536 | EXPECT_EQ("hello world", response_data); |
| 6537 | |
| 6538 | // Empty the current queue. This is necessary because idle sockets are |
| 6539 | // added to the connection pool asynchronously with a PostTask. |
| 6540 | base::RunLoop().RunUntilIdle(); |
| 6541 | |
| 6542 | // We now check to make sure the socket was added back to the pool. |
| 6543 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 6544 | |
| 6545 | // Idle sockets should be flushed now. |
| 6546 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 6547 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 6548 | base::RunLoop().RunUntilIdle(); |
| 6549 | |
| 6550 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 6551 | } |
| 6552 | |
| 6553 | // Grab an SSL socket, use it, and put it back into the pool. Then, make |
| 6554 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6555 | TEST_F(HttpNetworkTransactionTest, FlushSSLSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6556 | HttpRequestInfo request; |
| 6557 | request.method = "GET"; |
| 6558 | request.url = GURL("https://www.example.org/"); |
| 6559 | request.load_flags = 0; |
| 6560 | |
| 6561 | MockWrite data_writes[] = { |
| 6562 | MockWrite("GET / HTTP/1.1\r\n" |
| 6563 | "Host: www.example.org\r\n" |
| 6564 | "Connection: keep-alive\r\n\r\n"), |
| 6565 | }; |
| 6566 | |
| 6567 | MockRead data_reads[] = { |
| 6568 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 6569 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
| 6570 | |
| 6571 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6572 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6573 | |
| 6574 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 6575 | arraysize(data_writes)); |
| 6576 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6577 | |
| 6578 | TestCompletionCallback callback; |
| 6579 | |
| 6580 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6581 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6582 | |
| 6583 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6584 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6585 | |
| 6586 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6587 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6588 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6589 | ASSERT_TRUE(response); |
| 6590 | ASSERT_TRUE(response->headers); |
| 6591 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6592 | |
| 6593 | // Make memory critical notification and ensure the transaction still has been |
| 6594 | // operating right. |
| 6595 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 6596 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 6597 | base::RunLoop().RunUntilIdle(); |
| 6598 | |
| 6599 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 6600 | |
| 6601 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6602 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6603 | EXPECT_THAT(rv, IsOk()); |
| 6604 | EXPECT_EQ("hello world", response_data); |
| 6605 | |
| 6606 | // Empty the current queue. This is necessary because idle sockets are |
| 6607 | // added to the connection pool asynchronously with a PostTask. |
| 6608 | base::RunLoop().RunUntilIdle(); |
| 6609 | |
| 6610 | // We now check to make sure the socket was added back to the pool. |
| 6611 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 6612 | |
| 6613 | // Make memory notification once again and ensure idle socket is closed. |
| 6614 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 6615 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 6616 | base::RunLoop().RunUntilIdle(); |
| 6617 | |
| 6618 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 6619 | } |
| 6620 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6621 | // Make sure that we recycle a socket after a zero-length response. |
| 6622 | // http://crbug.com/9880 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6623 | TEST_F(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6624 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6625 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6626 | request.url = GURL( |
| 6627 | "http://www.example.org/csi?v=3&s=web&action=&" |
| 6628 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 6629 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 6630 | "rt=prt.2642,ol.2649,xjs.2951"); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6631 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6632 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6633 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6634 | MockRead data_reads[] = { |
| 6635 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 6636 | "Content-Length: 0\r\n" |
| 6637 | "Content-Type: text/html\r\n\r\n"), |
| 6638 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6639 | MockRead(SYNCHRONOUS, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6640 | }; |
| 6641 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6642 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6643 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6644 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 6645 | // Transaction must be created after the MockReads, so it's destroyed before |
| 6646 | // them. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6647 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 6648 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6649 | TestCompletionCallback callback; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6650 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6651 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6652 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6653 | |
| 6654 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6655 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6656 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6657 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6658 | ASSERT_TRUE(response); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6659 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6660 | EXPECT_TRUE(response->headers); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6661 | std::string status_line = response->headers->GetStatusLine(); |
| 6662 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 6663 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6664 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6665 | |
| 6666 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6667 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6668 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6669 | EXPECT_EQ("", response_data); |
| 6670 | |
| 6671 | // Empty the current queue. This is necessary because idle sockets are |
| 6672 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6673 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6674 | |
| 6675 | // 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] | 6676 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6677 | } |
| 6678 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6679 | TEST_F(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6680 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 6681 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 6682 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 6683 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 6684 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6685 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6686 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 6687 | // after use. |
| 6688 | request[0].method = "GET"; |
| 6689 | request[0].url = GURL("http://www.google.com/"); |
| 6690 | request[0].load_flags = 0; |
| 6691 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 6692 | // transaction 1. The first attempts fails when writing the POST data. |
| 6693 | // This causes the transaction to retry with a new socket. The second |
| 6694 | // attempt succeeds. |
| 6695 | request[1].method = "POST"; |
| 6696 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 6697 | request[1].upload_data_stream = &upload_data_stream; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6698 | request[1].load_flags = 0; |
| 6699 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6700 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6701 | |
| 6702 | // The first socket is used for transaction 1 and the first attempt of |
| 6703 | // transaction 2. |
| 6704 | |
| 6705 | // The response of transaction 1. |
| 6706 | MockRead data_reads1[] = { |
| 6707 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 6708 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6709 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6710 | }; |
| 6711 | // The mock write results of transaction 1 and the first attempt of |
| 6712 | // transaction 2. |
| 6713 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6714 | MockWrite(SYNCHRONOUS, 64), // GET |
| 6715 | MockWrite(SYNCHRONOUS, 93), // POST |
| 6716 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6717 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6718 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6719 | data_writes1, arraysize(data_writes1)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6720 | |
| 6721 | // The second socket is used for the second attempt of transaction 2. |
| 6722 | |
| 6723 | // The response of transaction 2. |
| 6724 | MockRead data_reads2[] = { |
| 6725 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 6726 | MockRead("welcome"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6727 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6728 | }; |
| 6729 | // The mock write results of the second attempt of transaction 2. |
| 6730 | MockWrite data_writes2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6731 | MockWrite(SYNCHRONOUS, 93), // POST |
| 6732 | MockWrite(SYNCHRONOUS, 3), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6733 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6734 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6735 | data_writes2, arraysize(data_writes2)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6736 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6737 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6738 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6739 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 6740 | const char* const kExpectedResponseData[] = { |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6741 | "hello world", "welcome" |
| 6742 | }; |
| 6743 | |
| 6744 | for (int i = 0; i < 2; ++i) { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6745 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6746 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6747 | TestCompletionCallback callback; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6748 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6749 | int rv = trans.Start(&request[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6750 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6751 | |
| 6752 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6753 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6754 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6755 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6756 | ASSERT_TRUE(response); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6757 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6758 | EXPECT_TRUE(response->headers); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6759 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6760 | |
| 6761 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6762 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6763 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6764 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 6765 | } |
| 6766 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6767 | |
| 6768 | // Test the request-challenge-retry sequence for basic auth when there is |
| 6769 | // 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] | 6770 | // it fails the identity from the URL is used to answer the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6771 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6772 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6773 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6774 | request.url = GURL("http://foo:b@[email protected]/"); |
[email protected] | 7b08ba6 | 2012-02-10 20:19:41 | [diff] [blame] | 6775 | request.load_flags = LOAD_NORMAL; |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 6776 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6777 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6778 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6779 | |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 6780 | // The password contains an escaped character -- for this test to pass it |
| 6781 | // will need to be unescaped by HttpNetworkTransaction. |
| 6782 | EXPECT_EQ("b%40r", request.url.password()); |
| 6783 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6784 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6785 | MockWrite( |
| 6786 | "GET / HTTP/1.1\r\n" |
| 6787 | "Host: www.example.org\r\n" |
| 6788 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6789 | }; |
| 6790 | |
| 6791 | MockRead data_reads1[] = { |
| 6792 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6793 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6794 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6795 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6796 | }; |
| 6797 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6798 | // After the challenge above, the transaction will be restarted using the |
| 6799 | // identity from the url (foo, b@r) to answer the challenge. |
| 6800 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6801 | MockWrite( |
| 6802 | "GET / HTTP/1.1\r\n" |
| 6803 | "Host: www.example.org\r\n" |
| 6804 | "Connection: keep-alive\r\n" |
| 6805 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6806 | }; |
| 6807 | |
| 6808 | MockRead data_reads2[] = { |
| 6809 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6810 | MockRead("Content-Length: 100\r\n\r\n"), |
| 6811 | MockRead(SYNCHRONOUS, OK), |
| 6812 | }; |
| 6813 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6814 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6815 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6816 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6817 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6818 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6819 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6820 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6821 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6822 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6823 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6824 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6825 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6826 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6827 | |
| 6828 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6829 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6830 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6831 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6832 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6833 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6834 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6835 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6836 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6837 | |
| 6838 | // There is no challenge info, since the identity in URL worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6839 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6840 | |
| 6841 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6842 | |
| 6843 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6844 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6845 | } |
| 6846 | |
| 6847 | // Test the request-challenge-retry sequence for basic auth when there is an |
| 6848 | // incorrect identity in the URL. The identity from the URL should be used only |
| 6849 | // once. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6850 | TEST_F(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6851 | HttpRequestInfo request; |
| 6852 | request.method = "GET"; |
| 6853 | // Note: the URL has a username:password in it. The password "baz" is |
| 6854 | // wrong (should be "bar"). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6855 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6856 | |
| 6857 | request.load_flags = LOAD_NORMAL; |
| 6858 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6859 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6860 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6861 | |
| 6862 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6863 | MockWrite( |
| 6864 | "GET / HTTP/1.1\r\n" |
| 6865 | "Host: www.example.org\r\n" |
| 6866 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6867 | }; |
| 6868 | |
| 6869 | MockRead data_reads1[] = { |
| 6870 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6871 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6872 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6873 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 6874 | }; |
| 6875 | |
| 6876 | // After the challenge above, the transaction will be restarted using the |
| 6877 | // identity from the url (foo, baz) to answer the challenge. |
| 6878 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6879 | MockWrite( |
| 6880 | "GET / HTTP/1.1\r\n" |
| 6881 | "Host: www.example.org\r\n" |
| 6882 | "Connection: keep-alive\r\n" |
| 6883 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6884 | }; |
| 6885 | |
| 6886 | MockRead data_reads2[] = { |
| 6887 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6888 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6889 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6890 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 6891 | }; |
| 6892 | |
| 6893 | // After the challenge above, the transaction will be restarted using the |
| 6894 | // identity supplied by the user (foo, bar) to answer the challenge. |
| 6895 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6896 | MockWrite( |
| 6897 | "GET / HTTP/1.1\r\n" |
| 6898 | "Host: www.example.org\r\n" |
| 6899 | "Connection: keep-alive\r\n" |
| 6900 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6901 | }; |
| 6902 | |
| 6903 | MockRead data_reads3[] = { |
| 6904 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6905 | MockRead("Content-Length: 100\r\n\r\n"), |
| 6906 | MockRead(SYNCHRONOUS, OK), |
| 6907 | }; |
| 6908 | |
| 6909 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6910 | data_writes1, arraysize(data_writes1)); |
| 6911 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6912 | data_writes2, arraysize(data_writes2)); |
| 6913 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6914 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6915 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6916 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6917 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6918 | |
| 6919 | TestCompletionCallback callback1; |
| 6920 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6921 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6922 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6923 | |
| 6924 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6925 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6926 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6927 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6928 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6929 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6930 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6931 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6932 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6933 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6934 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6935 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6936 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6937 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 6938 | |
| 6939 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6940 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6941 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6942 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6943 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6944 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6945 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6946 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6947 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6948 | |
| 6949 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6950 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6951 | |
| 6952 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6953 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6954 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6955 | base::RunLoop().RunUntilIdle(); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6956 | } |
| 6957 | |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6958 | |
| 6959 | // Test the request-challenge-retry sequence for basic auth when there is a |
| 6960 | // correct identity in the URL, but its use is being suppressed. The identity |
| 6961 | // from the URL should never be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6962 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURLSuppressed) { |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6963 | HttpRequestInfo request; |
| 6964 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6965 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6966 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
| 6967 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6968 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6969 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6970 | |
| 6971 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6972 | MockWrite( |
| 6973 | "GET / HTTP/1.1\r\n" |
| 6974 | "Host: www.example.org\r\n" |
| 6975 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6976 | }; |
| 6977 | |
| 6978 | MockRead data_reads1[] = { |
| 6979 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6980 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6981 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6982 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 6983 | }; |
| 6984 | |
| 6985 | // After the challenge above, the transaction will be restarted using the |
| 6986 | // identity supplied by the user, not the one in the URL, to answer the |
| 6987 | // challenge. |
| 6988 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6989 | MockWrite( |
| 6990 | "GET / HTTP/1.1\r\n" |
| 6991 | "Host: www.example.org\r\n" |
| 6992 | "Connection: keep-alive\r\n" |
| 6993 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6994 | }; |
| 6995 | |
| 6996 | MockRead data_reads3[] = { |
| 6997 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6998 | MockRead("Content-Length: 100\r\n\r\n"), |
| 6999 | MockRead(SYNCHRONOUS, OK), |
| 7000 | }; |
| 7001 | |
| 7002 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7003 | data_writes1, arraysize(data_writes1)); |
| 7004 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 7005 | data_writes3, arraysize(data_writes3)); |
| 7006 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7007 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 7008 | |
| 7009 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7010 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7011 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7012 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7013 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7014 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7015 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7016 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7017 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7018 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 7019 | |
| 7020 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7021 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7022 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7023 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7024 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7025 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7026 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7027 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7028 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7029 | |
| 7030 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7031 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7032 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7033 | |
| 7034 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7035 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7036 | } |
| 7037 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7038 | // Test that previously tried username/passwords for a realm get re-used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7039 | TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7040 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7041 | |
| 7042 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 7043 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7044 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7045 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7046 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7047 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7048 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7049 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7050 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7051 | MockWrite( |
| 7052 | "GET /x/y/z HTTP/1.1\r\n" |
| 7053 | "Host: www.example.org\r\n" |
| 7054 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7055 | }; |
| 7056 | |
| 7057 | MockRead data_reads1[] = { |
| 7058 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7059 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7060 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7061 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7062 | }; |
| 7063 | |
| 7064 | // Resend with authorization (username=foo, password=bar) |
| 7065 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7066 | MockWrite( |
| 7067 | "GET /x/y/z HTTP/1.1\r\n" |
| 7068 | "Host: www.example.org\r\n" |
| 7069 | "Connection: keep-alive\r\n" |
| 7070 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7071 | }; |
| 7072 | |
| 7073 | // Sever accepts the authorization. |
| 7074 | MockRead data_reads2[] = { |
| 7075 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7076 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7077 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7078 | }; |
| 7079 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7080 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7081 | data_writes1, arraysize(data_writes1)); |
| 7082 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7083 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7084 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7085 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7086 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7087 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7088 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7089 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7090 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7091 | |
| 7092 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7093 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7094 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7095 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7096 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7097 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7098 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7099 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7100 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7101 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 7102 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7103 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7104 | |
| 7105 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7106 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7107 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7108 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7109 | ASSERT_TRUE(response); |
| 7110 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7111 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7112 | } |
| 7113 | |
| 7114 | // ------------------------------------------------------------------------ |
| 7115 | |
| 7116 | // Transaction 2: authenticate (foo2, bar2) on MyRealm2 |
| 7117 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7118 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7119 | request.method = "GET"; |
| 7120 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 7121 | // protection space as MyRealm1. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7122 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7123 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7124 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7125 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7126 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7127 | MockWrite( |
| 7128 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 7129 | "Host: www.example.org\r\n" |
| 7130 | "Connection: keep-alive\r\n" |
| 7131 | // Send preemptive authorization for MyRealm1 |
| 7132 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7133 | }; |
| 7134 | |
| 7135 | // The server didn't like the preemptive authorization, and |
| 7136 | // challenges us for a different realm (MyRealm2). |
| 7137 | MockRead data_reads1[] = { |
| 7138 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7139 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 7140 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7141 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7142 | }; |
| 7143 | |
| 7144 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 7145 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7146 | MockWrite( |
| 7147 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 7148 | "Host: www.example.org\r\n" |
| 7149 | "Connection: keep-alive\r\n" |
| 7150 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7151 | }; |
| 7152 | |
| 7153 | // Sever accepts the authorization. |
| 7154 | MockRead data_reads2[] = { |
| 7155 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7156 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7157 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7158 | }; |
| 7159 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7160 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7161 | data_writes1, arraysize(data_writes1)); |
| 7162 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7163 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7164 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7165 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7166 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7167 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7168 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7169 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7170 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7171 | |
| 7172 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7173 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7174 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7175 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7176 | ASSERT_TRUE(response); |
| 7177 | ASSERT_TRUE(response->auth_challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7178 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 7179 | EXPECT_EQ("http://www.example.org", |
| 7180 | response->auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7181 | EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 7182 | EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7183 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7184 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7185 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7186 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 7187 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7188 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7189 | |
| 7190 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7191 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7192 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7193 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7194 | ASSERT_TRUE(response); |
| 7195 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7196 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7197 | } |
| 7198 | |
| 7199 | // ------------------------------------------------------------------------ |
| 7200 | |
| 7201 | // Transaction 3: Resend a request in MyRealm's protection space -- |
| 7202 | // succeed with preemptive authorization. |
| 7203 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7204 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7205 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7206 | request.url = GURL("http://www.example.org/x/y/z2"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7207 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7208 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7209 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7210 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7211 | MockWrite( |
| 7212 | "GET /x/y/z2 HTTP/1.1\r\n" |
| 7213 | "Host: www.example.org\r\n" |
| 7214 | "Connection: keep-alive\r\n" |
| 7215 | // The authorization for MyRealm1 gets sent preemptively |
| 7216 | // (since the url is in the same protection space) |
| 7217 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7218 | }; |
| 7219 | |
| 7220 | // Sever accepts the preemptive authorization |
| 7221 | MockRead data_reads1[] = { |
| 7222 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7223 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7224 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7225 | }; |
| 7226 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7227 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7228 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7229 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7230 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7231 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7232 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7233 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7234 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7235 | |
| 7236 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7237 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7238 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7239 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7240 | ASSERT_TRUE(response); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7241 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7242 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7243 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7244 | } |
| 7245 | |
| 7246 | // ------------------------------------------------------------------------ |
| 7247 | |
| 7248 | // Transaction 4: request another URL in MyRealm (however the |
| 7249 | // url is not known to belong to the protection space, so no pre-auth). |
| 7250 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7251 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7252 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7253 | request.url = GURL("http://www.example.org/x/1"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7254 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7255 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7256 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7257 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7258 | MockWrite( |
| 7259 | "GET /x/1 HTTP/1.1\r\n" |
| 7260 | "Host: www.example.org\r\n" |
| 7261 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7262 | }; |
| 7263 | |
| 7264 | MockRead data_reads1[] = { |
| 7265 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7266 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7267 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7268 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7269 | }; |
| 7270 | |
| 7271 | // Resend with authorization from MyRealm's cache. |
| 7272 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7273 | MockWrite( |
| 7274 | "GET /x/1 HTTP/1.1\r\n" |
| 7275 | "Host: www.example.org\r\n" |
| 7276 | "Connection: keep-alive\r\n" |
| 7277 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7278 | }; |
| 7279 | |
| 7280 | // Sever accepts the authorization. |
| 7281 | MockRead data_reads2[] = { |
| 7282 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7283 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7284 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7285 | }; |
| 7286 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7287 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7288 | data_writes1, arraysize(data_writes1)); |
| 7289 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7290 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7291 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7292 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7293 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7294 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7295 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7296 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7297 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7298 | |
| 7299 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7300 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7301 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7302 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7303 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7304 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7305 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7306 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7307 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7308 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7309 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7310 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7311 | ASSERT_TRUE(response); |
| 7312 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7313 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7314 | } |
| 7315 | |
| 7316 | // ------------------------------------------------------------------------ |
| 7317 | |
| 7318 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 7319 | // cached identity. Should invalidate and re-prompt. |
| 7320 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7321 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7322 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7323 | request.url = GURL("http://www.example.org/p/q/t"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7324 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7325 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7326 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7327 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7328 | MockWrite( |
| 7329 | "GET /p/q/t HTTP/1.1\r\n" |
| 7330 | "Host: www.example.org\r\n" |
| 7331 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7332 | }; |
| 7333 | |
| 7334 | MockRead data_reads1[] = { |
| 7335 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7336 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7337 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7338 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7339 | }; |
| 7340 | |
| 7341 | // Resend with authorization from cache for MyRealm. |
| 7342 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7343 | MockWrite( |
| 7344 | "GET /p/q/t HTTP/1.1\r\n" |
| 7345 | "Host: www.example.org\r\n" |
| 7346 | "Connection: keep-alive\r\n" |
| 7347 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7348 | }; |
| 7349 | |
| 7350 | // Sever rejects the authorization. |
| 7351 | MockRead data_reads2[] = { |
| 7352 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7353 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7354 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7355 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7356 | }; |
| 7357 | |
| 7358 | // At this point we should prompt for new credentials for MyRealm. |
| 7359 | // Restart with username=foo3, password=foo4. |
| 7360 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7361 | MockWrite( |
| 7362 | "GET /p/q/t HTTP/1.1\r\n" |
| 7363 | "Host: www.example.org\r\n" |
| 7364 | "Connection: keep-alive\r\n" |
| 7365 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7366 | }; |
| 7367 | |
| 7368 | // Sever accepts the authorization. |
| 7369 | MockRead data_reads3[] = { |
| 7370 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7371 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7372 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7373 | }; |
| 7374 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7375 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7376 | data_writes1, arraysize(data_writes1)); |
| 7377 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7378 | data_writes2, arraysize(data_writes2)); |
| 7379 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 7380 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7381 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7382 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7383 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7384 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7385 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7386 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7387 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7388 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7389 | |
| 7390 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7391 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7392 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7393 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7394 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7395 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7396 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7397 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7398 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7399 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7400 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7401 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7402 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7403 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7404 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7405 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7406 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7407 | rv = trans.RestartWithAuth(AuthCredentials(kFoo3, kBar3), |
| 7408 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7409 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7410 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7411 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7412 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7413 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7414 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7415 | ASSERT_TRUE(response); |
| 7416 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7417 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7418 | } |
| 7419 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7420 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7421 | // Tests that nonce count increments when multiple auth attempts |
| 7422 | // are started with the same nonce. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7423 | TEST_F(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { |
[email protected] | 54fea256 | 2010-11-17 14:40:44 | [diff] [blame] | 7424 | HttpAuthHandlerDigest::Factory* digest_factory = |
| 7425 | new HttpAuthHandlerDigest::Factory(); |
| 7426 | HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = |
| 7427 | new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); |
| 7428 | digest_factory->set_nonce_generator(nonce_generator); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7429 | session_deps_.http_auth_handler_factory.reset(digest_factory); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7430 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7431 | |
| 7432 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 7433 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7434 | HttpRequestInfo request; |
| 7435 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7436 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7437 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7438 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7439 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7440 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7441 | MockWrite( |
| 7442 | "GET /x/y/z HTTP/1.1\r\n" |
| 7443 | "Host: www.example.org\r\n" |
| 7444 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7445 | }; |
| 7446 | |
| 7447 | MockRead data_reads1[] = { |
| 7448 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7449 | MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " |
| 7450 | "algorithm=MD5, qop=\"auth\"\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7451 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7452 | }; |
| 7453 | |
| 7454 | // Resend with authorization (username=foo, password=bar) |
| 7455 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7456 | MockWrite( |
| 7457 | "GET /x/y/z HTTP/1.1\r\n" |
| 7458 | "Host: www.example.org\r\n" |
| 7459 | "Connection: keep-alive\r\n" |
| 7460 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 7461 | "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " |
| 7462 | "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " |
| 7463 | "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7464 | }; |
| 7465 | |
| 7466 | // Sever accepts the authorization. |
| 7467 | MockRead data_reads2[] = { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 7468 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7469 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7470 | }; |
| 7471 | |
| 7472 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7473 | data_writes1, arraysize(data_writes1)); |
| 7474 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7475 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7476 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7477 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7478 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7479 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7480 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7481 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7482 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7483 | |
| 7484 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7485 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7486 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7487 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7488 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7489 | EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge.get())); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7490 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7491 | TestCompletionCallback callback2; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7492 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7493 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 7494 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7495 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7496 | |
| 7497 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7498 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7499 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7500 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7501 | ASSERT_TRUE(response); |
| 7502 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7503 | } |
| 7504 | |
| 7505 | // ------------------------------------------------------------------------ |
| 7506 | |
| 7507 | // Transaction 2: Request another resource in digestive's protection space. |
| 7508 | // This will preemptively add an Authorization header which should have an |
| 7509 | // "nc" value of 2 (as compared to 1 in the first use. |
| 7510 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7511 | HttpRequestInfo request; |
| 7512 | request.method = "GET"; |
| 7513 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 7514 | // protection space as digest. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7515 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7516 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7517 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7518 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7519 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7520 | MockWrite( |
| 7521 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 7522 | "Host: www.example.org\r\n" |
| 7523 | "Connection: keep-alive\r\n" |
| 7524 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 7525 | "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " |
| 7526 | "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " |
| 7527 | "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7528 | }; |
| 7529 | |
| 7530 | // Sever accepts the authorization. |
| 7531 | MockRead data_reads1[] = { |
| 7532 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7533 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7534 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7535 | }; |
| 7536 | |
| 7537 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7538 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7539 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7540 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7541 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7542 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7543 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7544 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7545 | |
| 7546 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7547 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7548 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7549 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7550 | ASSERT_TRUE(response); |
| 7551 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7552 | } |
| 7553 | } |
| 7554 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7555 | // Test the ResetStateForRestart() private method. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7556 | TEST_F(HttpNetworkTransactionTest, ResetStateForRestart) { |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7557 | // Create a transaction (the dependencies aren't important). |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7558 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7559 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7560 | |
| 7561 | // Setup some state (which we expect ResetStateForRestart() will clear). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7562 | trans.read_buf_ = new IOBuffer(15); |
| 7563 | trans.read_buf_len_ = 15; |
| 7564 | trans.request_headers_.SetHeader("Authorization", "NTLM"); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7565 | |
| 7566 | // Setup state in response_ |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7567 | HttpResponseInfo* response = &trans.response_; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7568 | response->auth_challenge = new AuthChallengeInfo(); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 7569 | response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7570 | response->response_time = base::Time::Now(); |
| 7571 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7572 | |
| 7573 | { // Setup state for response_.vary_data |
| 7574 | HttpRequestInfo request; |
| 7575 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 7576 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 7577 | scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 7578 | request.extra_headers.SetHeader("Foo", "1"); |
| 7579 | request.extra_headers.SetHeader("bar", "23"); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7580 | EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7581 | } |
| 7582 | |
| 7583 | // Cause the above state to be reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7584 | trans.ResetStateForRestart(); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7585 | |
| 7586 | // Verify that the state that needed to be reset, has been reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7587 | EXPECT_FALSE(trans.read_buf_); |
| 7588 | EXPECT_EQ(0, trans.read_buf_len_); |
| 7589 | EXPECT_TRUE(trans.request_headers_.IsEmpty()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7590 | EXPECT_FALSE(response->auth_challenge); |
| 7591 | EXPECT_FALSE(response->headers); |
[email protected] | 34f4094 | 2010-10-04 00:34:04 | [diff] [blame] | 7592 | EXPECT_FALSE(response->was_cached); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 7593 | EXPECT_EQ(0U, response->ssl_info.cert_status); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7594 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7595 | } |
| 7596 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7597 | // Test HTTPS connections to a site with a bad certificate |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7598 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7599 | HttpRequestInfo request; |
| 7600 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7601 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7602 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7603 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7604 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7605 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7606 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7607 | MockWrite( |
| 7608 | "GET / HTTP/1.1\r\n" |
| 7609 | "Host: www.example.org\r\n" |
| 7610 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7611 | }; |
| 7612 | |
| 7613 | MockRead data_reads[] = { |
| 7614 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7615 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7616 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7617 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7618 | }; |
| 7619 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 7620 | StaticSocketDataProvider ssl_bad_certificate; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7621 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7622 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7623 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 7624 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7625 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7626 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 7627 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7628 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 7629 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7630 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7631 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7632 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7633 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7634 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7635 | |
| 7636 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7637 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7638 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7639 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7640 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7641 | |
| 7642 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7643 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7644 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7645 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7646 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7647 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7648 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7649 | } |
| 7650 | |
| 7651 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 7652 | // proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7653 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7654 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7655 | |
| 7656 | HttpRequestInfo request; |
| 7657 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7658 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7659 | |
| 7660 | MockWrite proxy_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7661 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7662 | "Host: www.example.org:443\r\n" |
| 7663 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7664 | }; |
| 7665 | |
| 7666 | MockRead proxy_reads[] = { |
| 7667 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7668 | MockRead(SYNCHRONOUS, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7669 | }; |
| 7670 | |
| 7671 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7672 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7673 | "Host: www.example.org:443\r\n" |
| 7674 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7675 | MockWrite("GET / HTTP/1.1\r\n" |
| 7676 | "Host: www.example.org\r\n" |
| 7677 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7678 | }; |
| 7679 | |
| 7680 | MockRead data_reads[] = { |
| 7681 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 7682 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7683 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7684 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7685 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7686 | }; |
| 7687 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7688 | StaticSocketDataProvider ssl_bad_certificate( |
| 7689 | proxy_reads, arraysize(proxy_reads), |
| 7690 | proxy_writes, arraysize(proxy_writes)); |
| 7691 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7692 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7693 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 7694 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7695 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7696 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 7697 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7698 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 7699 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7700 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7701 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7702 | |
| 7703 | for (int i = 0; i < 2; i++) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7704 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7705 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7706 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7707 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7708 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7709 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7710 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7711 | |
| 7712 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7713 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7714 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7715 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7716 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7717 | |
| 7718 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7719 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7720 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7721 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7722 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7723 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7724 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7725 | } |
| 7726 | } |
| 7727 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7728 | |
| 7729 | // Test HTTPS connections to a site, going through an HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7730 | TEST_F(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7731 | session_deps_.proxy_service = |
| 7732 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7733 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7734 | session_deps_.net_log = &net_log; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7735 | |
| 7736 | HttpRequestInfo request; |
| 7737 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7738 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7739 | |
| 7740 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7741 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7742 | "Host: www.example.org:443\r\n" |
| 7743 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7744 | MockWrite("GET / HTTP/1.1\r\n" |
| 7745 | "Host: www.example.org\r\n" |
| 7746 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7747 | }; |
| 7748 | |
| 7749 | MockRead data_reads[] = { |
| 7750 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 7751 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7752 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7753 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7754 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7755 | }; |
| 7756 | |
| 7757 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7758 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7759 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 7760 | SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7761 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7762 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7763 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 7764 | session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7765 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7766 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7767 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7768 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7769 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7770 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7771 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7772 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7773 | |
| 7774 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7775 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7776 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7777 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7778 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7779 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 7780 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7781 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 7782 | EXPECT_EQ(200, response->headers->response_code()); |
| 7783 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7784 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7785 | |
| 7786 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7787 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7788 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7789 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7790 | } |
| 7791 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7792 | // Test an HTTPS Proxy's ability to redirect a CONNECT request |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7793 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7794 | session_deps_.proxy_service = |
| 7795 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7796 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7797 | session_deps_.net_log = &net_log; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7798 | |
| 7799 | HttpRequestInfo request; |
| 7800 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7801 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7802 | |
| 7803 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7804 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7805 | "Host: www.example.org:443\r\n" |
| 7806 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7807 | }; |
| 7808 | |
| 7809 | MockRead data_reads[] = { |
| 7810 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 7811 | MockRead("Location: http://login.example.com/\r\n"), |
| 7812 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7813 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7814 | }; |
| 7815 | |
| 7816 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7817 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7818 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7819 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7820 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7821 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7822 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7823 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7824 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7825 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7826 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7827 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7828 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7829 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7830 | |
| 7831 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7832 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7833 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7834 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7835 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7836 | |
| 7837 | EXPECT_EQ(302, response->headers->response_code()); |
| 7838 | std::string url; |
| 7839 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 7840 | EXPECT_EQ("http://login.example.com/", url); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7841 | |
| 7842 | // In the case of redirects from proxies, HttpNetworkTransaction returns |
| 7843 | // timing for the proxy connection instead of the connection to the host, |
| 7844 | // and no send / receive times. |
| 7845 | // See HttpNetworkTransaction::OnHttpsProxyTunnelResponse. |
| 7846 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7847 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7848 | |
| 7849 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 7850 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7851 | |
| 7852 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 7853 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 7854 | load_timing_info.proxy_resolve_end); |
| 7855 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 7856 | load_timing_info.connect_timing.connect_start); |
| 7857 | ExpectConnectTimingHasTimes( |
| 7858 | load_timing_info.connect_timing, |
| 7859 | CONNECT_TIMING_HAS_DNS_TIMES | CONNECT_TIMING_HAS_SSL_TIMES); |
| 7860 | |
| 7861 | EXPECT_TRUE(load_timing_info.send_start.is_null()); |
| 7862 | EXPECT_TRUE(load_timing_info.send_end.is_null()); |
| 7863 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7864 | } |
| 7865 | |
| 7866 | // Test an HTTPS (SPDY) Proxy's ability to redirect a CONNECT request |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7867 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7868 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7869 | |
| 7870 | HttpRequestInfo request; |
| 7871 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7872 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7873 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7874 | SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7875 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7876 | SpdySerializedFrame goaway( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 7877 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7878 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7879 | CreateMockWrite(conn, 0, SYNCHRONOUS), |
| 7880 | CreateMockWrite(goaway, 2, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7881 | }; |
| 7882 | |
| 7883 | static const char* const kExtraHeaders[] = { |
| 7884 | "location", |
| 7885 | "http://login.example.com/", |
| 7886 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 7887 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
bnc | c9f762a | 2016-12-06 20:38:23 | [diff] [blame] | 7888 | "302", kExtraHeaders, arraysize(kExtraHeaders) / 2, 1)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7889 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7890 | CreateMockRead(resp, 1), MockRead(ASYNC, 0, 3), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7891 | }; |
| 7892 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7893 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 7894 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7895 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 7896 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7897 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7898 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7899 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7900 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7901 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7902 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7903 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7904 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7905 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7906 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7907 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7908 | |
| 7909 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7910 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7911 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7912 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7913 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7914 | |
| 7915 | EXPECT_EQ(302, response->headers->response_code()); |
| 7916 | std::string url; |
| 7917 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 7918 | EXPECT_EQ("http://login.example.com/", url); |
| 7919 | } |
| 7920 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7921 | // Test that an HTTPS proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7922 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7923 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7924 | |
| 7925 | HttpRequestInfo request; |
| 7926 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7927 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7928 | |
| 7929 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7930 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7931 | "Host: www.example.org:443\r\n" |
| 7932 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7933 | }; |
| 7934 | |
| 7935 | MockRead data_reads[] = { |
| 7936 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 7937 | MockRead("Content-Length: 23\r\n\r\n"), |
| 7938 | MockRead("The host does not exist"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7939 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7940 | }; |
| 7941 | |
| 7942 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7943 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7944 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7945 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7946 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7947 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7948 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7949 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7950 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7951 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7952 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7953 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7954 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7955 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7956 | |
| 7957 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7958 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7959 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 7960 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7961 | } |
| 7962 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 7963 | // Test that a SPDY proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7964 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaSpdyProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7965 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7966 | |
| 7967 | HttpRequestInfo request; |
| 7968 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7969 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7970 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7971 | SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7972 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7973 | SpdySerializedFrame rst( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 7974 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7975 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7976 | CreateMockWrite(conn, 0), CreateMockWrite(rst, 3), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7977 | }; |
| 7978 | |
| 7979 | static const char* const kExtraHeaders[] = { |
| 7980 | "location", |
| 7981 | "http://login.example.com/", |
| 7982 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 7983 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
bnc | c9f762a | 2016-12-06 20:38:23 | [diff] [blame] | 7984 | "404", kExtraHeaders, arraysize(kExtraHeaders) / 2, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7985 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 7986 | 1, "The host does not exist", 23, true)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7987 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7988 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7989 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7990 | }; |
| 7991 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7992 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 7993 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7994 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 7995 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7996 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7997 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7998 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7999 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8000 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8001 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8002 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8003 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8004 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8005 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8006 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8007 | |
| 8008 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8009 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8010 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 8011 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8012 | } |
| 8013 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8014 | // Test the request-challenge-retry sequence for basic auth, through |
| 8015 | // a SPDY proxy over a single SPDY session. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8016 | TEST_F(HttpNetworkTransactionTest, BasicAuthSpdyProxy) { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8017 | HttpRequestInfo request; |
| 8018 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8019 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8020 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 8021 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8022 | |
| 8023 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8024 | session_deps_.proxy_service = |
| 8025 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8026 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8027 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8028 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8029 | |
| 8030 | // Since we have proxy, should try to establish tunnel. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8031 | SpdySerializedFrame req(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8032 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8033 | SpdySerializedFrame rst( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 8034 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 8035 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8036 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8037 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8038 | // be issuing -- the final header line contains the credentials. |
| 8039 | const char* const kAuthCredentials[] = { |
| 8040 | "proxy-authorization", "Basic Zm9vOmJhcg==", |
| 8041 | }; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8042 | SpdySerializedFrame connect2(spdy_util_.ConstructSpdyConnect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 8043 | kAuthCredentials, arraysize(kAuthCredentials) / 2, 3, LOWEST, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8044 | HostPortPair("www.example.org", 443))); |
| 8045 | // fetch https://www.example.org/ via HTTP |
| 8046 | const char get[] = |
| 8047 | "GET / HTTP/1.1\r\n" |
| 8048 | "Host: www.example.org\r\n" |
| 8049 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8050 | SpdySerializedFrame wrapped_get( |
| 8051 | spdy_util_.ConstructSpdyDataFrame(3, get, strlen(get), false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8052 | |
| 8053 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8054 | CreateMockWrite(req, 0, ASYNC), CreateMockWrite(rst, 2, ASYNC), |
| 8055 | CreateMockWrite(connect2, 3), CreateMockWrite(wrapped_get, 5), |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8056 | }; |
| 8057 | |
| 8058 | // The proxy responds to the connect with a 407, using a persistent |
| 8059 | // connection. |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 8060 | const char kAuthStatus[] = "407"; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8061 | const char* const kAuthChallenge[] = { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8062 | "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 8063 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8064 | SpdySerializedFrame conn_auth_resp(spdy_util_.ConstructSpdyReplyError( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8065 | kAuthStatus, kAuthChallenge, arraysize(kAuthChallenge) / 2, 1)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8066 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8067 | SpdySerializedFrame conn_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8068 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 8069 | "Content-Length: 5\r\n\r\n"; |
| 8070 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8071 | SpdySerializedFrame wrapped_get_resp( |
| 8072 | spdy_util_.ConstructSpdyDataFrame(3, resp, strlen(resp), false)); |
| 8073 | SpdySerializedFrame wrapped_body( |
| 8074 | spdy_util_.ConstructSpdyDataFrame(3, "hello", 5, false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8075 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8076 | CreateMockRead(conn_auth_resp, 1, ASYNC), |
| 8077 | CreateMockRead(conn_resp, 4, ASYNC), |
| 8078 | CreateMockRead(wrapped_get_resp, 6, ASYNC), |
| 8079 | CreateMockRead(wrapped_body, 7, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8080 | MockRead(ASYNC, OK, 8), // EOF. May or may not be read. |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8081 | }; |
| 8082 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8083 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8084 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8085 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8086 | // Negotiate SPDY to the proxy |
| 8087 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8088 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8089 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8090 | // Vanilla SSL to the server |
| 8091 | SSLSocketDataProvider server(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8092 | session_deps_.socket_factory->AddSSLSocketDataProvider(&server); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8093 | |
| 8094 | TestCompletionCallback callback1; |
| 8095 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8096 | auto trans = |
| 8097 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8098 | |
| 8099 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8100 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8101 | |
| 8102 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8103 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 8104 | TestNetLogEntry::List entries; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8105 | log.GetEntries(&entries); |
| 8106 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 8107 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 8108 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8109 | ExpectLogContainsSomewhere( |
| 8110 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 8111 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 8112 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8113 | |
| 8114 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8115 | ASSERT_TRUE(response); |
| 8116 | ASSERT_TRUE(response->headers); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8117 | EXPECT_EQ(407, response->headers->response_code()); |
| 8118 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8119 | EXPECT_TRUE(response->auth_challenge); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 8120 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8121 | |
| 8122 | TestCompletionCallback callback2; |
| 8123 | |
| 8124 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 8125 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8126 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8127 | |
| 8128 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8129 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8130 | |
| 8131 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8132 | ASSERT_TRUE(response); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8133 | |
| 8134 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8135 | EXPECT_EQ(200, response->headers->response_code()); |
| 8136 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 8137 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8138 | |
| 8139 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8140 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8141 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8142 | LoadTimingInfo load_timing_info; |
| 8143 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8144 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8145 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 8146 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8147 | trans.reset(); |
| 8148 | session->CloseAllConnections(); |
| 8149 | } |
| 8150 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8151 | // Test that an explicitly trusted SPDY proxy can push a resource from an |
| 8152 | // origin that is different from that of its associated resource. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8153 | TEST_F(HttpNetworkTransactionTest, CrossOriginSPDYProxyPush) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8154 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8155 | auto proxy_delegate = base::MakeUnique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8156 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 8157 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8158 | HttpRequestInfo request; |
| 8159 | HttpRequestInfo push_request; |
| 8160 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8161 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8162 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8163 | push_request.method = "GET"; |
| 8164 | push_request.url = GURL("http://www.another-origin.com/foo.dat"); |
| 8165 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8166 | // Configure against https proxy server "myproxy:443". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8167 | session_deps_.proxy_service = |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8168 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:443"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8169 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8170 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8171 | |
inlinechan | 894515af | 2016-12-09 02:40:10 | [diff] [blame] | 8172 | session_deps_.proxy_delegate = std::move(proxy_delegate); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8173 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8174 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8175 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8176 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 8177 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8178 | SpdySerializedFrame stream2_priority( |
| 8179 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8180 | |
| 8181 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8182 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8183 | CreateMockWrite(stream2_priority, 3, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8184 | }; |
| 8185 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8186 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8187 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8188 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8189 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8190 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8191 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 8192 | NULL, 0, 2, 1, "http://www.another-origin.com/foo.dat")); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8193 | const char kPushedData[] = "pushed"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8194 | SpdySerializedFrame stream2_body(spdy_util_.ConstructSpdyDataFrame( |
| 8195 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8196 | |
| 8197 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8198 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 8199 | CreateMockRead(stream2_syn, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8200 | CreateMockRead(stream1_body, 4, ASYNC), |
| 8201 | CreateMockRead(stream2_body, 5, ASYNC), |
| 8202 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8203 | }; |
| 8204 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8205 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8206 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8207 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8208 | // Negotiate SPDY to the proxy |
| 8209 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8210 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8211 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8212 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8213 | auto trans = |
| 8214 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8215 | TestCompletionCallback callback; |
| 8216 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8217 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8218 | |
| 8219 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8220 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8221 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8222 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8223 | auto push_trans = |
| 8224 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8225 | rv = push_trans->Start(&push_request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8226 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8227 | |
| 8228 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8229 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8230 | const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); |
| 8231 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8232 | ASSERT_TRUE(response); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8233 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8234 | |
| 8235 | EXPECT_EQ(200, response->headers->response_code()); |
| 8236 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8237 | |
| 8238 | std::string response_data; |
| 8239 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8240 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8241 | EXPECT_EQ("hello!", response_data); |
| 8242 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8243 | LoadTimingInfo load_timing_info; |
| 8244 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8245 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8246 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 8247 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8248 | // Verify the pushed stream. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8249 | EXPECT_TRUE(push_response->headers); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8250 | EXPECT_EQ(200, push_response->headers->response_code()); |
| 8251 | |
| 8252 | rv = ReadTransaction(push_trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8253 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8254 | EXPECT_EQ("pushed", response_data); |
| 8255 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8256 | LoadTimingInfo push_load_timing_info; |
| 8257 | EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); |
| 8258 | TestLoadTimingReusedWithPac(push_load_timing_info); |
| 8259 | // The transactions should share a socket ID, despite being for different |
| 8260 | // origins. |
| 8261 | EXPECT_EQ(load_timing_info.socket_log_id, |
| 8262 | push_load_timing_info.socket_log_id); |
| 8263 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8264 | trans.reset(); |
| 8265 | push_trans.reset(); |
| 8266 | session->CloseAllConnections(); |
| 8267 | } |
| 8268 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8269 | // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8270 | TEST_F(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8271 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8272 | auto proxy_delegate = base::MakeUnique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8273 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 8274 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8275 | HttpRequestInfo request; |
| 8276 | |
| 8277 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8278 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8279 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8280 | session_deps_.proxy_service = |
| 8281 | ProxyService::CreateFixed("https://myproxy:443"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8282 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8283 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8284 | |
| 8285 | // Enable cross-origin push. |
inlinechan | 894515af | 2016-12-09 02:40:10 | [diff] [blame] | 8286 | session_deps_.proxy_delegate = std::move(proxy_delegate); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8287 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8288 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8289 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8290 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 8291 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8292 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8293 | SpdySerializedFrame push_rst( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 8294 | spdy_util_.ConstructSpdyRstStream(2, ERROR_CODE_REFUSED_STREAM)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8295 | |
| 8296 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8297 | CreateMockWrite(stream1_syn, 0, ASYNC), CreateMockWrite(push_rst, 3), |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8298 | }; |
| 8299 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8300 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8301 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8302 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8303 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8304 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8305 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 8306 | NULL, 0, 2, 1, "https://www.another-origin.com/foo.dat")); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8307 | |
| 8308 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8309 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 8310 | CreateMockRead(stream2_syn, 2, ASYNC), |
| 8311 | CreateMockRead(stream1_body, 4, ASYNC), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 8312 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a hang |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8313 | }; |
| 8314 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8315 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8316 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8317 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8318 | // Negotiate SPDY to the proxy |
| 8319 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8320 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8321 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8322 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8323 | auto trans = |
| 8324 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8325 | TestCompletionCallback callback; |
| 8326 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8327 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8328 | |
| 8329 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8330 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8331 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8332 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8333 | ASSERT_TRUE(response); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8334 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8335 | |
| 8336 | EXPECT_EQ(200, response->headers->response_code()); |
| 8337 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8338 | |
| 8339 | std::string response_data; |
| 8340 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8341 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8342 | EXPECT_EQ("hello!", response_data); |
| 8343 | |
| 8344 | trans.reset(); |
| 8345 | session->CloseAllConnections(); |
| 8346 | } |
| 8347 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8348 | // Test that an explicitly trusted SPDY proxy can push same-origin HTTPS |
| 8349 | // resources. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8350 | TEST_F(HttpNetworkTransactionTest, SameOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8351 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8352 | auto proxy_delegate = base::MakeUnique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8353 | proxy_delegate->set_trusted_spdy_proxy( |
| 8354 | net::ProxyServer::FromURI("myproxy:70", net::ProxyServer::SCHEME_HTTP)); |
| 8355 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8356 | HttpRequestInfo request; |
| 8357 | |
| 8358 | request.method = "GET"; |
| 8359 | request.url = GURL("http://www.example.org/"); |
| 8360 | |
| 8361 | // Configure against https proxy server "myproxy:70". |
| 8362 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
| 8363 | BoundTestNetLog log; |
| 8364 | session_deps_.net_log = log.bound().net_log(); |
| 8365 | |
| 8366 | // Enable cross-origin push. |
inlinechan | 894515af | 2016-12-09 02:40:10 | [diff] [blame] | 8367 | session_deps_.proxy_delegate = std::move(proxy_delegate); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8368 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8369 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8370 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8371 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 8372 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8373 | SpdySerializedFrame stream2_priority( |
| 8374 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8375 | |
| 8376 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8377 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8378 | CreateMockWrite(stream2_priority, 3, ASYNC), |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8379 | }; |
| 8380 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8381 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8382 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8383 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8384 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 8385 | nullptr, 0, 2, 1, "https://myproxy:70/foo.dat")); |
| 8386 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8387 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8388 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8389 | SpdySerializedFrame stream2_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8390 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8391 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8392 | SpdySerializedFrame stream2_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8393 | |
| 8394 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8395 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 8396 | CreateMockRead(stream2_syn, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8397 | CreateMockRead(stream1_body, 4, ASYNC), |
| 8398 | CreateMockRead(stream2_body, 5, ASYNC), |
| 8399 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8400 | }; |
| 8401 | |
| 8402 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8403 | arraysize(spdy_writes)); |
| 8404 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 8405 | // Negotiate SPDY to the proxy |
| 8406 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8407 | proxy.next_proto = kProtoHTTP2; |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8408 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
| 8409 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8410 | auto trans = |
| 8411 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8412 | TestCompletionCallback callback; |
| 8413 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8414 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8415 | |
| 8416 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8417 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8418 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8419 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8420 | ASSERT_TRUE(response); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8421 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8422 | |
| 8423 | EXPECT_EQ(200, response->headers->response_code()); |
| 8424 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8425 | |
| 8426 | std::string response_data; |
| 8427 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8428 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8429 | EXPECT_EQ("hello!", response_data); |
| 8430 | |
| 8431 | trans.reset(); |
| 8432 | session->CloseAllConnections(); |
| 8433 | } |
| 8434 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8435 | // Test HTTPS connections to a site with a bad certificate, going through an |
| 8436 | // HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8437 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8438 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8439 | |
| 8440 | HttpRequestInfo request; |
| 8441 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8442 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8443 | |
| 8444 | // Attempt to fetch the URL from a server with a bad cert |
| 8445 | MockWrite bad_cert_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8446 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8447 | "Host: www.example.org:443\r\n" |
| 8448 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8449 | }; |
| 8450 | |
| 8451 | MockRead bad_cert_reads[] = { |
| 8452 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8453 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8454 | }; |
| 8455 | |
| 8456 | // Attempt to fetch the URL with a good cert |
| 8457 | MockWrite good_data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8458 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8459 | "Host: www.example.org:443\r\n" |
| 8460 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 8461 | MockWrite("GET / HTTP/1.1\r\n" |
| 8462 | "Host: www.example.org\r\n" |
| 8463 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8464 | }; |
| 8465 | |
| 8466 | MockRead good_cert_reads[] = { |
| 8467 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 8468 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8469 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8470 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8471 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8472 | }; |
| 8473 | |
| 8474 | StaticSocketDataProvider ssl_bad_certificate( |
| 8475 | bad_cert_reads, arraysize(bad_cert_reads), |
| 8476 | bad_cert_writes, arraysize(bad_cert_writes)); |
| 8477 | StaticSocketDataProvider data(good_cert_reads, arraysize(good_cert_reads), |
| 8478 | good_data_writes, arraysize(good_data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8479 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 8480 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8481 | |
| 8482 | // SSL to the proxy, then CONNECT request, then SSL with bad certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8483 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 8484 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 8485 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8486 | |
| 8487 | // SSL to the proxy, then CONNECT request, then valid SSL certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8488 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 8489 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8490 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8491 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8492 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8493 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8494 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8495 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8496 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8497 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8498 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8499 | |
| 8500 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8501 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8502 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8503 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8504 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8505 | |
| 8506 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8507 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8508 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8509 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8510 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8511 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8512 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8513 | } |
| 8514 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8515 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8516 | HttpRequestInfo request; |
| 8517 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8518 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8519 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 8520 | "Chromium Ultra Awesome X Edition"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8521 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8522 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8523 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8524 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8525 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8526 | MockWrite( |
| 8527 | "GET / HTTP/1.1\r\n" |
| 8528 | "Host: www.example.org\r\n" |
| 8529 | "Connection: keep-alive\r\n" |
| 8530 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8531 | }; |
| 8532 | |
| 8533 | // Lastly, the server responds with the actual content. |
| 8534 | MockRead data_reads[] = { |
| 8535 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8536 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8537 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8538 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8539 | }; |
| 8540 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8541 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8542 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8543 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8544 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8545 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8546 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8547 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8548 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8549 | |
| 8550 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8551 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8552 | } |
| 8553 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8554 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8555 | HttpRequestInfo request; |
| 8556 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8557 | request.url = GURL("https://www.example.org/"); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8558 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 8559 | "Chromium Ultra Awesome X Edition"); |
| 8560 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8561 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8562 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8563 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8564 | |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8565 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8566 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8567 | "Host: www.example.org:443\r\n" |
| 8568 | "Proxy-Connection: keep-alive\r\n" |
| 8569 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8570 | }; |
| 8571 | MockRead data_reads[] = { |
| 8572 | // Return an error, so the transaction stops here (this test isn't |
| 8573 | // interested in the rest). |
| 8574 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 8575 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8576 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 8577 | }; |
| 8578 | |
| 8579 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8580 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8581 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8582 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8583 | TestCompletionCallback callback; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8584 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8585 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8586 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8587 | |
| 8588 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8589 | EXPECT_THAT(rv, IsOk()); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8590 | } |
| 8591 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8592 | TEST_F(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8593 | HttpRequestInfo request; |
| 8594 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8595 | request.url = GURL("http://www.example.org/"); |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 8596 | request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 8597 | "http://the.previous.site.com/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8598 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8599 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8600 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8601 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8602 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8603 | MockWrite( |
| 8604 | "GET / HTTP/1.1\r\n" |
| 8605 | "Host: www.example.org\r\n" |
| 8606 | "Connection: keep-alive\r\n" |
| 8607 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8608 | }; |
| 8609 | |
| 8610 | // Lastly, the server responds with the actual content. |
| 8611 | MockRead data_reads[] = { |
| 8612 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8613 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8614 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8615 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8616 | }; |
| 8617 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8618 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8619 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8620 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8621 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8622 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8623 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8624 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8625 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8626 | |
| 8627 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8628 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8629 | } |
| 8630 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8631 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8632 | HttpRequestInfo request; |
| 8633 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8634 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8635 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8636 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8637 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8638 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8639 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8640 | MockWrite( |
| 8641 | "POST / HTTP/1.1\r\n" |
| 8642 | "Host: www.example.org\r\n" |
| 8643 | "Connection: keep-alive\r\n" |
| 8644 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8645 | }; |
| 8646 | |
| 8647 | // Lastly, the server responds with the actual content. |
| 8648 | MockRead data_reads[] = { |
| 8649 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8650 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8651 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8652 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8653 | }; |
| 8654 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8655 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8656 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8657 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8658 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8659 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8660 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8661 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8662 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8663 | |
| 8664 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8665 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8666 | } |
| 8667 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8668 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8669 | HttpRequestInfo request; |
| 8670 | request.method = "PUT"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8671 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8672 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8673 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8674 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8675 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8676 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8677 | MockWrite( |
| 8678 | "PUT / HTTP/1.1\r\n" |
| 8679 | "Host: www.example.org\r\n" |
| 8680 | "Connection: keep-alive\r\n" |
| 8681 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8682 | }; |
| 8683 | |
| 8684 | // Lastly, the server responds with the actual content. |
| 8685 | MockRead data_reads[] = { |
| 8686 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8687 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8688 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8689 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8690 | }; |
| 8691 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8692 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8693 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8694 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8695 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8696 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8697 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8698 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8699 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8700 | |
| 8701 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8702 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8703 | } |
| 8704 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8705 | TEST_F(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8706 | HttpRequestInfo request; |
| 8707 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8708 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8709 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8710 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8711 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8712 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8713 | MockWrite data_writes[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 8714 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 8715 | "Host: www.example.org\r\n" |
| 8716 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8717 | }; |
| 8718 | |
| 8719 | // Lastly, the server responds with the actual content. |
| 8720 | MockRead data_reads[] = { |
| 8721 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8722 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8723 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8724 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8725 | }; |
| 8726 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8727 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8728 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8729 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8730 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8731 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8732 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8733 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8734 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8735 | |
| 8736 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8737 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8738 | } |
| 8739 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8740 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8741 | HttpRequestInfo request; |
| 8742 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8743 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8744 | request.load_flags = LOAD_BYPASS_CACHE; |
| 8745 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8746 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8747 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8748 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8749 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8750 | MockWrite( |
| 8751 | "GET / HTTP/1.1\r\n" |
| 8752 | "Host: www.example.org\r\n" |
| 8753 | "Connection: keep-alive\r\n" |
| 8754 | "Pragma: no-cache\r\n" |
| 8755 | "Cache-Control: no-cache\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8756 | }; |
| 8757 | |
| 8758 | // Lastly, the server responds with the actual content. |
| 8759 | MockRead data_reads[] = { |
| 8760 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8761 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8762 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8763 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8764 | }; |
| 8765 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8766 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8767 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8768 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8769 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8770 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8771 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8772 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8773 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8774 | |
| 8775 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8776 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8777 | } |
| 8778 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8779 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlValidateCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8780 | HttpRequestInfo request; |
| 8781 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8782 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8783 | request.load_flags = LOAD_VALIDATE_CACHE; |
| 8784 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8785 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8786 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8787 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8788 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8789 | MockWrite( |
| 8790 | "GET / HTTP/1.1\r\n" |
| 8791 | "Host: www.example.org\r\n" |
| 8792 | "Connection: keep-alive\r\n" |
| 8793 | "Cache-Control: max-age=0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8794 | }; |
| 8795 | |
| 8796 | // Lastly, the server responds with the actual content. |
| 8797 | MockRead data_reads[] = { |
| 8798 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8799 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8800 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8801 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8802 | }; |
| 8803 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8804 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8805 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8806 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8807 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8808 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8809 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8810 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8811 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8812 | |
| 8813 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8814 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8815 | } |
| 8816 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8817 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8818 | HttpRequestInfo request; |
| 8819 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8820 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8821 | request.extra_headers.SetHeader("FooHeader", "Bar"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8822 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8823 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8824 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8825 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8826 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8827 | MockWrite( |
| 8828 | "GET / HTTP/1.1\r\n" |
| 8829 | "Host: www.example.org\r\n" |
| 8830 | "Connection: keep-alive\r\n" |
| 8831 | "FooHeader: Bar\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8832 | }; |
| 8833 | |
| 8834 | // Lastly, the server responds with the actual content. |
| 8835 | MockRead data_reads[] = { |
| 8836 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8837 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8838 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8839 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8840 | }; |
| 8841 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8842 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8843 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8844 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8845 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8846 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8847 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8848 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8849 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8850 | |
| 8851 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8852 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8853 | } |
| 8854 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8855 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8856 | HttpRequestInfo request; |
| 8857 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8858 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8859 | request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 8860 | request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 8861 | request.extra_headers.SetHeader("FoO", "bar"); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8862 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8863 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8864 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8865 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8866 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8867 | MockWrite( |
| 8868 | "GET / HTTP/1.1\r\n" |
| 8869 | "Host: www.example.org\r\n" |
| 8870 | "Connection: keep-alive\r\n" |
| 8871 | "referer: www.foo.com\r\n" |
| 8872 | "hEllo: Kitty\r\n" |
| 8873 | "FoO: bar\r\n\r\n"), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8874 | }; |
| 8875 | |
| 8876 | // Lastly, the server responds with the actual content. |
| 8877 | MockRead data_reads[] = { |
| 8878 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8879 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8880 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8881 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8882 | }; |
| 8883 | |
| 8884 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8885 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8886 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8887 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8888 | TestCompletionCallback callback; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8889 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8890 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8891 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8892 | |
| 8893 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8894 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8895 | } |
| 8896 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8897 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8898 | HttpRequestInfo request; |
| 8899 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8900 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8901 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8902 | session_deps_.proxy_service = |
| 8903 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8904 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8905 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8906 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8907 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8908 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8909 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8910 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 8911 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 8912 | |
| 8913 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8914 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 8915 | MockWrite( |
| 8916 | "GET / HTTP/1.1\r\n" |
| 8917 | "Host: www.example.org\r\n" |
| 8918 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8919 | |
| 8920 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8921 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8922 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8923 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8924 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8925 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8926 | }; |
| 8927 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8928 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8929 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8930 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8931 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8932 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8933 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8934 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8935 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8936 | |
| 8937 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8938 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8939 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8940 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8941 | ASSERT_TRUE(response); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8942 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 8943 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8944 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8945 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8946 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8947 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 8948 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8949 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8950 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8951 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8952 | EXPECT_EQ("Payload", response_text); |
| 8953 | } |
| 8954 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8955 | TEST_F(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8956 | HttpRequestInfo request; |
| 8957 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8958 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8959 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8960 | session_deps_.proxy_service = |
| 8961 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8962 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8963 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8964 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8965 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8966 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8967 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8968 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 8969 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 8970 | |
| 8971 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8972 | MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), |
| 8973 | arraysize(write_buffer)), |
| 8974 | MockWrite( |
| 8975 | "GET / HTTP/1.1\r\n" |
| 8976 | "Host: www.example.org\r\n" |
| 8977 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8978 | |
| 8979 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 8980 | MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), |
| 8981 | arraysize(read_buffer)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8982 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8983 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 8984 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8985 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8986 | }; |
| 8987 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8988 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8989 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8990 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8991 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8992 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8993 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8994 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8995 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8996 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8997 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8998 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 8999 | |
| 9000 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9001 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9002 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9003 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9004 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9005 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9006 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 9007 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9008 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9009 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9010 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9011 | |
| 9012 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9013 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9014 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9015 | EXPECT_EQ("Payload", response_text); |
| 9016 | } |
| 9017 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9018 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9019 | HttpRequestInfo request; |
| 9020 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9021 | request.url = GURL("http://www.example.org/"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9022 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9023 | session_deps_.proxy_service = |
| 9024 | ProxyService::CreateFixed("socks4://myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9025 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9026 | session_deps_.net_log = &net_log; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9027 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9028 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9029 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9030 | |
| 9031 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 9032 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 9033 | |
| 9034 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9035 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 9036 | MockWrite( |
| 9037 | "GET / HTTP/1.1\r\n" |
| 9038 | "Host: www.example.org\r\n" |
| 9039 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9040 | |
| 9041 | MockRead data_reads[] = { |
| 9042 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
| 9043 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9044 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9045 | MockRead("Payload"), |
| 9046 | MockRead(SYNCHRONOUS, OK) |
| 9047 | }; |
| 9048 | |
| 9049 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9050 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9051 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9052 | |
| 9053 | TestCompletionCallback callback; |
| 9054 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9055 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9056 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9057 | |
| 9058 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9059 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9060 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9061 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9062 | ASSERT_TRUE(response); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9063 | |
| 9064 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9065 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9066 | TestLoadTimingNotReused(load_timing_info, |
| 9067 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 9068 | |
| 9069 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9070 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9071 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9072 | EXPECT_EQ("Payload", response_text); |
| 9073 | } |
| 9074 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9075 | TEST_F(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9076 | HttpRequestInfo request; |
| 9077 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9078 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9079 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9080 | session_deps_.proxy_service = |
| 9081 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9082 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9083 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9084 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9085 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9086 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9087 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9088 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 9089 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9090 | const char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9091 | 0x05, // Version |
| 9092 | 0x01, // Command (CONNECT) |
| 9093 | 0x00, // Reserved. |
| 9094 | 0x03, // Address type (DOMAINNAME). |
| 9095 | 0x0F, // Length of domain (15) |
| 9096 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 9097 | '.', 'o', 'r', 'g', 0x00, 0x50, // 16-bit port (80) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9098 | }; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9099 | const char kSOCKS5OkResponse[] = |
| 9100 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 9101 | |
| 9102 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9103 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 9104 | MockWrite(ASYNC, kSOCKS5OkRequest, arraysize(kSOCKS5OkRequest)), |
| 9105 | MockWrite( |
| 9106 | "GET / HTTP/1.1\r\n" |
| 9107 | "Host: www.example.org\r\n" |
| 9108 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9109 | |
| 9110 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 9111 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 9112 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9113 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9114 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9115 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9116 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9117 | }; |
| 9118 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9119 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9120 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9121 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9122 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9123 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9124 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9125 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9126 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9127 | |
| 9128 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9129 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9130 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9131 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9132 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9133 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9134 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9135 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9136 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9137 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9138 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 9139 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9140 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9141 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9142 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9143 | EXPECT_EQ("Payload", response_text); |
| 9144 | } |
| 9145 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9146 | TEST_F(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9147 | HttpRequestInfo request; |
| 9148 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9149 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9150 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9151 | session_deps_.proxy_service = |
| 9152 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9153 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9154 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9155 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9156 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9157 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9158 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9159 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 9160 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9161 | const unsigned char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9162 | 0x05, // Version |
| 9163 | 0x01, // Command (CONNECT) |
| 9164 | 0x00, // Reserved. |
| 9165 | 0x03, // Address type (DOMAINNAME). |
| 9166 | 0x0F, // Length of domain (15) |
| 9167 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 9168 | '.', 'o', 'r', 'g', 0x01, 0xBB, // 16-bit port (443) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9169 | }; |
| 9170 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9171 | const char kSOCKS5OkResponse[] = |
| 9172 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 9173 | |
| 9174 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9175 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 9176 | MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
| 9177 | arraysize(kSOCKS5OkRequest)), |
| 9178 | MockWrite( |
| 9179 | "GET / HTTP/1.1\r\n" |
| 9180 | "Host: www.example.org\r\n" |
| 9181 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9182 | |
| 9183 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 9184 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 9185 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9186 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9187 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9188 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9189 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9190 | }; |
| 9191 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9192 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9193 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9194 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9195 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9196 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9197 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9198 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9199 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9200 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9201 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9202 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9203 | |
| 9204 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9205 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9206 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9207 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9208 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9209 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9210 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9211 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9212 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9213 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9214 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 9215 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9216 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9217 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9218 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9219 | EXPECT_EQ("Payload", response_text); |
| 9220 | } |
| 9221 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9222 | namespace { |
| 9223 | |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9224 | // Tests that for connection endpoints the group names are correctly set. |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9225 | |
| 9226 | struct GroupNameTest { |
| 9227 | std::string proxy_server; |
| 9228 | std::string url; |
| 9229 | std::string expected_group_name; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9230 | bool ssl; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9231 | }; |
| 9232 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9233 | std::unique_ptr<HttpNetworkSession> SetupSessionForGroupNameTests( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9234 | SpdySessionDependencies* session_deps_) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9235 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9236 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 9237 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9238 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 9239 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9240 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 9241 | http_server_properties->SetAlternativeService( |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9242 | url::SchemeHostPort("https", "host.with.alternate", 443), |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 9243 | alternative_service, expiration); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9244 | |
| 9245 | return session; |
| 9246 | } |
| 9247 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9248 | int GroupNameTransactionHelper(const std::string& url, |
| 9249 | HttpNetworkSession* session) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9250 | HttpRequestInfo request; |
| 9251 | request.method = "GET"; |
| 9252 | request.url = GURL(url); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9253 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9254 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9255 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9256 | TestCompletionCallback callback; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9257 | |
| 9258 | // We do not complete this request, the dtor will clean the transaction up. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9259 | return trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9260 | } |
| 9261 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9262 | } // namespace |
| 9263 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9264 | TEST_F(HttpNetworkTransactionTest, GroupNameForDirectConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9265 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9266 | { |
| 9267 | "", // unused |
| 9268 | "http://www.example.org/direct", |
| 9269 | "www.example.org:80", |
| 9270 | false, |
| 9271 | }, |
| 9272 | { |
| 9273 | "", // unused |
| 9274 | "http://[2001:1418:13:1::25]/direct", |
| 9275 | "[2001:1418:13:1::25]:80", |
| 9276 | false, |
| 9277 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9278 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9279 | // SSL Tests |
| 9280 | { |
| 9281 | "", // unused |
| 9282 | "https://www.example.org/direct_ssl", |
| 9283 | "ssl/www.example.org:443", |
| 9284 | true, |
| 9285 | }, |
| 9286 | { |
| 9287 | "", // unused |
| 9288 | "https://[2001:1418:13:1::25]/direct", |
| 9289 | "ssl/[2001:1418:13:1::25]:443", |
| 9290 | true, |
| 9291 | }, |
| 9292 | { |
| 9293 | "", // unused |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9294 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9295 | "ssl/host.with.alternate:443", |
| 9296 | true, |
| 9297 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9298 | }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9299 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 9300 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9301 | session_deps_.proxy_service = |
| 9302 | ProxyService::CreateFixed(tests[i].proxy_server); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9303 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 9304 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9305 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9306 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9307 | CaptureGroupNameTransportSocketPool* transport_conn_pool = |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9308 | new CaptureGroupNameTransportSocketPool(nullptr, nullptr); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9309 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9310 | new CaptureGroupNameSSLSocketPool(nullptr, nullptr); |
| 9311 | auto mock_pool_manager = base::MakeUnique<MockClientSocketPoolManager>(); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 9312 | mock_pool_manager->SetTransportSocketPool(transport_conn_pool); |
| 9313 | mock_pool_manager->SetSSLSocketPool(ssl_conn_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 9314 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9315 | |
| 9316 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9317 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9318 | if (tests[i].ssl) |
| 9319 | EXPECT_EQ(tests[i].expected_group_name, |
| 9320 | ssl_conn_pool->last_group_name_received()); |
| 9321 | else |
| 9322 | EXPECT_EQ(tests[i].expected_group_name, |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9323 | transport_conn_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9324 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9325 | } |
| 9326 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9327 | TEST_F(HttpNetworkTransactionTest, GroupNameForHTTPProxyConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9328 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9329 | { |
| 9330 | "http_proxy", |
| 9331 | "http://www.example.org/http_proxy_normal", |
| 9332 | "www.example.org:80", |
| 9333 | false, |
| 9334 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9335 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9336 | // SSL Tests |
| 9337 | { |
| 9338 | "http_proxy", |
| 9339 | "https://www.example.org/http_connect_ssl", |
| 9340 | "ssl/www.example.org:443", |
| 9341 | true, |
| 9342 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 9343 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9344 | { |
| 9345 | "http_proxy", |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9346 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9347 | "ssl/host.with.alternate:443", |
| 9348 | true, |
| 9349 | }, |
[email protected] | 4549925 | 2013-01-23 17:12:56 | [diff] [blame] | 9350 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9351 | { |
| 9352 | "http_proxy", |
| 9353 | "ftp://ftp.google.com/http_proxy_normal", |
| 9354 | "ftp/ftp.google.com:21", |
| 9355 | false, |
| 9356 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9357 | }; |
| 9358 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 9359 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9360 | session_deps_.proxy_service = |
| 9361 | ProxyService::CreateFixed(tests[i].proxy_server); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9362 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 9363 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9364 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9365 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9366 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9367 | HostPortPair proxy_host("http_proxy", 80); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9368 | CaptureGroupNameHttpProxySocketPool* http_proxy_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9369 | new CaptureGroupNameHttpProxySocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9370 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9371 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9372 | auto mock_pool_manager = base::MakeUnique<MockClientSocketPoolManager>(); |
avi | adef344 | 2016-10-03 18:50:39 | [diff] [blame] | 9373 | mock_pool_manager->SetSocketPoolForHTTPProxy( |
| 9374 | proxy_host, base::WrapUnique(http_proxy_pool)); |
| 9375 | mock_pool_manager->SetSocketPoolForSSLWithProxy( |
| 9376 | proxy_host, base::WrapUnique(ssl_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 9377 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9378 | |
| 9379 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9380 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9381 | if (tests[i].ssl) |
| 9382 | EXPECT_EQ(tests[i].expected_group_name, |
| 9383 | ssl_conn_pool->last_group_name_received()); |
| 9384 | else |
| 9385 | EXPECT_EQ(tests[i].expected_group_name, |
| 9386 | http_proxy_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9387 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9388 | } |
| 9389 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9390 | TEST_F(HttpNetworkTransactionTest, GroupNameForSOCKSConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9391 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9392 | { |
| 9393 | "socks4://socks_proxy:1080", |
| 9394 | "http://www.example.org/socks4_direct", |
| 9395 | "socks4/www.example.org:80", |
| 9396 | false, |
| 9397 | }, |
| 9398 | { |
| 9399 | "socks5://socks_proxy:1080", |
| 9400 | "http://www.example.org/socks5_direct", |
| 9401 | "socks5/www.example.org:80", |
| 9402 | false, |
| 9403 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9404 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9405 | // SSL Tests |
| 9406 | { |
| 9407 | "socks4://socks_proxy:1080", |
| 9408 | "https://www.example.org/socks4_ssl", |
| 9409 | "socks4/ssl/www.example.org:443", |
| 9410 | true, |
| 9411 | }, |
| 9412 | { |
| 9413 | "socks5://socks_proxy:1080", |
| 9414 | "https://www.example.org/socks5_ssl", |
| 9415 | "socks5/ssl/www.example.org:443", |
| 9416 | true, |
| 9417 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 9418 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9419 | { |
| 9420 | "socks4://socks_proxy:1080", |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9421 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9422 | "socks4/ssl/host.with.alternate:443", |
| 9423 | true, |
| 9424 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9425 | }; |
| 9426 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 9427 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9428 | session_deps_.proxy_service = |
| 9429 | ProxyService::CreateFixed(tests[i].proxy_server); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9430 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 9431 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 9432 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9433 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9434 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9435 | HostPortPair proxy_host("socks_proxy", 1080); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9436 | CaptureGroupNameSOCKSSocketPool* socks_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9437 | new CaptureGroupNameSOCKSSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9438 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9439 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9440 | auto mock_pool_manager = base::MakeUnique<MockClientSocketPoolManager>(); |
avi | adef344 | 2016-10-03 18:50:39 | [diff] [blame] | 9441 | mock_pool_manager->SetSocketPoolForSOCKSProxy( |
| 9442 | proxy_host, base::WrapUnique(socks_conn_pool)); |
| 9443 | mock_pool_manager->SetSocketPoolForSSLWithProxy( |
| 9444 | proxy_host, base::WrapUnique(ssl_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 9445 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9446 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9447 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9448 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9449 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9450 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9451 | if (tests[i].ssl) |
| 9452 | EXPECT_EQ(tests[i].expected_group_name, |
| 9453 | ssl_conn_pool->last_group_name_received()); |
| 9454 | else |
| 9455 | EXPECT_EQ(tests[i].expected_group_name, |
| 9456 | socks_conn_pool->last_group_name_received()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9457 | } |
| 9458 | } |
| 9459 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9460 | TEST_F(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9461 | HttpRequestInfo request; |
| 9462 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9463 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9464 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9465 | session_deps_.proxy_service = |
| 9466 | ProxyService::CreateFixed("myproxy:70;foobar:80"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 9467 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 9468 | // This simulates failure resolving all hostnames; that means we will fail |
| 9469 | // connecting to both proxies (myproxy:70 and foobar:80). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9470 | session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 9471 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9472 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9473 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9474 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9475 | TestCompletionCallback callback; |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9476 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9477 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9478 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9479 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9480 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9481 | EXPECT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9482 | } |
| 9483 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9484 | // Base test to make sure that when the load flags for a request specify to |
| 9485 | // bypass the cache, the DNS cache is not used. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9486 | void HttpNetworkTransactionTest::BypassHostCacheOnRefreshHelper( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9487 | int load_flags) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9488 | // Issue a request, asking to bypass the cache(s). |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9489 | HttpRequestInfo request_info; |
| 9490 | request_info.method = "GET"; |
| 9491 | request_info.load_flags = load_flags; |
| 9492 | request_info.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9493 | |
[email protected] | a2c2fb9 | 2009-07-18 07:31:04 | [diff] [blame] | 9494 | // Select a host resolver that does caching. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9495 | session_deps_.host_resolver = base::MakeUnique<MockCachingHostResolver>(); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 9496 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9497 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9498 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9499 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9500 | // 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] | 9501 | AddressList addrlist; |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 9502 | TestCompletionCallback callback; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9503 | std::unique_ptr<HostResolver::Request> request1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9504 | int rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9505 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9506 | DEFAULT_PRIORITY, &addrlist, callback.callback(), &request1, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9507 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9508 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 9509 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9510 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9511 | |
| 9512 | // Verify that it was added to host cache, by doing a subsequent async lookup |
| 9513 | // and confirming it completes synchronously. |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9514 | std::unique_ptr<HostResolver::Request> request2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9515 | rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9516 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9517 | DEFAULT_PRIORITY, &addrlist, callback.callback(), &request2, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9518 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9519 | ASSERT_THAT(rv, IsOk()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9520 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9521 | // 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] | 9522 | // we can tell if the next lookup hit the cache, or the "network". |
| 9523 | // (cache --> success, "network" --> failure). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9524 | session_deps_.host_resolver->rules()->AddSimulatedFailure("www.example.org"); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9525 | |
| 9526 | // Connect up a mock socket which will fail with ERR_UNEXPECTED during the |
| 9527 | // 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] | 9528 | MockRead data_reads[] = { MockRead(SYNCHRONOUS, ERR_UNEXPECTED) }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9529 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9530 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9531 | |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9532 | // Run the request. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9533 | rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9534 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9535 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9536 | |
| 9537 | // If we bypassed the cache, we would have gotten a failure while resolving |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9538 | // "www.example.org". |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9539 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9540 | } |
| 9541 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9542 | // There are multiple load flags that should trigger the host cache bypass. |
| 9543 | // Test each in isolation: |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9544 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh1) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9545 | BypassHostCacheOnRefreshHelper(LOAD_BYPASS_CACHE); |
| 9546 | } |
| 9547 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9548 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh2) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9549 | BypassHostCacheOnRefreshHelper(LOAD_VALIDATE_CACHE); |
| 9550 | } |
| 9551 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9552 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh3) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9553 | BypassHostCacheOnRefreshHelper(LOAD_DISABLE_CACHE); |
| 9554 | } |
| 9555 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9556 | // Make sure we can handle an error when writing the request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9557 | TEST_F(HttpNetworkTransactionTest, RequestWriteError) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9558 | HttpRequestInfo request; |
| 9559 | request.method = "GET"; |
| 9560 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9561 | |
| 9562 | MockWrite write_failure[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9563 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9564 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9565 | StaticSocketDataProvider data(NULL, 0, |
| 9566 | write_failure, arraysize(write_failure)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9567 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9568 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9569 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9570 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9571 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9572 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9573 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9574 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9575 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9576 | |
| 9577 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9578 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9579 | |
| 9580 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9581 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9582 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9583 | } |
| 9584 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9585 | // Check that a connection closed after the start of the headers finishes ok. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9586 | TEST_F(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9587 | HttpRequestInfo request; |
| 9588 | request.method = "GET"; |
| 9589 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9590 | |
| 9591 | MockRead data_reads[] = { |
| 9592 | MockRead("HTTP/1."), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9593 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9594 | }; |
| 9595 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9596 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9597 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9598 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9599 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9600 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9601 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9602 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9603 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9604 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9605 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9606 | |
| 9607 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9608 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9609 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9610 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9611 | ASSERT_TRUE(response); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9612 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9613 | EXPECT_TRUE(response->headers); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9614 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 9615 | |
| 9616 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9617 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9618 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9619 | EXPECT_EQ("", response_data); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9620 | |
| 9621 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9622 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9623 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9624 | } |
| 9625 | |
| 9626 | // Make sure that a dropped connection while draining the body for auth |
| 9627 | // restart does the right thing. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9628 | TEST_F(HttpNetworkTransactionTest, DrainResetOK) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9629 | HttpRequestInfo request; |
| 9630 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9631 | request.url = GURL("http://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9632 | |
| 9633 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9634 | MockWrite( |
| 9635 | "GET / HTTP/1.1\r\n" |
| 9636 | "Host: www.example.org\r\n" |
| 9637 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9638 | }; |
| 9639 | |
| 9640 | MockRead data_reads1[] = { |
| 9641 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 9642 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9643 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9644 | MockRead("Content-Length: 14\r\n\r\n"), |
| 9645 | MockRead("Unauth"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9646 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9647 | }; |
| 9648 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9649 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 9650 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9651 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9652 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9653 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9654 | // be issuing -- the final header line contains the credentials. |
| 9655 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9656 | MockWrite( |
| 9657 | "GET / HTTP/1.1\r\n" |
| 9658 | "Host: www.example.org\r\n" |
| 9659 | "Connection: keep-alive\r\n" |
| 9660 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9661 | }; |
| 9662 | |
| 9663 | // Lastly, the server responds with the actual content. |
| 9664 | MockRead data_reads2[] = { |
| 9665 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9666 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9667 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9668 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9669 | }; |
| 9670 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9671 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 9672 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9673 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9674 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9675 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9676 | TestCompletionCallback callback1; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9677 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9678 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9679 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9680 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9681 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9682 | |
| 9683 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9684 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9685 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9686 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9687 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9688 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9689 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9690 | TestCompletionCallback callback2; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9691 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9692 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9693 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9694 | |
| 9695 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9696 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9697 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9698 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9699 | ASSERT_TRUE(response); |
| 9700 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9701 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9702 | } |
| 9703 | |
| 9704 | // Test HTTPS connections going through a proxy that sends extra data. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9705 | TEST_F(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9706 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9707 | |
| 9708 | HttpRequestInfo request; |
| 9709 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9710 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9711 | |
| 9712 | MockRead proxy_reads[] = { |
| 9713 | MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9714 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9715 | }; |
| 9716 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9717 | StaticSocketDataProvider data(proxy_reads, arraysize(proxy_reads), NULL, 0); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9718 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9719 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9720 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9721 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9722 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9723 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9724 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9725 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9726 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9727 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9728 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9729 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9730 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9731 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9732 | |
| 9733 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9734 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9735 | } |
| 9736 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9737 | TEST_F(HttpNetworkTransactionTest, LargeContentLengthThenClose) { |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9738 | HttpRequestInfo request; |
| 9739 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9740 | request.url = GURL("http://www.example.org/"); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9741 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9742 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9743 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9744 | |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 9745 | MockRead data_reads[] = { |
| 9746 | 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] | 9747 | MockRead(SYNCHRONOUS, OK), |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 9748 | }; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9749 | |
| 9750 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9751 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9752 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9753 | TestCompletionCallback callback; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9754 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9755 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9756 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9757 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9758 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9759 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9760 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9761 | ASSERT_TRUE(response); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9762 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9763 | EXPECT_TRUE(response->headers); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9764 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 9765 | |
| 9766 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9767 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9768 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 9769 | } |
| 9770 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9771 | TEST_F(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 9772 | base::FilePath temp_file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 9773 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path)); |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 9774 | const uint64_t kFakeSize = 100000; // file is actually blank |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 9775 | UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 9776 | overriding_content_length(kFakeSize); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9777 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9778 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 9779 | element_readers.push_back(base::MakeUnique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 9780 | base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 9781 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9782 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9783 | |
| 9784 | HttpRequestInfo request; |
| 9785 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9786 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9787 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9788 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9789 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9790 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9791 | |
| 9792 | MockRead data_reads[] = { |
| 9793 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 9794 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9795 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9796 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9797 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9798 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9799 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9800 | TestCompletionCallback callback; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9801 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9802 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9803 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9804 | |
| 9805 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9806 | EXPECT_THAT(rv, IsError(ERR_UPLOAD_FILE_CHANGED)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9807 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9808 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9809 | ASSERT_TRUE(response); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9810 | |
maksim.sisov | e869bf5 | 2016-06-23 17:11:52 | [diff] [blame] | 9811 | EXPECT_FALSE(response->headers); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9812 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 9813 | base::DeleteFile(temp_file_path, false); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9814 | } |
| 9815 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9816 | TEST_F(HttpNetworkTransactionTest, UploadUnreadableFile) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 9817 | base::FilePath temp_file; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 9818 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9819 | std::string temp_file_content("Unreadable file."); |
lazyboy | 8df84fc | 2017-04-12 02:12:48 | [diff] [blame] | 9820 | ASSERT_EQ(static_cast<int>(temp_file_content.length()), |
| 9821 | base::WriteFile(temp_file, temp_file_content.c_str(), |
| 9822 | temp_file_content.length())); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 9823 | ASSERT_TRUE(base::MakeFileUnreadable(temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9824 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9825 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 9826 | element_readers.push_back(base::MakeUnique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 9827 | base::ThreadTaskRunnerHandle::Get().get(), temp_file, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 9828 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9829 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9830 | |
| 9831 | HttpRequestInfo request; |
| 9832 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9833 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9834 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9835 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 9836 | // If we try to upload an unreadable file, the transaction should fail. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9837 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9838 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9839 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 9840 | StaticSocketDataProvider data(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9841 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9842 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9843 | TestCompletionCallback callback; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9844 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9845 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9846 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9847 | |
| 9848 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9849 | EXPECT_THAT(rv, IsError(ERR_ACCESS_DENIED)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9850 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 9851 | base::DeleteFile(temp_file, false); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9852 | } |
| 9853 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9854 | TEST_F(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9855 | class FakeUploadElementReader : public UploadElementReader { |
| 9856 | public: |
| 9857 | FakeUploadElementReader() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9858 | ~FakeUploadElementReader() override {} |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9859 | |
| 9860 | const CompletionCallback& callback() const { return callback_; } |
| 9861 | |
| 9862 | // UploadElementReader overrides: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9863 | int Init(const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9864 | callback_ = callback; |
| 9865 | return ERR_IO_PENDING; |
| 9866 | } |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 9867 | uint64_t GetContentLength() const override { return 0; } |
| 9868 | uint64_t BytesRemaining() const override { return 0; } |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9869 | int Read(IOBuffer* buf, |
| 9870 | int buf_length, |
| 9871 | const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9872 | return ERR_FAILED; |
| 9873 | } |
| 9874 | |
| 9875 | private: |
| 9876 | CompletionCallback callback_; |
| 9877 | }; |
| 9878 | |
| 9879 | FakeUploadElementReader* fake_reader = new FakeUploadElementReader; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9880 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
| 9881 | element_readers.push_back(base::WrapUnique(fake_reader)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9882 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9883 | |
| 9884 | HttpRequestInfo request; |
| 9885 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9886 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9887 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9888 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9889 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9890 | auto trans = |
| 9891 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9892 | |
| 9893 | StaticSocketDataProvider data; |
| 9894 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9895 | |
| 9896 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9897 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9898 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 9899 | base::RunLoop().RunUntilIdle(); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9900 | |
| 9901 | // Transaction is pending on request body initialization. |
| 9902 | ASSERT_FALSE(fake_reader->callback().is_null()); |
| 9903 | |
| 9904 | // Return Init()'s result after the transaction gets destroyed. |
| 9905 | trans.reset(); |
| 9906 | fake_reader->callback().Run(OK); // Should not crash. |
| 9907 | } |
| 9908 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9909 | // Tests that changes to Auth realms are treated like auth rejections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9910 | TEST_F(HttpNetworkTransactionTest, ChangeAuthRealms) { |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9911 | HttpRequestInfo request; |
| 9912 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9913 | request.url = GURL("http://www.example.org/"); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9914 | |
| 9915 | // First transaction will request a resource and receive a Basic challenge |
| 9916 | // with realm="first_realm". |
| 9917 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9918 | MockWrite( |
| 9919 | "GET / HTTP/1.1\r\n" |
| 9920 | "Host: www.example.org\r\n" |
| 9921 | "Connection: keep-alive\r\n" |
| 9922 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9923 | }; |
| 9924 | MockRead data_reads1[] = { |
| 9925 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 9926 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 9927 | "\r\n"), |
| 9928 | }; |
| 9929 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9930 | // After calling trans.RestartWithAuth(), provide an Authentication header |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9931 | // for first_realm. The server will reject and provide a challenge with |
| 9932 | // second_realm. |
| 9933 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9934 | MockWrite( |
| 9935 | "GET / HTTP/1.1\r\n" |
| 9936 | "Host: www.example.org\r\n" |
| 9937 | "Connection: keep-alive\r\n" |
| 9938 | "Authorization: Basic Zmlyc3Q6YmF6\r\n" |
| 9939 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9940 | }; |
| 9941 | MockRead data_reads2[] = { |
| 9942 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 9943 | "WWW-Authenticate: Basic realm=\"second_realm\"\r\n" |
| 9944 | "\r\n"), |
| 9945 | }; |
| 9946 | |
| 9947 | // This again fails, and goes back to first_realm. Make sure that the |
| 9948 | // entry is removed from cache. |
| 9949 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9950 | MockWrite( |
| 9951 | "GET / HTTP/1.1\r\n" |
| 9952 | "Host: www.example.org\r\n" |
| 9953 | "Connection: keep-alive\r\n" |
| 9954 | "Authorization: Basic c2Vjb25kOmZvdQ==\r\n" |
| 9955 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9956 | }; |
| 9957 | MockRead data_reads3[] = { |
| 9958 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 9959 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 9960 | "\r\n"), |
| 9961 | }; |
| 9962 | |
| 9963 | // Try one last time (with the correct password) and get the resource. |
| 9964 | MockWrite data_writes4[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9965 | MockWrite( |
| 9966 | "GET / HTTP/1.1\r\n" |
| 9967 | "Host: www.example.org\r\n" |
| 9968 | "Connection: keep-alive\r\n" |
| 9969 | "Authorization: Basic Zmlyc3Q6YmFy\r\n" |
| 9970 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9971 | }; |
| 9972 | MockRead data_reads4[] = { |
| 9973 | MockRead("HTTP/1.1 200 OK\r\n" |
| 9974 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9975 | "Content-Length: 5\r\n" |
| 9976 | "\r\n" |
| 9977 | "hello"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9978 | }; |
| 9979 | |
| 9980 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 9981 | data_writes1, arraysize(data_writes1)); |
| 9982 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 9983 | data_writes2, arraysize(data_writes2)); |
| 9984 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 9985 | data_writes3, arraysize(data_writes3)); |
| 9986 | StaticSocketDataProvider data4(data_reads4, arraysize(data_reads4), |
| 9987 | data_writes4, arraysize(data_writes4)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9988 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9989 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 9990 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 9991 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9992 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9993 | TestCompletionCallback callback1; |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9994 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9995 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9996 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9997 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9998 | // Issue the first request with Authorize headers. There should be a |
| 9999 | // password prompt for first_realm waiting to be filled in after the |
| 10000 | // transaction completes. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10001 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10002 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10003 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10004 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10005 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10006 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10007 | const AuthChallengeInfo* challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10008 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10009 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10010 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10011 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 10012 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10013 | |
| 10014 | // Issue the second request with an incorrect password. There should be a |
| 10015 | // password prompt for second_realm waiting to be filled in after the |
| 10016 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10017 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10018 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBaz), |
| 10019 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10020 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10021 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10022 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10023 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10024 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10025 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10026 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10027 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10028 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10029 | EXPECT_EQ("second_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 10030 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10031 | |
| 10032 | // Issue the third request with another incorrect password. There should be |
| 10033 | // a password prompt for first_realm waiting to be filled in. If the password |
| 10034 | // prompt is not present, it indicates that the HttpAuthCacheEntry for |
| 10035 | // first_realm was not correctly removed. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10036 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10037 | rv = trans.RestartWithAuth(AuthCredentials(kSecond, kFou), |
| 10038 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10039 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10040 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10041 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10042 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10043 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10044 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10045 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10046 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10047 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10048 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 10049 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10050 | |
| 10051 | // Issue the fourth request with the correct password and username. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10052 | TestCompletionCallback callback4; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10053 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBar), |
| 10054 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10055 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10056 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10057 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10058 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10059 | ASSERT_TRUE(response); |
| 10060 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10061 | } |
| 10062 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10063 | TEST_F(HttpNetworkTransactionTest, HonorAlternativeServiceHeader) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10064 | MockRead data_reads[] = { |
| 10065 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10066 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10067 | MockRead("\r\n"), |
| 10068 | MockRead("hello world"), |
| 10069 | MockRead(SYNCHRONOUS, OK), |
| 10070 | }; |
| 10071 | |
| 10072 | HttpRequestInfo request; |
| 10073 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10074 | request.url = GURL("https://www.example.org/"); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10075 | |
| 10076 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10077 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10078 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10079 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10080 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10081 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10082 | TestCompletionCallback callback; |
| 10083 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10084 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10085 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10086 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10087 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10088 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10089 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10090 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10091 | HttpServerProperties* http_server_properties = |
| 10092 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10093 | EXPECT_TRUE( |
| 10094 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10095 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10096 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10097 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10098 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10099 | ASSERT_TRUE(response); |
| 10100 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10101 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10102 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10103 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10104 | |
| 10105 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10106 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10107 | EXPECT_EQ("hello world", response_data); |
| 10108 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10109 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 10110 | http_server_properties->GetAlternativeServiceInfos(test_server); |
| 10111 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 10112 | AlternativeService alternative_service(kProtoHTTP2, "mail.example.org", 443); |
| 10113 | EXPECT_EQ(alternative_service, |
| 10114 | alternative_service_info_vector[0].alternative_service); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10115 | } |
| 10116 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10117 | // Regression test for https://crbug.com/615497. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10118 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10119 | DoNotParseAlternativeServiceHeaderOnInsecureRequest) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10120 | MockRead data_reads[] = { |
| 10121 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10122 | MockRead(kAlternativeServiceHttpHeader), |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10123 | MockRead("\r\n"), |
| 10124 | MockRead("hello world"), |
| 10125 | MockRead(SYNCHRONOUS, OK), |
| 10126 | }; |
| 10127 | |
| 10128 | HttpRequestInfo request; |
| 10129 | request.method = "GET"; |
| 10130 | request.url = GURL("http://www.example.org/"); |
| 10131 | request.load_flags = 0; |
| 10132 | |
| 10133 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 10134 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10135 | |
| 10136 | TestCompletionCallback callback; |
| 10137 | |
| 10138 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10139 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10140 | |
| 10141 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10142 | HttpServerProperties* http_server_properties = |
| 10143 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10144 | EXPECT_TRUE( |
| 10145 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10146 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10147 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10148 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10149 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10150 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10151 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10152 | ASSERT_TRUE(response); |
| 10153 | ASSERT_TRUE(response->headers); |
| 10154 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10155 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10156 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10157 | |
| 10158 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10159 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10160 | EXPECT_EQ("hello world", response_data); |
| 10161 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10162 | EXPECT_TRUE( |
| 10163 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10164 | } |
| 10165 | |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 10166 | // HTTP/2 Alternative Services should be disabled by default. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10167 | // TODO(bnc): Remove when https://crbug.com/615413 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10168 | TEST_F(HttpNetworkTransactionTest, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10169 | DisableHTTP2AlternativeServicesWithDifferentHost) { |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 10170 | session_deps_.enable_http2_alternative_service = false; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10171 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10172 | HttpRequestInfo request; |
| 10173 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10174 | request.url = GURL("https://www.example.org/"); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10175 | request.load_flags = 0; |
| 10176 | |
| 10177 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10178 | StaticSocketDataProvider first_data; |
| 10179 | first_data.set_connect_data(mock_connect); |
| 10180 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10181 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10182 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10183 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10184 | |
| 10185 | MockRead data_reads[] = { |
| 10186 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 10187 | MockRead(ASYNC, OK), |
| 10188 | }; |
| 10189 | StaticSocketDataProvider second_data(data_reads, arraysize(data_reads), NULL, |
| 10190 | 0); |
| 10191 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 10192 | |
| 10193 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10194 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10195 | HttpServerProperties* http_server_properties = |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10196 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10197 | AlternativeService alternative_service(kProtoHTTP2, "different.example.org", |
| 10198 | 444); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10199 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 10200 | http_server_properties->SetAlternativeService( |
| 10201 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 10202 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10203 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10204 | TestCompletionCallback callback; |
| 10205 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10206 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10207 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10208 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10209 | } |
| 10210 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10211 | // Regression test for https://crbug.com/615497: |
| 10212 | // Alternative Services should be disabled for http origin. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10213 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10214 | DisableAlternativeServicesForInsecureOrigin) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10215 | HttpRequestInfo request; |
| 10216 | request.method = "GET"; |
| 10217 | request.url = GURL("http://www.example.org/"); |
| 10218 | request.load_flags = 0; |
| 10219 | |
| 10220 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10221 | StaticSocketDataProvider first_data; |
| 10222 | first_data.set_connect_data(mock_connect); |
| 10223 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
| 10224 | |
| 10225 | MockRead data_reads[] = { |
| 10226 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 10227 | MockRead(ASYNC, OK), |
| 10228 | }; |
| 10229 | StaticSocketDataProvider second_data(data_reads, arraysize(data_reads), NULL, |
| 10230 | 0); |
| 10231 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 10232 | |
| 10233 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10234 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10235 | HttpServerProperties* http_server_properties = |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10236 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10237 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10238 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 10239 | http_server_properties->SetAlternativeService( |
| 10240 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 10241 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10242 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10243 | TestCompletionCallback callback; |
| 10244 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10245 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10246 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10247 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10248 | } |
| 10249 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10250 | TEST_F(HttpNetworkTransactionTest, ClearAlternativeServices) { |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10251 | // Set an alternative service for origin. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10252 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10253 | HttpServerProperties* http_server_properties = |
| 10254 | session->http_server_properties(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10255 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10256 | AlternativeService alternative_service(kProtoQUIC, "", 80); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10257 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10258 | http_server_properties->SetAlternativeService( |
| 10259 | test_server, alternative_service, expiration); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10260 | EXPECT_EQ( |
| 10261 | 1u, |
| 10262 | http_server_properties->GetAlternativeServiceInfos(test_server).size()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10263 | |
| 10264 | // Send a clear header. |
| 10265 | MockRead data_reads[] = { |
| 10266 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10267 | MockRead("Alt-Svc: clear\r\n"), |
| 10268 | MockRead("\r\n"), |
| 10269 | MockRead("hello world"), |
| 10270 | MockRead(SYNCHRONOUS, OK), |
| 10271 | }; |
| 10272 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 10273 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10274 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10275 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10276 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10277 | |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10278 | HttpRequestInfo request; |
| 10279 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10280 | request.url = GURL("https://www.example.org/"); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10281 | |
| 10282 | TestCompletionCallback callback; |
| 10283 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10284 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10285 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10286 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10287 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10288 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10289 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10290 | ASSERT_TRUE(response); |
| 10291 | ASSERT_TRUE(response->headers); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10292 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10293 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10294 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10295 | |
| 10296 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10297 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10298 | EXPECT_EQ("hello world", response_data); |
| 10299 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10300 | EXPECT_TRUE( |
| 10301 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10302 | } |
| 10303 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10304 | TEST_F(HttpNetworkTransactionTest, HonorMultipleAlternativeServiceHeaders) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10305 | MockRead data_reads[] = { |
| 10306 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10307 | MockRead("Alt-Svc: h2=\"www.example.com:443\","), |
| 10308 | MockRead("h2=\":1234\"\r\n\r\n"), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10309 | MockRead("hello world"), |
| 10310 | MockRead(SYNCHRONOUS, OK), |
| 10311 | }; |
| 10312 | |
| 10313 | HttpRequestInfo request; |
| 10314 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10315 | request.url = GURL("https://www.example.org/"); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10316 | |
| 10317 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10318 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10319 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10320 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10321 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10322 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10323 | TestCompletionCallback callback; |
| 10324 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10325 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10326 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10327 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10328 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10329 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10330 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10331 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10332 | HttpServerProperties* http_server_properties = |
| 10333 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10334 | EXPECT_TRUE( |
| 10335 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10336 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10337 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10338 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10339 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10340 | ASSERT_TRUE(response); |
| 10341 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10342 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10343 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10344 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10345 | |
| 10346 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10347 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10348 | EXPECT_EQ("hello world", response_data); |
| 10349 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10350 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 10351 | http_server_properties->GetAlternativeServiceInfos(test_server); |
| 10352 | ASSERT_EQ(2u, alternative_service_info_vector.size()); |
| 10353 | |
| 10354 | AlternativeService alternative_service(kProtoHTTP2, "www.example.com", 443); |
| 10355 | EXPECT_EQ(alternative_service, |
| 10356 | alternative_service_info_vector[0].alternative_service); |
| 10357 | AlternativeService alternative_service_2(kProtoHTTP2, "www.example.org", |
| 10358 | 1234); |
| 10359 | EXPECT_EQ(alternative_service_2, |
| 10360 | alternative_service_info_vector[1].alternative_service); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10361 | } |
| 10362 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10363 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10364 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10365 | HostPortPair alternative("alternative.example.org", 443); |
| 10366 | std::string origin_url = "https://origin.example.org:443"; |
| 10367 | std::string alternative_url = "https://alternative.example.org:443"; |
| 10368 | |
| 10369 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 10370 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10371 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10372 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10373 | |
| 10374 | // HTTP/1.1 data for request. |
| 10375 | MockWrite http_writes[] = { |
| 10376 | MockWrite("GET / HTTP/1.1\r\n" |
| 10377 | "Host: alternative.example.org\r\n" |
| 10378 | "Connection: keep-alive\r\n\r\n"), |
| 10379 | }; |
| 10380 | |
| 10381 | MockRead http_reads[] = { |
| 10382 | MockRead("HTTP/1.1 200 OK\r\n" |
| 10383 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10384 | "Content-Length: 40\r\n\r\n" |
| 10385 | "first HTTP/1.1 response from alternative"), |
| 10386 | }; |
| 10387 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 10388 | http_writes, arraysize(http_writes)); |
| 10389 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 10390 | |
| 10391 | StaticSocketDataProvider data_refused; |
| 10392 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 10393 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 10394 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10395 | // Set up a QUIC alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10396 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10397 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10398 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10399 | AlternativeService alternative_service(kProtoQUIC, alternative); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10400 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10401 | http_server_properties->SetAlternativeService(server, alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10402 | expiration); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10403 | // Mark the QUIC alternative service as broken. |
| 10404 | http_server_properties->MarkAlternativeServiceBroken(alternative_service); |
| 10405 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10406 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 10407 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10408 | request.method = "GET"; |
| 10409 | request.url = GURL(origin_url); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10410 | TestCompletionCallback callback; |
| 10411 | NetErrorDetails details; |
| 10412 | EXPECT_FALSE(details.quic_broken); |
| 10413 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10414 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10415 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10416 | EXPECT_TRUE(details.quic_broken); |
| 10417 | } |
| 10418 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10419 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicNotBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10420 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10421 | HostPortPair alternative1("alternative1.example.org", 443); |
| 10422 | HostPortPair alternative2("alternative2.example.org", 443); |
| 10423 | std::string origin_url = "https://origin.example.org:443"; |
| 10424 | std::string alternative_url1 = "https://alternative1.example.org:443"; |
| 10425 | std::string alternative_url2 = "https://alternative2.example.org:443"; |
| 10426 | |
| 10427 | // Negotiate HTTP/1.1 with alternative1.example.org. |
| 10428 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10429 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10430 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10431 | |
| 10432 | // HTTP/1.1 data for request. |
| 10433 | MockWrite http_writes[] = { |
| 10434 | MockWrite("GET / HTTP/1.1\r\n" |
| 10435 | "Host: alternative1.example.org\r\n" |
| 10436 | "Connection: keep-alive\r\n\r\n"), |
| 10437 | }; |
| 10438 | |
| 10439 | MockRead http_reads[] = { |
| 10440 | MockRead("HTTP/1.1 200 OK\r\n" |
| 10441 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10442 | "Content-Length: 40\r\n\r\n" |
| 10443 | "first HTTP/1.1 response from alternative1"), |
| 10444 | }; |
| 10445 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 10446 | http_writes, arraysize(http_writes)); |
| 10447 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 10448 | |
| 10449 | StaticSocketDataProvider data_refused; |
| 10450 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 10451 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 10452 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10453 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10454 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10455 | session->http_server_properties(); |
| 10456 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10457 | // Set up two QUIC alternative services for server. |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10458 | AlternativeServiceInfoVector alternative_service_info_vector; |
| 10459 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 10460 | |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10461 | AlternativeService alternative_service1(kProtoQUIC, alternative1); |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10462 | AlternativeServiceInfo alternative_service_info1(alternative_service1, |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10463 | expiration); |
| 10464 | alternative_service_info_vector.push_back(alternative_service_info1); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10465 | AlternativeService alternative_service2(kProtoQUIC, alternative2); |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10466 | AlternativeServiceInfo alternative_service_info2(alternative_service2, |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10467 | expiration); |
| 10468 | alternative_service_info_vector.push_back(alternative_service_info2); |
| 10469 | |
| 10470 | http_server_properties->SetAlternativeServices( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10471 | server, alternative_service_info_vector); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10472 | |
| 10473 | // Mark one of the QUIC alternative service as broken. |
| 10474 | http_server_properties->MarkAlternativeServiceBroken(alternative_service1); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10475 | EXPECT_EQ(2u, |
| 10476 | http_server_properties->GetAlternativeServiceInfos(server).size()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10477 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10478 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 10479 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10480 | request.method = "GET"; |
| 10481 | request.url = GURL(origin_url); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10482 | TestCompletionCallback callback; |
| 10483 | NetErrorDetails details; |
| 10484 | EXPECT_FALSE(details.quic_broken); |
| 10485 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10486 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10487 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10488 | EXPECT_FALSE(details.quic_broken); |
| 10489 | } |
| 10490 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10491 | TEST_F(HttpNetworkTransactionTest, MarkBrokenAlternateProtocolAndFallback) { |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10492 | HttpRequestInfo request; |
| 10493 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10494 | request.url = GURL("https://www.example.org/"); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10495 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10496 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10497 | StaticSocketDataProvider first_data; |
| 10498 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10499 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10500 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10501 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10502 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10503 | |
| 10504 | MockRead data_reads[] = { |
| 10505 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10506 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10507 | MockRead(ASYNC, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10508 | }; |
| 10509 | StaticSocketDataProvider second_data( |
| 10510 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10511 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10512 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10513 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10514 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10515 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10516 | session->http_server_properties(); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10517 | const url::SchemeHostPort server(request.url); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10518 | // Port must be < 1024, or the header will be ignored (since initial port was |
| 10519 | // port 80 (another restricted port). |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 10520 | const AlternativeService alternative_service( |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10521 | kProtoHTTP2, "www.example.org", |
bnc | d9b132e | 2015-07-08 05:16:10 | [diff] [blame] | 10522 | 666); // Port is ignored by MockConnect anyway. |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10523 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10524 | http_server_properties->SetAlternativeService(server, alternative_service, |
| 10525 | expiration); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10526 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10527 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10528 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10529 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10530 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10531 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10532 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10533 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10534 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10535 | ASSERT_TRUE(response); |
| 10536 | ASSERT_TRUE(response->headers); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10537 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10538 | |
| 10539 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10540 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10541 | EXPECT_EQ("hello world", response_data); |
| 10542 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10543 | const AlternativeServiceInfoVector alternative_service_info_vector = |
| 10544 | http_server_properties->GetAlternativeServiceInfos(server); |
| 10545 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 10546 | EXPECT_EQ(alternative_service, |
| 10547 | alternative_service_info_vector[0].alternative_service); |
| 10548 | EXPECT_TRUE( |
| 10549 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10550 | } |
| 10551 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10552 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10553 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10554 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10555 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10556 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedBlocked) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10557 | HttpRequestInfo restricted_port_request; |
| 10558 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10559 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10560 | restricted_port_request.load_flags = 0; |
| 10561 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10562 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10563 | StaticSocketDataProvider first_data; |
| 10564 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10565 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10566 | |
| 10567 | MockRead data_reads[] = { |
| 10568 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10569 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10570 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10571 | }; |
| 10572 | StaticSocketDataProvider second_data( |
| 10573 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10574 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10575 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10576 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10577 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10578 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10579 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10580 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10581 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10582 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10583 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10584 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 10585 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10586 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10587 | http_server_properties->SetAlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10588 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10589 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10590 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10591 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10592 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10593 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10594 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 10595 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10596 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10597 | // Invalid change to unrestricted port should fail. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10598 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_REFUSED)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10599 | } |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10600 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10601 | // Ensure that we are allowed to redirect traffic via an alternate protocol to |
| 10602 | // an unrestricted (port >= 1024) when the original traffic was on a restricted |
| 10603 | // port (port < 1024) if we set |enable_user_alternate_protocol_ports|. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10604 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedPermitted) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10605 | session_deps_.enable_user_alternate_protocol_ports = true; |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10606 | |
| 10607 | HttpRequestInfo restricted_port_request; |
| 10608 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10609 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10610 | restricted_port_request.load_flags = 0; |
| 10611 | |
| 10612 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10613 | StaticSocketDataProvider first_data; |
| 10614 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10615 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10616 | |
| 10617 | MockRead data_reads[] = { |
| 10618 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10619 | MockRead("hello world"), |
| 10620 | MockRead(ASYNC, OK), |
| 10621 | }; |
| 10622 | StaticSocketDataProvider second_data( |
| 10623 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10624 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10625 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10626 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10627 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10628 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10629 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10630 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10631 | HttpServerProperties* http_server_properties = |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10632 | session->http_server_properties(); |
| 10633 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10634 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 10635 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10636 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10637 | http_server_properties->SetAlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10638 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10639 | expiration); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10640 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10641 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10642 | TestCompletionCallback callback; |
| 10643 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10644 | EXPECT_EQ(ERR_IO_PENDING, |
| 10645 | trans.Start(&restricted_port_request, callback.callback(), |
| 10646 | NetLogWithSource())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10647 | // Change to unrestricted port should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10648 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10649 | } |
| 10650 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10651 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10652 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10653 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10654 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10655 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedAllowed) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10656 | HttpRequestInfo restricted_port_request; |
| 10657 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10658 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10659 | restricted_port_request.load_flags = 0; |
| 10660 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10661 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10662 | StaticSocketDataProvider first_data; |
| 10663 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10664 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10665 | |
| 10666 | MockRead data_reads[] = { |
| 10667 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10668 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10669 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10670 | }; |
| 10671 | StaticSocketDataProvider second_data( |
| 10672 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10673 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10674 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10675 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10676 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10677 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10678 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10679 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10680 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10681 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10682 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10683 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 10684 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10685 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10686 | http_server_properties->SetAlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10687 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10688 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10689 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10690 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10691 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10692 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10693 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 10694 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10695 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10696 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10697 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10698 | } |
| 10699 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10700 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10701 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10702 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10703 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10704 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed1) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10705 | HttpRequestInfo unrestricted_port_request; |
| 10706 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10707 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10708 | unrestricted_port_request.load_flags = 0; |
| 10709 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10710 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10711 | StaticSocketDataProvider first_data; |
| 10712 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10713 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10714 | |
| 10715 | MockRead data_reads[] = { |
| 10716 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10717 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10718 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10719 | }; |
| 10720 | StaticSocketDataProvider second_data( |
| 10721 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10722 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10723 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10724 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10725 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10726 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10727 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10728 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10729 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10730 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10731 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10732 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 10733 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10734 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10735 | http_server_properties->SetAlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10736 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10737 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10738 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10739 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10740 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10741 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10742 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10743 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10744 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10745 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10746 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10747 | } |
| 10748 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10749 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10750 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10751 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10752 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10753 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed2) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10754 | HttpRequestInfo unrestricted_port_request; |
| 10755 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10756 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10757 | unrestricted_port_request.load_flags = 0; |
| 10758 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10759 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10760 | StaticSocketDataProvider first_data; |
| 10761 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10762 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10763 | |
| 10764 | MockRead data_reads[] = { |
| 10765 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10766 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10767 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10768 | }; |
| 10769 | StaticSocketDataProvider second_data( |
| 10770 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10771 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10772 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10773 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10774 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10775 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10776 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10777 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10778 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10779 | session->http_server_properties(); |
bnc | 0bbb0262 | 2015-07-23 10:06:22 | [diff] [blame] | 10780 | const int kUnrestrictedAlternatePort = 1025; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10781 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 10782 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10783 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10784 | http_server_properties->SetAlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10785 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10786 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10787 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10788 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10789 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10790 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10791 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10792 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10793 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10794 | // Valid change to an unrestricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10795 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10796 | } |
| 10797 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10798 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10799 | // to an unsafe port, and that we resume the second HttpStreamFactoryImpl::Job |
| 10800 | // once the alternate protocol request fails. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10801 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) { |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10802 | HttpRequestInfo request; |
| 10803 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10804 | request.url = GURL("http://www.example.org/"); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10805 | |
| 10806 | // The alternate protocol request will error out before we attempt to connect, |
| 10807 | // so only the standard HTTP request will try to connect. |
| 10808 | MockRead data_reads[] = { |
| 10809 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10810 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10811 | MockRead(ASYNC, OK), |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10812 | }; |
| 10813 | StaticSocketDataProvider data( |
| 10814 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10815 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10816 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10817 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10818 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10819 | HttpServerProperties* http_server_properties = |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10820 | session->http_server_properties(); |
| 10821 | const int kUnsafePort = 7; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10822 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 10823 | kUnsafePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10824 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
bnc | cacc099 | 2015-03-20 20:22:22 | [diff] [blame] | 10825 | http_server_properties->SetAlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10826 | url::SchemeHostPort(request.url), alternative_service, expiration); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10827 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10828 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10829 | TestCompletionCallback callback; |
| 10830 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10831 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10832 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10833 | // The HTTP request should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10834 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10835 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10836 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10837 | ASSERT_TRUE(response); |
| 10838 | ASSERT_TRUE(response->headers); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10839 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10840 | |
| 10841 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10842 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10843 | EXPECT_EQ("hello world", response_data); |
| 10844 | } |
| 10845 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10846 | TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10847 | HttpRequestInfo request; |
| 10848 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10849 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10850 | |
| 10851 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10852 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10853 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10854 | MockRead("\r\n"), |
| 10855 | MockRead("hello world"), |
| 10856 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 10857 | MockRead(ASYNC, OK)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10858 | |
| 10859 | StaticSocketDataProvider first_transaction( |
| 10860 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10861 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10862 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10863 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10864 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10865 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 10866 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10867 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10868 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10869 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10870 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10871 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 10872 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10873 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10874 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10875 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10876 | }; |
| 10877 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10878 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 10879 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10880 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10881 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10882 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10883 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 10884 | NULL, 0, NULL, 0); |
| 10885 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 10886 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10887 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10888 | &hanging_non_alternate_protocol_socket); |
| 10889 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10890 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10891 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10892 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10893 | auto trans = |
| 10894 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10895 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10896 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10897 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10898 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10899 | |
| 10900 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10901 | ASSERT_TRUE(response); |
| 10902 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10903 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10904 | |
| 10905 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10906 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10907 | EXPECT_EQ("hello world", response_data); |
| 10908 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10909 | trans = |
| 10910 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10911 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10912 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10913 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10914 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10915 | |
| 10916 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10917 | ASSERT_TRUE(response); |
| 10918 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 10919 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 10920 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10921 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10922 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10923 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10924 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10925 | } |
| 10926 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10927 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10928 | HttpRequestInfo request; |
| 10929 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10930 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10931 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10932 | // First transaction receives Alt-Svc header over HTTP/1.1. |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10933 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10934 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10935 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10936 | MockRead("\r\n"), |
| 10937 | MockRead("hello world"), |
| 10938 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 10939 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10940 | }; |
| 10941 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10942 | StaticSocketDataProvider http11_data(data_reads, arraysize(data_reads), NULL, |
| 10943 | 0); |
| 10944 | session_deps_.socket_factory->AddSocketDataProvider(&http11_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10945 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10946 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
| 10947 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
| 10948 | |
| 10949 | // Second transaction starts an alternative and a non-alternative Job. |
| 10950 | // Both sockets hang. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10951 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 10952 | StaticSocketDataProvider hanging_socket1(NULL, 0, NULL, 0); |
| 10953 | hanging_socket1.set_connect_data(never_finishing_connect); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 10954 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket1); |
| 10955 | |
| 10956 | StaticSocketDataProvider hanging_socket2(NULL, 0, NULL, 0); |
| 10957 | hanging_socket2.set_connect_data(never_finishing_connect); |
| 10958 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket2); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10959 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10960 | // Third transaction starts an alternative and a non-alternative job. |
| 10961 | // The non-alternative job hangs, but the alternative one succeeds. |
| 10962 | // The second transaction, still pending, binds to this socket. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10963 | SpdySerializedFrame req1( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10964 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10965 | SpdySerializedFrame req2( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10966 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 3, LOWEST)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10967 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10968 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 1), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10969 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 10970 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10971 | SpdySerializedFrame data1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 10972 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10973 | SpdySerializedFrame data2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10974 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10975 | CreateMockRead(resp1, 2), CreateMockRead(data1, 3), |
| 10976 | CreateMockRead(resp2, 4), CreateMockRead(data2, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10977 | MockRead(ASYNC, 0, 6), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10978 | }; |
| 10979 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10980 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 10981 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10982 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10983 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 10984 | AddSSLSocketData(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10985 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 10986 | StaticSocketDataProvider hanging_socket3(NULL, 0, NULL, 0); |
| 10987 | hanging_socket3.set_connect_data(never_finishing_connect); |
| 10988 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket3); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10989 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10990 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10991 | TestCompletionCallback callback1; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10992 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10993 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10994 | int rv = trans1.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10995 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10996 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 10997 | |
| 10998 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10999 | ASSERT_TRUE(response); |
| 11000 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11001 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11002 | |
| 11003 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11004 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11005 | EXPECT_EQ("hello world", response_data); |
| 11006 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11007 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11008 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11009 | rv = trans2.Start(&request, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11010 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11011 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11012 | TestCompletionCallback callback3; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11013 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11014 | rv = trans3.Start(&request, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11015 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11016 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11017 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
| 11018 | EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11019 | |
| 11020 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11021 | ASSERT_TRUE(response); |
| 11022 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11023 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11024 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11025 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11026 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11027 | EXPECT_EQ("hello!", response_data); |
| 11028 | |
| 11029 | response = trans3.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11030 | ASSERT_TRUE(response); |
| 11031 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11032 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11033 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11034 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11035 | ASSERT_THAT(ReadTransaction(&trans3, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11036 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11037 | } |
| 11038 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11039 | TEST_F(HttpNetworkTransactionTest, StallAlternativeServiceForNpnSpdy) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11040 | HttpRequestInfo request; |
| 11041 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11042 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11043 | |
| 11044 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11045 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11046 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11047 | MockRead("\r\n"), |
| 11048 | MockRead("hello world"), |
| 11049 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11050 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11051 | }; |
| 11052 | |
| 11053 | StaticSocketDataProvider first_transaction( |
| 11054 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11055 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11056 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11057 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11058 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11059 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11060 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11061 | StaticSocketDataProvider hanging_alternate_protocol_socket( |
| 11062 | NULL, 0, NULL, 0); |
| 11063 | hanging_alternate_protocol_socket.set_connect_data( |
| 11064 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11065 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11066 | &hanging_alternate_protocol_socket); |
| 11067 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11068 | // 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] | 11069 | StaticSocketDataProvider second_transaction(data_reads, arraysize(data_reads), |
| 11070 | NULL, 0); |
| 11071 | session_deps_.socket_factory->AddSocketDataProvider(&second_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11072 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11073 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11074 | TestCompletionCallback callback; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11075 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11076 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11077 | auto trans = |
| 11078 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11079 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11080 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11081 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11082 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11083 | |
| 11084 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11085 | ASSERT_TRUE(response); |
| 11086 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11087 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11088 | |
| 11089 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11090 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11091 | EXPECT_EQ("hello world", response_data); |
| 11092 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11093 | trans = |
| 11094 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11095 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11096 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11097 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11098 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11099 | |
| 11100 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11101 | ASSERT_TRUE(response); |
| 11102 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11103 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11104 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11105 | EXPECT_FALSE(response->was_alpn_negotiated); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11106 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11107 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11108 | EXPECT_EQ("hello world", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11109 | } |
| 11110 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11111 | class CapturingProxyResolver : public ProxyResolver { |
| 11112 | public: |
sammc | e90c921 | 2015-05-27 23:43:35 | [diff] [blame] | 11113 | CapturingProxyResolver() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11114 | ~CapturingProxyResolver() override {} |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11115 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11116 | int GetProxyForURL(const GURL& url, |
| 11117 | ProxyInfo* results, |
| 11118 | const CompletionCallback& callback, |
maksim.sisov | 7e15726 | 2016-10-20 11:19:55 | [diff] [blame] | 11119 | std::unique_ptr<Request>* request, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11120 | const NetLogWithSource& net_log) override { |
[email protected] | fae7669f | 2010-08-02 21:49:40 | [diff] [blame] | 11121 | ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, |
| 11122 | HostPortPair("myproxy", 80)); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11123 | results->UseProxyServer(proxy_server); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11124 | resolved_.push_back(url); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11125 | return OK; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11126 | } |
| 11127 | |
[email protected] | 2447640 | 2010-07-20 20:55:17 | [diff] [blame] | 11128 | const std::vector<GURL>& resolved() const { return resolved_; } |
| 11129 | |
| 11130 | private: |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11131 | std::vector<GURL> resolved_; |
| 11132 | |
| 11133 | DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); |
| 11134 | }; |
| 11135 | |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 11136 | class CapturingProxyResolverFactory : public ProxyResolverFactory { |
| 11137 | public: |
| 11138 | explicit CapturingProxyResolverFactory(CapturingProxyResolver* resolver) |
| 11139 | : ProxyResolverFactory(false), resolver_(resolver) {} |
| 11140 | |
| 11141 | int CreateProxyResolver( |
| 11142 | const scoped_refptr<ProxyResolverScriptData>& pac_script, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11143 | std::unique_ptr<ProxyResolver>* resolver, |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 11144 | const net::CompletionCallback& callback, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11145 | std::unique_ptr<Request>* request) override { |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11146 | *resolver = base::MakeUnique<ForwardingProxyResolver>(resolver_); |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 11147 | return OK; |
| 11148 | } |
| 11149 | |
| 11150 | private: |
| 11151 | ProxyResolver* resolver_; |
| 11152 | }; |
| 11153 | |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11154 | // Test that proxy is resolved using the origin url, |
| 11155 | // regardless of the alternative server. |
| 11156 | TEST_F(HttpNetworkTransactionTest, UseOriginNotAlternativeForProxy) { |
| 11157 | // Configure proxy to bypass www.example.org, which is the origin URL. |
| 11158 | ProxyConfig proxy_config; |
| 11159 | proxy_config.proxy_rules().ParseFromString("myproxy:70"); |
| 11160 | proxy_config.proxy_rules().bypass_rules.AddRuleFromString("www.example.org"); |
| 11161 | auto proxy_config_service = |
| 11162 | base::MakeUnique<ProxyConfigServiceFixed>(proxy_config); |
| 11163 | |
| 11164 | CapturingProxyResolver capturing_proxy_resolver; |
| 11165 | auto proxy_resolver_factory = base::MakeUnique<CapturingProxyResolverFactory>( |
| 11166 | &capturing_proxy_resolver); |
| 11167 | |
| 11168 | TestNetLog net_log; |
| 11169 | |
| 11170 | session_deps_.proxy_service = base::MakeUnique<ProxyService>( |
| 11171 | std::move(proxy_config_service), std::move(proxy_resolver_factory), |
| 11172 | &net_log); |
| 11173 | |
| 11174 | session_deps_.net_log = &net_log; |
| 11175 | |
| 11176 | // Configure alternative service with a hostname that is not bypassed by the |
| 11177 | // proxy. |
| 11178 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11179 | HttpServerProperties* http_server_properties = |
| 11180 | session->http_server_properties(); |
| 11181 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 11182 | HostPortPair alternative("www.example.com", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11183 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11184 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 11185 | http_server_properties->SetAlternativeService(server, alternative_service, |
| 11186 | expiration); |
| 11187 | |
| 11188 | // Non-alternative job should hang. |
| 11189 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
| 11190 | StaticSocketDataProvider hanging_alternate_protocol_socket(nullptr, 0, |
| 11191 | nullptr, 0); |
| 11192 | hanging_alternate_protocol_socket.set_connect_data(never_finishing_connect); |
| 11193 | session_deps_.socket_factory->AddSocketDataProvider( |
| 11194 | &hanging_alternate_protocol_socket); |
| 11195 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11196 | AddSSLSocketData(); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11197 | |
| 11198 | HttpRequestInfo request; |
| 11199 | request.method = "GET"; |
| 11200 | request.url = GURL("https://www.example.org/"); |
| 11201 | request.load_flags = 0; |
| 11202 | |
| 11203 | SpdySerializedFrame req( |
| 11204 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
| 11205 | |
| 11206 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
| 11207 | |
| 11208 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 11209 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 11210 | MockRead spdy_reads[] = { |
| 11211 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
| 11212 | }; |
| 11213 | |
| 11214 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11215 | arraysize(spdy_writes)); |
| 11216 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 11217 | |
| 11218 | TestCompletionCallback callback; |
| 11219 | |
| 11220 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 11221 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11222 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11223 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 11224 | |
| 11225 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 11226 | ASSERT_TRUE(response); |
| 11227 | ASSERT_TRUE(response->headers); |
| 11228 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 11229 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11230 | EXPECT_TRUE(response->was_alpn_negotiated); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11231 | |
| 11232 | std::string response_data; |
| 11233 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 11234 | EXPECT_EQ("hello!", response_data); |
| 11235 | |
| 11236 | // Origin host bypasses proxy, no resolution should have happened. |
| 11237 | ASSERT_TRUE(capturing_proxy_resolver.resolved().empty()); |
| 11238 | } |
| 11239 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11240 | TEST_F(HttpNetworkTransactionTest, UseAlternativeServiceForTunneledNpnSpdy) { |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11241 | ProxyConfig proxy_config; |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11242 | proxy_config.set_auto_detect(true); |
| 11243 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 11244 | |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11245 | CapturingProxyResolver capturing_proxy_resolver; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11246 | session_deps_.proxy_service = base::MakeUnique<ProxyService>( |
| 11247 | base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), |
| 11248 | base::MakeUnique<CapturingProxyResolverFactory>( |
| 11249 | &capturing_proxy_resolver), |
| 11250 | nullptr); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11251 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11252 | session_deps_.net_log = &net_log; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11253 | |
| 11254 | HttpRequestInfo request; |
| 11255 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11256 | request.url = GURL("https://www.example.org/"); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11257 | |
| 11258 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11259 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11260 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11261 | MockRead("\r\n"), |
| 11262 | MockRead("hello world"), |
| 11263 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11264 | MockRead(ASYNC, OK), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11265 | }; |
| 11266 | |
| 11267 | StaticSocketDataProvider first_transaction( |
| 11268 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11269 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11270 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11271 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11272 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11273 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11274 | AddSSLSocketData(); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11275 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11276 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11277 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11278 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11279 | MockWrite(ASYNC, 0, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11280 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 11281 | "Host: www.example.org:443\r\n" |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11282 | "Proxy-Connection: keep-alive\r\n\r\n"), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11283 | CreateMockWrite(req, 2), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11284 | }; |
| 11285 | |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11286 | const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 11287 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 11288 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11289 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11290 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11291 | MockRead(ASYNC, 1, kCONNECTResponse), CreateMockRead(resp, 3), |
| 11292 | CreateMockRead(data, 4), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11293 | }; |
| 11294 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11295 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11296 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11297 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11298 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11299 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11300 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 11301 | NULL, 0, NULL, 0); |
| 11302 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 11303 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11304 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11305 | &hanging_non_alternate_protocol_socket); |
| 11306 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11307 | TestCompletionCallback callback; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11308 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11309 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11310 | auto trans = |
| 11311 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11312 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11313 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 11314 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11315 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 11316 | |
| 11317 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 11318 | ASSERT_TRUE(response); |
| 11319 | ASSERT_TRUE(response->headers); |
| 11320 | EXPECT_EQ("HTTP/0.9 200 OK", response->headers->GetStatusLine()); |
| 11321 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11322 | EXPECT_TRUE(response->was_alpn_negotiated); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 11323 | |
| 11324 | std::string response_data; |
| 11325 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 11326 | EXPECT_EQ("hello world", response_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11327 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11328 | trans = |
| 11329 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11330 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11331 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11332 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11333 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11334 | |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 11335 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11336 | ASSERT_TRUE(response); |
| 11337 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11338 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11339 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11340 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11341 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11342 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11343 | EXPECT_EQ("hello!", response_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11344 | ASSERT_EQ(2u, capturing_proxy_resolver.resolved().size()); |
| 11345 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11346 | capturing_proxy_resolver.resolved()[0].spec()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11347 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11348 | capturing_proxy_resolver.resolved()[1].spec()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11349 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11350 | LoadTimingInfo load_timing_info; |
| 11351 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 11352 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11353 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11354 | } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11355 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11356 | TEST_F(HttpNetworkTransactionTest, |
bnc | 1c196c6e | 2016-05-28 13:51:48 | [diff] [blame] | 11357 | UseAlternativeServiceForNpnSpdyWithExistingSpdySession) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11358 | HttpRequestInfo request; |
| 11359 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11360 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11361 | |
| 11362 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11363 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11364 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11365 | MockRead("\r\n"), |
| 11366 | MockRead("hello world"), |
| 11367 | MockRead(ASYNC, OK), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11368 | }; |
| 11369 | |
| 11370 | StaticSocketDataProvider first_transaction( |
| 11371 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11372 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11373 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11374 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11375 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11376 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11377 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11378 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11379 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11380 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11381 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11382 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 11383 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11384 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11385 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11386 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11387 | }; |
| 11388 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11389 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11390 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11391 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11392 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 11393 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11394 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11395 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11396 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11397 | auto trans = |
| 11398 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11399 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11400 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11401 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11402 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11403 | |
| 11404 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11405 | ASSERT_TRUE(response); |
| 11406 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11407 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11408 | |
| 11409 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11410 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11411 | EXPECT_EQ("hello world", response_data); |
| 11412 | |
| 11413 | // Set up an initial SpdySession in the pool to reuse. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11414 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 11415 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 11416 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 11417 | base::WeakPtr<SpdySession> spdy_session = |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11418 | CreateSecureSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 11419 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11420 | trans = |
| 11421 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11422 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11423 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11424 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11425 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11426 | |
| 11427 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11428 | ASSERT_TRUE(response); |
| 11429 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11430 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11431 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11432 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11433 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11434 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11435 | EXPECT_EQ("hello!", response_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11436 | } |
| 11437 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11438 | // GenerateAuthToken is a mighty big test. |
| 11439 | // It tests all permutation of GenerateAuthToken behavior: |
| 11440 | // - Synchronous and Asynchronous completion. |
| 11441 | // - OK or error on completion. |
| 11442 | // - Direct connection, non-authenticating proxy, and authenticating proxy. |
| 11443 | // - HTTP or HTTPS backend (to include proxy tunneling). |
| 11444 | // - Non-authenticating and authenticating backend. |
| 11445 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 11446 | // In all, there are 44 reasonable permuations (for example, if there are |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11447 | // problems generating an auth token for an authenticating proxy, we don't |
| 11448 | // need to test all permutations of the backend server). |
| 11449 | // |
| 11450 | // The test proceeds by going over each of the configuration cases, and |
| 11451 | // potentially running up to three rounds in each of the tests. The TestConfig |
| 11452 | // specifies both the configuration for the test as well as the expectations |
| 11453 | // for the results. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11454 | TEST_F(HttpNetworkTransactionTest, GenerateAuthToken) { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11455 | static const char kServer[] = "http://www.example.com"; |
| 11456 | static const char kSecureServer[] = "https://www.example.com"; |
| 11457 | static const char kProxy[] = "myproxy:70"; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11458 | |
| 11459 | enum AuthTiming { |
| 11460 | AUTH_NONE, |
| 11461 | AUTH_SYNC, |
| 11462 | AUTH_ASYNC, |
| 11463 | }; |
| 11464 | |
| 11465 | const MockWrite kGet( |
| 11466 | "GET / HTTP/1.1\r\n" |
| 11467 | "Host: www.example.com\r\n" |
| 11468 | "Connection: keep-alive\r\n\r\n"); |
| 11469 | const MockWrite kGetProxy( |
| 11470 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11471 | "Host: www.example.com\r\n" |
| 11472 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 11473 | const MockWrite kGetAuth( |
| 11474 | "GET / HTTP/1.1\r\n" |
| 11475 | "Host: www.example.com\r\n" |
| 11476 | "Connection: keep-alive\r\n" |
| 11477 | "Authorization: auth_token\r\n\r\n"); |
| 11478 | const MockWrite kGetProxyAuth( |
| 11479 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11480 | "Host: www.example.com\r\n" |
| 11481 | "Proxy-Connection: keep-alive\r\n" |
| 11482 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 11483 | const MockWrite kGetAuthThroughProxy( |
| 11484 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11485 | "Host: www.example.com\r\n" |
| 11486 | "Proxy-Connection: keep-alive\r\n" |
| 11487 | "Authorization: auth_token\r\n\r\n"); |
| 11488 | const MockWrite kGetAuthWithProxyAuth( |
| 11489 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11490 | "Host: www.example.com\r\n" |
| 11491 | "Proxy-Connection: keep-alive\r\n" |
| 11492 | "Proxy-Authorization: auth_token\r\n" |
| 11493 | "Authorization: auth_token\r\n\r\n"); |
| 11494 | const MockWrite kConnect( |
| 11495 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 11496 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11497 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 11498 | const MockWrite kConnectProxyAuth( |
| 11499 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 11500 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11501 | "Proxy-Connection: keep-alive\r\n" |
| 11502 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 11503 | |
| 11504 | const MockRead kSuccess( |
| 11505 | "HTTP/1.1 200 OK\r\n" |
| 11506 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11507 | "Content-Length: 3\r\n\r\n" |
| 11508 | "Yes"); |
| 11509 | const MockRead kFailure( |
| 11510 | "Should not be called."); |
| 11511 | const MockRead kServerChallenge( |
| 11512 | "HTTP/1.1 401 Unauthorized\r\n" |
| 11513 | "WWW-Authenticate: Mock realm=server\r\n" |
| 11514 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11515 | "Content-Length: 14\r\n\r\n" |
| 11516 | "Unauthorized\r\n"); |
| 11517 | const MockRead kProxyChallenge( |
| 11518 | "HTTP/1.1 407 Unauthorized\r\n" |
| 11519 | "Proxy-Authenticate: Mock realm=proxy\r\n" |
| 11520 | "Proxy-Connection: close\r\n" |
| 11521 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11522 | "Content-Length: 14\r\n\r\n" |
| 11523 | "Unauthorized\r\n"); |
| 11524 | const MockRead kProxyConnected( |
| 11525 | "HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 11526 | |
| 11527 | // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with |
| 11528 | // no constructors, but the C++ compiler on Windows warns about |
| 11529 | // unspecified data in compound literals. So, moved to using constructors, |
| 11530 | // and TestRound's created with the default constructor should not be used. |
| 11531 | struct TestRound { |
| 11532 | TestRound() |
| 11533 | : expected_rv(ERR_UNEXPECTED), |
| 11534 | extra_write(NULL), |
| 11535 | extra_read(NULL) { |
| 11536 | } |
| 11537 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 11538 | int expected_rv_arg) |
| 11539 | : write(write_arg), |
| 11540 | read(read_arg), |
| 11541 | expected_rv(expected_rv_arg), |
| 11542 | extra_write(NULL), |
| 11543 | extra_read(NULL) { |
| 11544 | } |
| 11545 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 11546 | int expected_rv_arg, const MockWrite* extra_write_arg, |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 11547 | const MockRead* extra_read_arg) |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11548 | : write(write_arg), |
| 11549 | read(read_arg), |
| 11550 | expected_rv(expected_rv_arg), |
| 11551 | extra_write(extra_write_arg), |
| 11552 | extra_read(extra_read_arg) { |
| 11553 | } |
| 11554 | MockWrite write; |
| 11555 | MockRead read; |
| 11556 | int expected_rv; |
| 11557 | const MockWrite* extra_write; |
| 11558 | const MockRead* extra_read; |
| 11559 | }; |
| 11560 | |
| 11561 | static const int kNoSSL = 500; |
| 11562 | |
| 11563 | struct TestConfig { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11564 | int line_number; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 11565 | const char* const proxy_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11566 | AuthTiming proxy_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11567 | int first_generate_proxy_token_rv; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 11568 | const char* const server_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11569 | AuthTiming server_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11570 | int first_generate_server_token_rv; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11571 | int num_auth_rounds; |
| 11572 | int first_ssl_round; |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11573 | TestRound rounds[4]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11574 | } test_configs[] = { |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11575 | // Non-authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11576 | {__LINE__, |
| 11577 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11578 | AUTH_NONE, |
| 11579 | OK, |
| 11580 | kServer, |
| 11581 | AUTH_NONE, |
| 11582 | OK, |
| 11583 | 1, |
| 11584 | kNoSSL, |
| 11585 | {TestRound(kGet, kSuccess, OK)}}, |
| 11586 | // Authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11587 | {__LINE__, |
| 11588 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11589 | AUTH_NONE, |
| 11590 | OK, |
| 11591 | kServer, |
| 11592 | AUTH_SYNC, |
| 11593 | OK, |
| 11594 | 2, |
| 11595 | kNoSSL, |
| 11596 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11597 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11598 | {__LINE__, |
| 11599 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11600 | AUTH_NONE, |
| 11601 | OK, |
| 11602 | kServer, |
| 11603 | AUTH_SYNC, |
| 11604 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11605 | 3, |
| 11606 | kNoSSL, |
| 11607 | {TestRound(kGet, kServerChallenge, OK), |
| 11608 | TestRound(kGet, kServerChallenge, OK), |
| 11609 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11610 | {__LINE__, |
| 11611 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11612 | AUTH_NONE, |
| 11613 | OK, |
| 11614 | kServer, |
| 11615 | AUTH_SYNC, |
| 11616 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 11617 | 2, |
| 11618 | kNoSSL, |
| 11619 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11620 | {__LINE__, |
| 11621 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11622 | AUTH_NONE, |
| 11623 | OK, |
| 11624 | kServer, |
| 11625 | AUTH_SYNC, |
| 11626 | ERR_UNDOCUMENTED_SECURITY_LIBRARY_STATUS, |
| 11627 | 2, |
| 11628 | kNoSSL, |
| 11629 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11630 | {__LINE__, |
| 11631 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11632 | AUTH_SYNC, |
| 11633 | ERR_FAILED, |
| 11634 | kServer, |
| 11635 | AUTH_NONE, |
| 11636 | OK, |
| 11637 | 2, |
| 11638 | kNoSSL, |
| 11639 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 11640 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11641 | {__LINE__, |
| 11642 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11643 | AUTH_ASYNC, |
| 11644 | ERR_FAILED, |
| 11645 | kServer, |
| 11646 | AUTH_NONE, |
| 11647 | OK, |
| 11648 | 2, |
| 11649 | kNoSSL, |
| 11650 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 11651 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11652 | {__LINE__, |
| 11653 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11654 | AUTH_NONE, |
| 11655 | OK, |
| 11656 | kServer, |
| 11657 | AUTH_SYNC, |
| 11658 | ERR_FAILED, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11659 | 2, |
| 11660 | kNoSSL, |
| 11661 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11662 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11663 | {__LINE__, |
| 11664 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11665 | AUTH_NONE, |
| 11666 | OK, |
| 11667 | kServer, |
| 11668 | AUTH_ASYNC, |
| 11669 | ERR_FAILED, |
| 11670 | 2, |
| 11671 | kNoSSL, |
| 11672 | {TestRound(kGet, kServerChallenge, OK), |
| 11673 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11674 | {__LINE__, |
| 11675 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11676 | AUTH_NONE, |
| 11677 | OK, |
| 11678 | kServer, |
| 11679 | AUTH_ASYNC, |
| 11680 | OK, |
| 11681 | 2, |
| 11682 | kNoSSL, |
| 11683 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11684 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11685 | {__LINE__, |
| 11686 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11687 | AUTH_NONE, |
| 11688 | OK, |
| 11689 | kServer, |
| 11690 | AUTH_ASYNC, |
| 11691 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11692 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11693 | kNoSSL, |
| 11694 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11695 | // The second round uses a HttpAuthHandlerMock that always succeeds. |
| 11696 | TestRound(kGet, kServerChallenge, OK), |
| 11697 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11698 | // Non-authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11699 | {__LINE__, |
| 11700 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11701 | AUTH_NONE, |
| 11702 | OK, |
| 11703 | kServer, |
| 11704 | AUTH_NONE, |
| 11705 | OK, |
| 11706 | 1, |
| 11707 | kNoSSL, |
| 11708 | {TestRound(kGetProxy, kSuccess, OK)}}, |
| 11709 | // Authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11710 | {__LINE__, |
| 11711 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11712 | AUTH_NONE, |
| 11713 | OK, |
| 11714 | kServer, |
| 11715 | AUTH_SYNC, |
| 11716 | OK, |
| 11717 | 2, |
| 11718 | kNoSSL, |
| 11719 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11720 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11721 | {__LINE__, |
| 11722 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11723 | AUTH_NONE, |
| 11724 | OK, |
| 11725 | kServer, |
| 11726 | AUTH_SYNC, |
| 11727 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11728 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11729 | kNoSSL, |
| 11730 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11731 | TestRound(kGetProxy, kServerChallenge, OK), |
| 11732 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11733 | {__LINE__, |
| 11734 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11735 | AUTH_NONE, |
| 11736 | OK, |
| 11737 | kServer, |
| 11738 | AUTH_ASYNC, |
| 11739 | OK, |
| 11740 | 2, |
| 11741 | kNoSSL, |
| 11742 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11743 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11744 | {__LINE__, |
| 11745 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11746 | AUTH_NONE, |
| 11747 | OK, |
| 11748 | kServer, |
| 11749 | AUTH_ASYNC, |
| 11750 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11751 | 2, |
| 11752 | kNoSSL, |
| 11753 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11754 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11755 | // Non-authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11756 | {__LINE__, |
| 11757 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11758 | AUTH_SYNC, |
| 11759 | OK, |
| 11760 | kServer, |
| 11761 | AUTH_NONE, |
| 11762 | OK, |
| 11763 | 2, |
| 11764 | kNoSSL, |
| 11765 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11766 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11767 | {__LINE__, |
| 11768 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11769 | AUTH_SYNC, |
| 11770 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11771 | kServer, |
| 11772 | AUTH_NONE, |
| 11773 | OK, |
| 11774 | 2, |
| 11775 | kNoSSL, |
| 11776 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11777 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11778 | {__LINE__, |
| 11779 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11780 | AUTH_ASYNC, |
| 11781 | OK, |
| 11782 | kServer, |
| 11783 | AUTH_NONE, |
| 11784 | OK, |
| 11785 | 2, |
| 11786 | kNoSSL, |
| 11787 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11788 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11789 | {__LINE__, |
| 11790 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11791 | AUTH_ASYNC, |
| 11792 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11793 | kServer, |
| 11794 | AUTH_NONE, |
| 11795 | OK, |
| 11796 | 2, |
| 11797 | kNoSSL, |
| 11798 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11799 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11800 | {__LINE__, |
| 11801 | kProxy, |
| 11802 | AUTH_ASYNC, |
| 11803 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11804 | kServer, |
| 11805 | AUTH_NONE, |
| 11806 | OK, |
| 11807 | 3, |
| 11808 | kNoSSL, |
| 11809 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 11810 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 11811 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11812 | // Authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11813 | {__LINE__, |
| 11814 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11815 | AUTH_SYNC, |
| 11816 | OK, |
| 11817 | kServer, |
| 11818 | AUTH_SYNC, |
| 11819 | OK, |
| 11820 | 3, |
| 11821 | kNoSSL, |
| 11822 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11823 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11824 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11825 | {__LINE__, |
| 11826 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11827 | AUTH_SYNC, |
| 11828 | OK, |
| 11829 | kServer, |
| 11830 | AUTH_SYNC, |
| 11831 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11832 | 3, |
| 11833 | kNoSSL, |
| 11834 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11835 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11836 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11837 | {__LINE__, |
| 11838 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11839 | AUTH_ASYNC, |
| 11840 | OK, |
| 11841 | kServer, |
| 11842 | AUTH_SYNC, |
| 11843 | OK, |
| 11844 | 3, |
| 11845 | kNoSSL, |
| 11846 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11847 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11848 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11849 | {__LINE__, |
| 11850 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11851 | AUTH_ASYNC, |
| 11852 | OK, |
| 11853 | kServer, |
| 11854 | AUTH_SYNC, |
| 11855 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11856 | 3, |
| 11857 | kNoSSL, |
| 11858 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11859 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11860 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11861 | {__LINE__, |
| 11862 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11863 | AUTH_SYNC, |
| 11864 | OK, |
| 11865 | kServer, |
| 11866 | AUTH_ASYNC, |
| 11867 | OK, |
| 11868 | 3, |
| 11869 | kNoSSL, |
| 11870 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11871 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11872 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11873 | {__LINE__, |
| 11874 | kProxy, |
| 11875 | AUTH_SYNC, |
| 11876 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11877 | kServer, |
| 11878 | AUTH_ASYNC, |
| 11879 | OK, |
| 11880 | 4, |
| 11881 | kNoSSL, |
| 11882 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 11883 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 11884 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11885 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 11886 | {__LINE__, |
| 11887 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11888 | AUTH_SYNC, |
| 11889 | OK, |
| 11890 | kServer, |
| 11891 | AUTH_ASYNC, |
| 11892 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11893 | 3, |
| 11894 | kNoSSL, |
| 11895 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11896 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11897 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11898 | {__LINE__, |
| 11899 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11900 | AUTH_ASYNC, |
| 11901 | OK, |
| 11902 | kServer, |
| 11903 | AUTH_ASYNC, |
| 11904 | OK, |
| 11905 | 3, |
| 11906 | kNoSSL, |
| 11907 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11908 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11909 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11910 | {__LINE__, |
| 11911 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11912 | AUTH_ASYNC, |
| 11913 | OK, |
| 11914 | kServer, |
| 11915 | AUTH_ASYNC, |
| 11916 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11917 | 3, |
| 11918 | kNoSSL, |
| 11919 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11920 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11921 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11922 | {__LINE__, |
| 11923 | kProxy, |
| 11924 | AUTH_ASYNC, |
| 11925 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11926 | kServer, |
| 11927 | AUTH_ASYNC, |
| 11928 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11929 | 4, |
| 11930 | kNoSSL, |
| 11931 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 11932 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 11933 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11934 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11935 | // Non-authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11936 | {__LINE__, |
| 11937 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11938 | AUTH_NONE, |
| 11939 | OK, |
| 11940 | kSecureServer, |
| 11941 | AUTH_NONE, |
| 11942 | OK, |
| 11943 | 1, |
| 11944 | 0, |
| 11945 | {TestRound(kGet, kSuccess, OK)}}, |
| 11946 | // Authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11947 | {__LINE__, |
| 11948 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11949 | AUTH_NONE, |
| 11950 | OK, |
| 11951 | kSecureServer, |
| 11952 | AUTH_SYNC, |
| 11953 | OK, |
| 11954 | 2, |
| 11955 | 0, |
| 11956 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11957 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11958 | {__LINE__, |
| 11959 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11960 | AUTH_NONE, |
| 11961 | OK, |
| 11962 | kSecureServer, |
| 11963 | AUTH_SYNC, |
| 11964 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11965 | 2, |
| 11966 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11967 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11968 | {__LINE__, |
| 11969 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11970 | AUTH_NONE, |
| 11971 | OK, |
| 11972 | kSecureServer, |
| 11973 | AUTH_ASYNC, |
| 11974 | OK, |
| 11975 | 2, |
| 11976 | 0, |
| 11977 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11978 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11979 | {__LINE__, |
| 11980 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11981 | AUTH_NONE, |
| 11982 | OK, |
| 11983 | kSecureServer, |
| 11984 | AUTH_ASYNC, |
| 11985 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11986 | 2, |
| 11987 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11988 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11989 | // Non-authenticating HTTPS server with a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11990 | {__LINE__, |
| 11991 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11992 | AUTH_NONE, |
| 11993 | OK, |
| 11994 | kSecureServer, |
| 11995 | AUTH_NONE, |
| 11996 | OK, |
| 11997 | 1, |
| 11998 | 0, |
| 11999 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 12000 | // Authenticating HTTPS server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12001 | {__LINE__, |
| 12002 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12003 | AUTH_NONE, |
| 12004 | OK, |
| 12005 | kSecureServer, |
| 12006 | AUTH_SYNC, |
| 12007 | OK, |
| 12008 | 2, |
| 12009 | 0, |
| 12010 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12011 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12012 | {__LINE__, |
| 12013 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12014 | AUTH_NONE, |
| 12015 | OK, |
| 12016 | kSecureServer, |
| 12017 | AUTH_SYNC, |
| 12018 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12019 | 2, |
| 12020 | 0, |
| 12021 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12022 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12023 | {__LINE__, |
| 12024 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12025 | AUTH_NONE, |
| 12026 | OK, |
| 12027 | kSecureServer, |
| 12028 | AUTH_ASYNC, |
| 12029 | OK, |
| 12030 | 2, |
| 12031 | 0, |
| 12032 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12033 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12034 | {__LINE__, |
| 12035 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12036 | AUTH_NONE, |
| 12037 | OK, |
| 12038 | kSecureServer, |
| 12039 | AUTH_ASYNC, |
| 12040 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12041 | 2, |
| 12042 | 0, |
| 12043 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12044 | TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12045 | // Non-Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12046 | {__LINE__, |
| 12047 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12048 | AUTH_SYNC, |
| 12049 | OK, |
| 12050 | kSecureServer, |
| 12051 | AUTH_NONE, |
| 12052 | OK, |
| 12053 | 2, |
| 12054 | 1, |
| 12055 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12056 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12057 | {__LINE__, |
| 12058 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12059 | AUTH_SYNC, |
| 12060 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12061 | kSecureServer, |
| 12062 | AUTH_NONE, |
| 12063 | OK, |
| 12064 | 2, |
| 12065 | kNoSSL, |
| 12066 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12067 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12068 | {__LINE__, |
| 12069 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12070 | AUTH_SYNC, |
| 12071 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 12072 | kSecureServer, |
| 12073 | AUTH_NONE, |
| 12074 | OK, |
| 12075 | 2, |
| 12076 | kNoSSL, |
| 12077 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12078 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12079 | {__LINE__, |
| 12080 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12081 | AUTH_SYNC, |
| 12082 | ERR_UNEXPECTED, |
| 12083 | kSecureServer, |
| 12084 | AUTH_NONE, |
| 12085 | OK, |
| 12086 | 2, |
| 12087 | kNoSSL, |
| 12088 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12089 | TestRound(kConnect, kProxyConnected, ERR_UNEXPECTED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12090 | {__LINE__, |
| 12091 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12092 | AUTH_ASYNC, |
| 12093 | OK, |
| 12094 | kSecureServer, |
| 12095 | AUTH_NONE, |
| 12096 | OK, |
| 12097 | 2, |
| 12098 | 1, |
| 12099 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12100 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12101 | {__LINE__, |
| 12102 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12103 | AUTH_ASYNC, |
| 12104 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12105 | kSecureServer, |
| 12106 | AUTH_NONE, |
| 12107 | OK, |
| 12108 | 2, |
| 12109 | kNoSSL, |
| 12110 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12111 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12112 | // Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12113 | {__LINE__, |
| 12114 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12115 | AUTH_SYNC, |
| 12116 | OK, |
| 12117 | kSecureServer, |
| 12118 | AUTH_SYNC, |
| 12119 | OK, |
| 12120 | 3, |
| 12121 | 1, |
| 12122 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12123 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12124 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12125 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12126 | {__LINE__, |
| 12127 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12128 | AUTH_SYNC, |
| 12129 | OK, |
| 12130 | kSecureServer, |
| 12131 | AUTH_SYNC, |
| 12132 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12133 | 3, |
| 12134 | 1, |
| 12135 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12136 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12137 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12138 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12139 | {__LINE__, |
| 12140 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12141 | AUTH_ASYNC, |
| 12142 | OK, |
| 12143 | kSecureServer, |
| 12144 | AUTH_SYNC, |
| 12145 | OK, |
| 12146 | 3, |
| 12147 | 1, |
| 12148 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12149 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12150 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12151 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12152 | {__LINE__, |
| 12153 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12154 | AUTH_ASYNC, |
| 12155 | OK, |
| 12156 | kSecureServer, |
| 12157 | AUTH_SYNC, |
| 12158 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12159 | 3, |
| 12160 | 1, |
| 12161 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12162 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12163 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12164 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12165 | {__LINE__, |
| 12166 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12167 | AUTH_SYNC, |
| 12168 | OK, |
| 12169 | kSecureServer, |
| 12170 | AUTH_ASYNC, |
| 12171 | OK, |
| 12172 | 3, |
| 12173 | 1, |
| 12174 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12175 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12176 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12177 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12178 | {__LINE__, |
| 12179 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12180 | AUTH_SYNC, |
| 12181 | OK, |
| 12182 | kSecureServer, |
| 12183 | AUTH_ASYNC, |
| 12184 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12185 | 3, |
| 12186 | 1, |
| 12187 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12188 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12189 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12190 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12191 | {__LINE__, |
| 12192 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12193 | AUTH_ASYNC, |
| 12194 | OK, |
| 12195 | kSecureServer, |
| 12196 | AUTH_ASYNC, |
| 12197 | OK, |
| 12198 | 3, |
| 12199 | 1, |
| 12200 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12201 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12202 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12203 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12204 | {__LINE__, |
| 12205 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12206 | AUTH_ASYNC, |
| 12207 | OK, |
| 12208 | kSecureServer, |
| 12209 | AUTH_ASYNC, |
| 12210 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12211 | 3, |
| 12212 | 1, |
| 12213 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12214 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12215 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12216 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12217 | {__LINE__, |
| 12218 | kProxy, |
| 12219 | AUTH_ASYNC, |
| 12220 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12221 | kSecureServer, |
| 12222 | AUTH_ASYNC, |
| 12223 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12224 | 4, |
| 12225 | 2, |
| 12226 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12227 | TestRound(kConnect, kProxyChallenge, OK), |
| 12228 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12229 | &kServerChallenge), |
| 12230 | TestRound(kGet, kSuccess, OK)}}, |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12231 | }; |
| 12232 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12233 | for (const auto& test_config : test_configs) { |
| 12234 | SCOPED_TRACE(::testing::Message() << "Test config at " |
| 12235 | << test_config.line_number); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12236 | HttpAuthHandlerMock::Factory* auth_factory( |
| 12237 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12238 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 12239 | SSLInfo empty_ssl_info; |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 12240 | |
| 12241 | // Set up authentication handlers as necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12242 | if (test_config.proxy_auth_timing != AUTH_NONE) { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12243 | for (int n = 0; n < 3; n++) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12244 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 12245 | std::string auth_challenge = "Mock realm=proxy"; |
| 12246 | GURL origin(test_config.proxy_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 12247 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 12248 | auth_challenge.end()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12249 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12250 | empty_ssl_info, origin, |
| 12251 | NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12252 | auth_handler->SetGenerateExpectation( |
| 12253 | test_config.proxy_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12254 | n == 0 ? test_config.first_generate_proxy_token_rv : OK); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12255 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 12256 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12257 | } |
| 12258 | if (test_config.server_auth_timing != AUTH_NONE) { |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 12259 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12260 | std::string auth_challenge = "Mock realm=server"; |
| 12261 | GURL origin(test_config.server_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 12262 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 12263 | auth_challenge.end()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12264 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12265 | empty_ssl_info, origin, |
| 12266 | NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12267 | auth_handler->SetGenerateExpectation( |
| 12268 | test_config.server_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12269 | test_config.first_generate_server_token_rv); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12270 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12271 | |
| 12272 | // The second handler always succeeds. It should only be used where there |
| 12273 | // are multiple auth sessions for server auth in the same network |
| 12274 | // transaction using the same auth scheme. |
| 12275 | std::unique_ptr<HttpAuthHandlerMock> second_handler = |
| 12276 | base::MakeUnique<HttpAuthHandlerMock>(); |
| 12277 | second_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 12278 | empty_ssl_info, origin, |
| 12279 | NetLogWithSource()); |
| 12280 | second_handler->SetGenerateExpectation(true, OK); |
| 12281 | auth_factory->AddMockHandler(second_handler.release(), |
| 12282 | HttpAuth::AUTH_SERVER); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12283 | } |
| 12284 | if (test_config.proxy_url) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12285 | session_deps_.proxy_service = |
| 12286 | ProxyService::CreateFixed(test_config.proxy_url); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12287 | } else { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12288 | session_deps_.proxy_service = ProxyService::CreateDirect(); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12289 | } |
| 12290 | |
| 12291 | HttpRequestInfo request; |
| 12292 | request.method = "GET"; |
| 12293 | request.url = GURL(test_config.server_url); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12294 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12295 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12296 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12297 | SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
| 12298 | |
| 12299 | std::vector<std::vector<MockRead>> mock_reads(1); |
| 12300 | std::vector<std::vector<MockWrite>> mock_writes(1); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12301 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 12302 | SCOPED_TRACE(round); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12303 | const TestRound& read_write_round = test_config.rounds[round]; |
| 12304 | |
| 12305 | // Set up expected reads and writes. |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12306 | mock_reads.back().push_back(read_write_round.read); |
| 12307 | mock_writes.back().push_back(read_write_round.write); |
| 12308 | |
| 12309 | // kProxyChallenge uses Proxy-Connection: close which means that the |
| 12310 | // socket is closed and a new one will be created for the next request. |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 12311 | if (read_write_round.read.data == kProxyChallenge.data) { |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12312 | mock_reads.push_back(std::vector<MockRead>()); |
| 12313 | mock_writes.push_back(std::vector<MockWrite>()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12314 | } |
| 12315 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12316 | if (read_write_round.extra_read) { |
| 12317 | mock_reads.back().push_back(*read_write_round.extra_read); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12318 | } |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12319 | if (read_write_round.extra_write) { |
| 12320 | mock_writes.back().push_back(*read_write_round.extra_write); |
| 12321 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12322 | |
| 12323 | // Add an SSL sequence if necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12324 | if (round >= test_config.first_ssl_round) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12325 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12326 | &ssl_socket_data_provider); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12327 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12328 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12329 | std::vector<std::unique_ptr<StaticSocketDataProvider>> data_providers; |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12330 | for (size_t i = 0; i < mock_reads.size(); ++i) { |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12331 | data_providers.push_back(base::MakeUnique<StaticSocketDataProvider>( |
davidben | 5f8b6bc | 2015-11-25 03:19:54 | [diff] [blame] | 12332 | mock_reads[i].data(), mock_reads[i].size(), mock_writes[i].data(), |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12333 | mock_writes[i].size())); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12334 | session_deps_.socket_factory->AddSocketDataProvider( |
olli.raula | 525048c | 2015-12-10 07:38:32 | [diff] [blame] | 12335 | data_providers.back().get()); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12336 | } |
| 12337 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12338 | // Transaction must be created after DataProviders, so it's destroyed before |
| 12339 | // they are as well. |
| 12340 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 12341 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12342 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 12343 | SCOPED_TRACE(round); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12344 | const TestRound& read_write_round = test_config.rounds[round]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12345 | // Start or restart the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12346 | TestCompletionCallback callback; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12347 | int rv; |
| 12348 | if (round == 0) { |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12349 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12350 | } else { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12351 | rv = trans.RestartWithAuth( |
| 12352 | AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12353 | } |
| 12354 | if (rv == ERR_IO_PENDING) |
| 12355 | rv = callback.WaitForResult(); |
| 12356 | |
| 12357 | // Compare results with expected data. |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12358 | EXPECT_THAT(rv, IsError(read_write_round.expected_rv)); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12359 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | c0c82849 | 2015-05-15 01:25:55 | [diff] [blame] | 12360 | if (read_write_round.expected_rv != OK) { |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12361 | EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
| 12362 | continue; |
| 12363 | } |
| 12364 | if (round + 1 < test_config.num_auth_rounds) { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12365 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12366 | } else { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12367 | EXPECT_FALSE(response->auth_challenge); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12368 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12369 | } |
| 12370 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 12371 | } |
| 12372 | } |
| 12373 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12374 | TEST_F(HttpNetworkTransactionTest, MultiRoundAuth) { |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12375 | // Do multi-round authentication and make sure it works correctly. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12376 | HttpAuthHandlerMock::Factory* auth_factory( |
| 12377 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12378 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12379 | session_deps_.proxy_service = ProxyService::CreateDirect(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12380 | session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
| 12381 | session_deps_.host_resolver->set_synchronous_mode(true); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12382 | |
| 12383 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 12384 | auth_handler->set_connection_based(true); |
| 12385 | std::string auth_challenge = "Mock realm=server"; |
| 12386 | GURL origin("http://www.example.com"); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 12387 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 12388 | auth_challenge.end()); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 12389 | SSLInfo empty_ssl_info; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12390 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12391 | empty_ssl_info, origin, NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12392 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12393 | |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12394 | int rv = OK; |
| 12395 | const HttpResponseInfo* response = NULL; |
| 12396 | HttpRequestInfo request; |
| 12397 | request.method = "GET"; |
| 12398 | request.url = origin; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12399 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12400 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12401 | |
| 12402 | // Use a TCP Socket Pool with only one connection per group. This is used |
| 12403 | // to validate that the TCP socket is not released to the pool between |
| 12404 | // each round of multi-round authentication. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12405 | HttpNetworkSessionPeer session_peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12406 | TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12407 | 50, // Max sockets for pool |
| 12408 | 1, // Max sockets per group |
tbansal | 7b403bcc | 2016-04-13 22:33:21 | [diff] [blame] | 12409 | session_deps_.host_resolver.get(), session_deps_.socket_factory.get(), |
| 12410 | NULL, session_deps_.net_log); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12411 | auto mock_pool_manager = base::MakeUnique<MockClientSocketPoolManager>(); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 12412 | mock_pool_manager->SetTransportSocketPool(transport_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 12413 | session_peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12414 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12415 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12416 | TestCompletionCallback callback; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12417 | |
| 12418 | const MockWrite kGet( |
| 12419 | "GET / HTTP/1.1\r\n" |
| 12420 | "Host: www.example.com\r\n" |
| 12421 | "Connection: keep-alive\r\n\r\n"); |
| 12422 | const MockWrite kGetAuth( |
| 12423 | "GET / HTTP/1.1\r\n" |
| 12424 | "Host: www.example.com\r\n" |
| 12425 | "Connection: keep-alive\r\n" |
| 12426 | "Authorization: auth_token\r\n\r\n"); |
| 12427 | |
| 12428 | const MockRead kServerChallenge( |
| 12429 | "HTTP/1.1 401 Unauthorized\r\n" |
| 12430 | "WWW-Authenticate: Mock realm=server\r\n" |
| 12431 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12432 | "Content-Length: 14\r\n\r\n" |
| 12433 | "Unauthorized\r\n"); |
| 12434 | const MockRead kSuccess( |
| 12435 | "HTTP/1.1 200 OK\r\n" |
| 12436 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12437 | "Content-Length: 3\r\n\r\n" |
| 12438 | "Yes"); |
| 12439 | |
| 12440 | MockWrite writes[] = { |
| 12441 | // First round |
| 12442 | kGet, |
| 12443 | // Second round |
| 12444 | kGetAuth, |
| 12445 | // Third round |
| 12446 | kGetAuth, |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 12447 | // Fourth round |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12448 | kGetAuth, |
| 12449 | // Competing request |
| 12450 | kGet, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12451 | }; |
| 12452 | MockRead reads[] = { |
| 12453 | // First round |
| 12454 | kServerChallenge, |
| 12455 | // Second round |
| 12456 | kServerChallenge, |
| 12457 | // Third round |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 12458 | kServerChallenge, |
| 12459 | // Fourth round |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12460 | kSuccess, |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12461 | // Competing response |
| 12462 | kSuccess, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12463 | }; |
| 12464 | StaticSocketDataProvider data_provider(reads, arraysize(reads), |
| 12465 | writes, arraysize(writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12466 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12467 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 12468 | const char kSocketGroup[] = "www.example.com:80"; |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12469 | |
| 12470 | // First round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12471 | auth_handler->SetGenerateExpectation(false, OK); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12472 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12473 | if (rv == ERR_IO_PENDING) |
| 12474 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12475 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12476 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12477 | ASSERT_TRUE(response); |
| 12478 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12479 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12480 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 12481 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12482 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12483 | // In between rounds, another request comes in for the same domain. |
| 12484 | // It should not be able to grab the TCP socket that trans has already |
| 12485 | // claimed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12486 | HttpNetworkTransaction trans_compete(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12487 | TestCompletionCallback callback_compete; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12488 | rv = trans_compete.Start(&request, callback_compete.callback(), |
| 12489 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12490 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12491 | // callback_compete.WaitForResult at this point would stall forever, |
| 12492 | // since the HttpNetworkTransaction does not release the request back to |
| 12493 | // the pool until after authentication completes. |
| 12494 | |
| 12495 | // Second round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12496 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12497 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12498 | if (rv == ERR_IO_PENDING) |
| 12499 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12500 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12501 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12502 | ASSERT_TRUE(response); |
| 12503 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12504 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12505 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 12506 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12507 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12508 | // Third round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12509 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12510 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12511 | if (rv == ERR_IO_PENDING) |
| 12512 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12513 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12514 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12515 | ASSERT_TRUE(response); |
| 12516 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12517 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12518 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 12519 | auth_handler->state()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 12520 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12521 | // Fourth round of authentication, which completes successfully. |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 12522 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12523 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 12524 | if (rv == ERR_IO_PENDING) |
| 12525 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12526 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12527 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12528 | ASSERT_TRUE(response); |
| 12529 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12530 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12531 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12532 | // In WAIT_FOR_CHALLENGE, although in reality the auth handler is done. A real |
| 12533 | // auth handler should transition to a DONE state in concert with the remote |
| 12534 | // server. But that's not something we can test here with a mock handler. |
| 12535 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_CHALLENGE, |
| 12536 | auth_handler->state()); |
| 12537 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12538 | // Read the body since the fourth round was successful. This will also |
| 12539 | // release the socket back to the pool. |
| 12540 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(50)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12541 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12542 | if (rv == ERR_IO_PENDING) |
| 12543 | rv = callback.WaitForResult(); |
| 12544 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12545 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12546 | EXPECT_EQ(0, rv); |
| 12547 | // There are still 0 idle sockets, since the trans_compete transaction |
| 12548 | // will be handed it immediately after trans releases it to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12549 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12550 | |
| 12551 | // The competing request can now finish. Wait for the headers and then |
| 12552 | // read the body. |
| 12553 | rv = callback_compete.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12554 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12555 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12556 | if (rv == ERR_IO_PENDING) |
| 12557 | rv = callback.WaitForResult(); |
| 12558 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12559 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12560 | EXPECT_EQ(0, rv); |
| 12561 | |
| 12562 | // Finally, the socket is released to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12563 | EXPECT_EQ(1, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12564 | } |
| 12565 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12566 | // This tests the case that a request is issued via http instead of spdy after |
| 12567 | // npn is negotiated. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12568 | TEST_F(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12569 | HttpRequestInfo request; |
| 12570 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12571 | request.url = GURL("https://www.example.org/"); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12572 | |
| 12573 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12574 | MockWrite( |
| 12575 | "GET / HTTP/1.1\r\n" |
| 12576 | "Host: www.example.org\r\n" |
| 12577 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12578 | }; |
| 12579 | |
| 12580 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12581 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12582 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12583 | MockRead("\r\n"), |
| 12584 | MockRead("hello world"), |
| 12585 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12586 | }; |
| 12587 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12588 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12589 | ssl.next_proto = kProtoHTTP11; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12590 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12591 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12592 | |
| 12593 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 12594 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12595 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12596 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12597 | TestCompletionCallback callback; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12598 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12599 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12600 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12601 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12602 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12603 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12604 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12605 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12606 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12607 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12608 | ASSERT_TRUE(response); |
| 12609 | ASSERT_TRUE(response->headers); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12610 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12611 | |
| 12612 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12613 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12614 | EXPECT_EQ("hello world", response_data); |
| 12615 | |
| 12616 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12617 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12618 | } |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12619 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12620 | // Simulate the SSL handshake completing with an NPN negotiation followed by an |
| 12621 | // immediate server closing of the socket. |
| 12622 | // Regression test for https://crbug.com/46369. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12623 | TEST_F(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12624 | HttpRequestInfo request; |
| 12625 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12626 | request.url = GURL("https://www.example.org/"); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12627 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12628 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12629 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12630 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12631 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12632 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 12633 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12634 | MockWrite spdy_writes[] = {CreateMockWrite(req, 1)}; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12635 | |
| 12636 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12637 | MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12638 | }; |
| 12639 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12640 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 12641 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12642 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12643 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12644 | TestCompletionCallback callback; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12645 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12646 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12647 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12648 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12649 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12650 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12651 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12652 | } |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 12653 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 12654 | // A subclass of HttpAuthHandlerMock that records the request URL when |
| 12655 | // it gets it. This is needed since the auth handler may get destroyed |
| 12656 | // before we get a chance to query it. |
| 12657 | class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock { |
| 12658 | public: |
| 12659 | explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {} |
| 12660 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12661 | ~UrlRecordingHttpAuthHandlerMock() override {} |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 12662 | |
| 12663 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12664 | int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 12665 | const HttpRequestInfo* request, |
| 12666 | const CompletionCallback& callback, |
| 12667 | std::string* auth_token) override { |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 12668 | *url_ = request->url; |
| 12669 | return HttpAuthHandlerMock::GenerateAuthTokenImpl( |
| 12670 | credentials, request, callback, auth_token); |
| 12671 | } |
| 12672 | |
| 12673 | private: |
| 12674 | GURL* url_; |
| 12675 | }; |
| 12676 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12677 | // Test that if we cancel the transaction as the connection is completing, that |
| 12678 | // everything tears down correctly. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12679 | TEST_F(HttpNetworkTransactionTest, SimpleCancel) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12680 | // Setup everything about the connection to complete synchronously, so that |
| 12681 | // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
| 12682 | // for is the callback from the HttpStreamRequest. |
| 12683 | // Then cancel the transaction. |
| 12684 | // Verify that we don't crash. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12685 | MockConnect mock_connect(SYNCHRONOUS, OK); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12686 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12687 | MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), |
| 12688 | MockRead(SYNCHRONOUS, "hello world"), |
| 12689 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12690 | }; |
| 12691 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12692 | HttpRequestInfo request; |
| 12693 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12694 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12695 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12696 | session_deps_.host_resolver->set_synchronous_mode(true); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12697 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12698 | auto trans = |
| 12699 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12700 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12701 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 12702 | data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12703 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12704 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12705 | TestCompletionCallback callback; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12706 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12707 | BoundTestNetLog log; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12708 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12709 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12710 | trans.reset(); // Cancel the transaction here. |
| 12711 | |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 12712 | base::RunLoop().RunUntilIdle(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 12713 | } |
| 12714 | |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12715 | // Test that if a transaction is cancelled after receiving the headers, the |
| 12716 | // stream is drained properly and added back to the socket pool. The main |
| 12717 | // purpose of this test is to make sure that an HttpStreamParser can be read |
| 12718 | // from after the HttpNetworkTransaction and the objects it owns have been |
| 12719 | // deleted. |
| 12720 | // See http://crbug.com/368418 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12721 | TEST_F(HttpNetworkTransactionTest, CancelAfterHeaders) { |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12722 | MockRead data_reads[] = { |
| 12723 | MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"), |
| 12724 | MockRead(ASYNC, "Content-Length: 2\r\n"), |
| 12725 | MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"), |
| 12726 | MockRead(ASYNC, "1"), |
| 12727 | // 2 async reads are necessary to trigger a ReadResponseBody call after the |
| 12728 | // HttpNetworkTransaction has been deleted. |
| 12729 | MockRead(ASYNC, "2"), |
| 12730 | MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this. |
| 12731 | }; |
| 12732 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 12733 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12734 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12735 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12736 | |
| 12737 | { |
| 12738 | HttpRequestInfo request; |
| 12739 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12740 | request.url = GURL("http://www.example.org/"); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12741 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12742 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12743 | TestCompletionCallback callback; |
| 12744 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12745 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12746 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12747 | callback.WaitForResult(); |
| 12748 | |
| 12749 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12750 | ASSERT_TRUE(response); |
| 12751 | EXPECT_TRUE(response->headers); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12752 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12753 | |
| 12754 | // The transaction and HttpRequestInfo are deleted. |
| 12755 | } |
| 12756 | |
| 12757 | // Let the HttpResponseBodyDrainer drain the socket. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 12758 | base::RunLoop().RunUntilIdle(); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12759 | |
| 12760 | // Socket should now be idle, waiting to be reused. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12761 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12762 | } |
| 12763 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12764 | // Test a basic GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12765 | TEST_F(HttpNetworkTransactionTest, ProxyGet) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12766 | session_deps_.proxy_service = |
| 12767 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12768 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12769 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12770 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12771 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12772 | HttpRequestInfo request; |
| 12773 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12774 | request.url = GURL("http://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12775 | |
| 12776 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12777 | MockWrite( |
| 12778 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 12779 | "Host: www.example.org\r\n" |
| 12780 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12781 | }; |
| 12782 | |
| 12783 | MockRead data_reads1[] = { |
| 12784 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12785 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 12786 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12787 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12788 | }; |
| 12789 | |
| 12790 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 12791 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12792 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12793 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12794 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12795 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12796 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 12797 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12798 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 12799 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 12800 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12801 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12802 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12803 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12804 | |
| 12805 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12806 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12807 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12808 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12809 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12810 | |
| 12811 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 12812 | EXPECT_EQ(200, response->headers->response_code()); |
| 12813 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 12814 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 12815 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 12816 | HostPortPair::FromString("myproxy:70")), |
| 12817 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 12818 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 12819 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 12820 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12821 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12822 | |
| 12823 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12824 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12825 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12826 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12827 | } |
| 12828 | |
| 12829 | // Test a basic HTTPS GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12830 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGet) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12831 | session_deps_.proxy_service = |
| 12832 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12833 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12834 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12835 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12836 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12837 | HttpRequestInfo request; |
| 12838 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12839 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12840 | |
| 12841 | // Since we have proxy, should try to establish tunnel. |
| 12842 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12843 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 12844 | "Host: www.example.org:443\r\n" |
| 12845 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12846 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12847 | MockWrite("GET / HTTP/1.1\r\n" |
| 12848 | "Host: www.example.org\r\n" |
| 12849 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12850 | }; |
| 12851 | |
| 12852 | MockRead data_reads1[] = { |
| 12853 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 12854 | |
| 12855 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12856 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 12857 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12858 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12859 | }; |
| 12860 | |
| 12861 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 12862 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12863 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12864 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12865 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12866 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12867 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12868 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12869 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 12870 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12871 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 12872 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 12873 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12874 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12875 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12876 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12877 | |
| 12878 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12879 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 12880 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12881 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12882 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 12883 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 12884 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12885 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 12886 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 12887 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 12888 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12889 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12890 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12891 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12892 | |
| 12893 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 12894 | EXPECT_EQ(200, response->headers->response_code()); |
| 12895 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 12896 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 12897 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 12898 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 12899 | HostPortPair::FromString("myproxy:70")), |
| 12900 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 12901 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 12902 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 12903 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12904 | |
| 12905 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12906 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12907 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12908 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12909 | } |
| 12910 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12911 | // Test a basic HTTPS GET request through a proxy, connecting to an IPv6 |
| 12912 | // literal host. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12913 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetIPv6) { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12914 | session_deps_.proxy_service = |
| 12915 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 12916 | BoundTestNetLog log; |
| 12917 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12918 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12919 | |
| 12920 | HttpRequestInfo request; |
| 12921 | request.method = "GET"; |
| 12922 | request.url = GURL("https://[::1]:443/"); |
| 12923 | |
| 12924 | // Since we have proxy, should try to establish tunnel. |
| 12925 | MockWrite data_writes1[] = { |
| 12926 | MockWrite("CONNECT [::1]:443 HTTP/1.1\r\n" |
| 12927 | "Host: [::1]:443\r\n" |
| 12928 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 12929 | |
| 12930 | MockWrite("GET / HTTP/1.1\r\n" |
| 12931 | "Host: [::1]\r\n" |
| 12932 | "Connection: keep-alive\r\n\r\n"), |
| 12933 | }; |
| 12934 | |
| 12935 | MockRead data_reads1[] = { |
| 12936 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 12937 | |
| 12938 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12939 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 12940 | MockRead("Content-Length: 100\r\n\r\n"), |
| 12941 | MockRead(SYNCHRONOUS, OK), |
| 12942 | }; |
| 12943 | |
| 12944 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 12945 | data_writes1, arraysize(data_writes1)); |
| 12946 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 12947 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12948 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12949 | |
| 12950 | TestCompletionCallback callback1; |
| 12951 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12952 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12953 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12954 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12955 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12956 | |
| 12957 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12958 | EXPECT_THAT(rv, IsOk()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12959 | TestNetLogEntry::List entries; |
| 12960 | log.GetEntries(&entries); |
| 12961 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 12962 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 12963 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12964 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 12965 | entries, pos, |
| 12966 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 12967 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12968 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12969 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12970 | ASSERT_TRUE(response); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12971 | |
| 12972 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 12973 | EXPECT_EQ(200, response->headers->response_code()); |
| 12974 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 12975 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 12976 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 12977 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 12978 | HostPortPair::FromString("myproxy:70")), |
| 12979 | response->proxy_server); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12980 | |
| 12981 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12982 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12983 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12984 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 12985 | } |
| 12986 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12987 | // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 12988 | // while establishing the tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12989 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12990 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12991 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12992 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12993 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12994 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12995 | HttpRequestInfo request; |
| 12996 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12997 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12998 | |
| 12999 | // Since we have proxy, should try to establish tunnel. |
| 13000 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13001 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 13002 | "Host: www.example.org:443\r\n" |
| 13003 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13004 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13005 | MockWrite("GET / HTTP/1.1\r\n" |
| 13006 | "Host: www.example.org\r\n" |
| 13007 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13008 | }; |
| 13009 | |
| 13010 | MockRead data_reads1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13011 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13012 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13013 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13014 | }; |
| 13015 | |
| 13016 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 13017 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13018 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13019 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13020 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13021 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13022 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13023 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13024 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13025 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13026 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13027 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13028 | |
| 13029 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13030 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 13031 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 13032 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13033 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13034 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 13035 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13036 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 13037 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13038 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 13039 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13040 | } |
| 13041 | |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13042 | // Test for crbug.com/55424. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13043 | TEST_F(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13044 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13045 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13046 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13047 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13048 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13049 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13050 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13051 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13052 | }; |
| 13053 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13054 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 13055 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13056 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13057 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13058 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13059 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13060 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13061 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13062 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13063 | |
| 13064 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13065 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 13066 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 13067 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13068 | base::WeakPtr<SpdySession> spdy_session = |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13069 | CreateSecureSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13070 | |
| 13071 | HttpRequestInfo request; |
| 13072 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13073 | request.url = GURL("https://www.example.org/"); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13074 | |
| 13075 | // This is the important line that marks this as a preconnect. |
| 13076 | request.motivation = HttpRequestInfo::PRECONNECT_MOTIVATED; |
| 13077 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13078 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13079 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13080 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13081 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13082 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13083 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13084 | } |
| 13085 | |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13086 | // Given a net error, cause that error to be returned from the first Write() |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13087 | // call and verify that the HttpNetworkTransaction fails with that error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13088 | void HttpNetworkTransactionTest::CheckErrorIsPassedBack( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13089 | int error, IoMode mode) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13090 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13091 | request_info.url = GURL("https://www.example.com/"); |
| 13092 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13093 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13094 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13095 | SSLSocketDataProvider ssl_data(mode, OK); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13096 | MockWrite data_writes[] = { |
| 13097 | MockWrite(mode, error), |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13098 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13099 | StaticSocketDataProvider data(NULL, 0, data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13100 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13101 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13102 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13103 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13104 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13105 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13106 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13107 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13108 | if (rv == ERR_IO_PENDING) |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13109 | rv = callback.WaitForResult(); |
| 13110 | ASSERT_EQ(error, rv); |
| 13111 | } |
| 13112 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13113 | TEST_F(HttpNetworkTransactionTest, SSLWriteCertError) { |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13114 | // Just check a grab bag of cert errors. |
| 13115 | static const int kErrors[] = { |
| 13116 | ERR_CERT_COMMON_NAME_INVALID, |
| 13117 | ERR_CERT_AUTHORITY_INVALID, |
| 13118 | ERR_CERT_DATE_INVALID, |
| 13119 | }; |
| 13120 | for (size_t i = 0; i < arraysize(kErrors); i++) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13121 | CheckErrorIsPassedBack(kErrors[i], ASYNC); |
| 13122 | CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13123 | } |
| 13124 | } |
| 13125 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13126 | // Ensure that a client certificate is removed from the SSL client auth |
| 13127 | // cache when: |
| 13128 | // 1) No proxy is involved. |
| 13129 | // 2) TLS False Start is disabled. |
| 13130 | // 3) The initial TLS handshake requests a client certificate. |
| 13131 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13132 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_NoFalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13133 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13134 | request_info.url = GURL("https://www.example.com/"); |
| 13135 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13136 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13137 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13138 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13139 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13140 | |
| 13141 | // [ssl_]data1 contains the data for the first SSL handshake. When a |
| 13142 | // CertificateRequest is received for the first time, the handshake will |
| 13143 | // be aborted to allow the caller to provide a certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13144 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13145 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13146 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13147 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13148 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13149 | |
| 13150 | // [ssl_]data2 contains the data for the second SSL handshake. When TLS |
| 13151 | // False Start is not being used, the result of the SSL handshake will be |
| 13152 | // returned as part of the SSLClientSocket::Connect() call. This test |
| 13153 | // matches the result of a server sending a handshake_failure alert, |
| 13154 | // rather than a Finished message, because it requires a client |
| 13155 | // certificate and none was supplied. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13156 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13157 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13158 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13159 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13160 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13161 | |
| 13162 | // [ssl_]data3 contains the data for the third SSL handshake. When a |
| 13163 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 13164 | // HttpNetworkTransaction will attempt to fallback to TLSv1.1 if the previous |
| 13165 | // connection was attempted with TLSv1.2. This is transparent to the caller |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13166 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 13167 | // requiring a client certificate, this fallback handshake should also |
| 13168 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13169 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13170 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13171 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13172 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13173 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13174 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13175 | // [ssl_]data4 contains the data for the fourth SSL handshake. When a |
| 13176 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 13177 | // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous |
| 13178 | // connection was attempted with TLSv1.1. This is transparent to the caller |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13179 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 13180 | // requiring a client certificate, this fallback handshake should also |
| 13181 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13182 | SSLSocketDataProvider ssl_data4(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13183 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13184 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13185 | StaticSocketDataProvider data4(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13186 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13187 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13188 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13189 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13190 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13191 | // Begin the SSL handshake with the peer. This consumes ssl_data1. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13192 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13193 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13194 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13195 | |
| 13196 | // Complete the SSL handshake, which should abort due to requiring a |
| 13197 | // client certificate. |
| 13198 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13199 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13200 | |
| 13201 | // Indicate that no certificate should be supplied. From the perspective |
| 13202 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 13203 | // certificate, so this is the same as supply a |
| 13204 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13205 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13206 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13207 | |
| 13208 | // Ensure the certificate was added to the client auth cache before |
| 13209 | // allowing the connection to continue restarting. |
| 13210 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13211 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13212 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13213 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13214 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13215 | |
| 13216 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13217 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 13218 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13219 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13220 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13221 | |
| 13222 | // Ensure that the client certificate is removed from the cache on a |
| 13223 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13224 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13225 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13226 | } |
| 13227 | |
| 13228 | // Ensure that a client certificate is removed from the SSL client auth |
| 13229 | // cache when: |
| 13230 | // 1) No proxy is involved. |
| 13231 | // 2) TLS False Start is enabled. |
| 13232 | // 3) The initial TLS handshake requests a client certificate. |
| 13233 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13234 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_FalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13235 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13236 | request_info.url = GURL("https://www.example.com/"); |
| 13237 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13238 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13239 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13240 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13241 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13242 | |
| 13243 | // When TLS False Start is used, SSLClientSocket::Connect() calls will |
| 13244 | // return successfully after reading up to the peer's Certificate message. |
| 13245 | // This is to allow the caller to call SSLClientSocket::Write(), which can |
| 13246 | // enqueue application data to be sent in the same packet as the |
| 13247 | // ChangeCipherSpec and Finished messages. |
| 13248 | // The actual handshake will be finished when SSLClientSocket::Read() is |
| 13249 | // called, which expects to process the peer's ChangeCipherSpec and |
| 13250 | // Finished messages. If there was an error negotiating with the peer, |
| 13251 | // such as due to the peer requiring a client certificate when none was |
| 13252 | // supplied, the alert sent by the peer won't be processed until Read() is |
| 13253 | // called. |
| 13254 | |
| 13255 | // Like the non-False Start case, when a client certificate is requested by |
| 13256 | // the peer, the handshake is aborted during the Connect() call. |
| 13257 | // [ssl_]data1 represents the initial SSL handshake with the peer. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13258 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13259 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13260 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13261 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13262 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13263 | |
| 13264 | // When a client certificate is supplied, Connect() will not be aborted |
| 13265 | // when the peer requests the certificate. Instead, the handshake will |
| 13266 | // artificially succeed, allowing the caller to write the HTTP request to |
| 13267 | // the socket. The handshake messages are not processed until Read() is |
| 13268 | // called, which then detects that the handshake was aborted, due to the |
| 13269 | // peer sending a handshake_failure because it requires a client |
| 13270 | // certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13271 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13272 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13273 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13274 | MockRead data2_reads[] = { |
| 13275 | MockRead(ASYNC /* async */, ERR_SSL_PROTOCOL_ERROR), |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13276 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13277 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13278 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13279 | |
| 13280 | // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13281 | // the data for the SSL handshake once the TLSv1.1 connection falls back to |
| 13282 | // TLSv1. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13283 | SSLSocketDataProvider ssl_data3(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13284 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13285 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13286 | StaticSocketDataProvider data3(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13287 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13288 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13289 | // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection |
| 13290 | // falls back to SSLv3. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13291 | SSLSocketDataProvider ssl_data4(ASYNC, OK); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13292 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13293 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13294 | StaticSocketDataProvider data4(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13295 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13296 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 13297 | // Need one more if TLSv1.2 is enabled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13298 | SSLSocketDataProvider ssl_data5(ASYNC, OK); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 13299 | ssl_data5.cert_request_info = cert_request.get(); |
| 13300 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13301 | StaticSocketDataProvider data5(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 13302 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 13303 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13304 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13305 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13306 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13307 | // Begin the initial SSL handshake. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13308 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13309 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13310 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13311 | |
| 13312 | // Complete the SSL handshake, which should abort due to requiring a |
| 13313 | // client certificate. |
| 13314 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13315 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13316 | |
| 13317 | // Indicate that no certificate should be supplied. From the perspective |
| 13318 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 13319 | // certificate, so this is the same as supply a |
| 13320 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13321 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13322 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13323 | |
| 13324 | // Ensure the certificate was added to the client auth cache before |
| 13325 | // allowing the connection to continue restarting. |
| 13326 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13327 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13328 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13329 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13330 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13331 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13332 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13333 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 13334 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13335 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13336 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13337 | |
| 13338 | // Ensure that the client certificate is removed from the cache on a |
| 13339 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13340 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13341 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13342 | } |
| 13343 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13344 | // Ensure that a client certificate is removed from the SSL client auth |
| 13345 | // cache when: |
| 13346 | // 1) An HTTPS proxy is involved. |
| 13347 | // 3) The HTTPS proxy requests a client certificate. |
| 13348 | // 4) The client supplies an invalid/unacceptable certificate for the |
| 13349 | // proxy. |
| 13350 | // The test is repeated twice, first for connecting to an HTTPS endpoint, |
| 13351 | // then for connecting to an HTTP endpoint. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13352 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 13353 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13354 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13355 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13356 | |
| 13357 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13358 | cert_request->host_and_port = HostPortPair("proxy", 70); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13359 | |
| 13360 | // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of |
| 13361 | // [ssl_]data[1-3]. Rather than represending the endpoint |
| 13362 | // (www.example.com:443), they represent failures with the HTTPS proxy |
| 13363 | // (proxy:70). |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13364 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13365 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13366 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13367 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13368 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13369 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13370 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13371 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13372 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13373 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13374 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13375 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13376 | // TODO(wtc): find out why this unit test doesn't need [ssl_]data3. |
| 13377 | #if 0 |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13378 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13379 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13380 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13381 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13382 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13383 | #endif |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13384 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13385 | HttpRequestInfo requests[2]; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13386 | requests[0].url = GURL("https://www.example.com/"); |
| 13387 | requests[0].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13388 | requests[0].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13389 | |
| 13390 | requests[1].url = GURL("http://www.example.com/"); |
| 13391 | requests[1].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13392 | requests[1].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13393 | |
| 13394 | for (size_t i = 0; i < arraysize(requests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13395 | session_deps_.socket_factory->ResetNextMockIndexes(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13396 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13397 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13398 | |
| 13399 | // Begin the SSL handshake with the proxy. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13400 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13401 | int rv = trans.Start(&requests[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13402 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13403 | |
| 13404 | // Complete the SSL handshake, which should abort due to requiring a |
| 13405 | // client certificate. |
| 13406 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13407 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13408 | |
| 13409 | // Indicate that no certificate should be supplied. From the perspective |
| 13410 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 13411 | // certificate, so this is the same as supply a |
| 13412 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13413 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13414 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13415 | |
| 13416 | // Ensure the certificate was added to the client auth cache before |
| 13417 | // allowing the connection to continue restarting. |
| 13418 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13419 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13420 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13421 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13422 | ASSERT_FALSE(client_cert); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13423 | // Ensure the certificate was NOT cached for the endpoint. This only |
| 13424 | // applies to HTTPS requests, but is fine to check for HTTP requests. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13425 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13426 | HostPortPair("www.example.com", 443), &client_cert, |
| 13427 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13428 | |
| 13429 | // Restart the handshake. This will consume ssl_data2, which fails, and |
| 13430 | // then consume ssl_data3, which should also fail. The result code is |
| 13431 | // checked against what ssl_data3 should return. |
| 13432 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13433 | ASSERT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13434 | |
| 13435 | // Now that the new handshake has failed, ensure that the client |
| 13436 | // certificate was removed from the client auth cache. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13437 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13438 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13439 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13440 | HostPortPair("www.example.com", 443), &client_cert, |
| 13441 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13442 | } |
| 13443 | } |
| 13444 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13445 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPooling) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13446 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13447 | session_deps_.host_resolver = base::MakeUnique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13448 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13449 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13450 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13451 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13452 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13453 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13454 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13455 | SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13456 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13457 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13458 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13459 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13460 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13461 | SpdySerializedFrame host1_resp_body( |
| 13462 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13463 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13464 | SpdySerializedFrame host2_resp_body( |
| 13465 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13466 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13467 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 13468 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13469 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13470 | }; |
| 13471 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 13472 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13473 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13474 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 13475 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13476 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13477 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 13478 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13479 | HttpRequestInfo request1; |
| 13480 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13481 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13482 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13483 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13484 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13485 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13486 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13487 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13488 | |
| 13489 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13490 | ASSERT_TRUE(response); |
| 13491 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13492 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13493 | |
| 13494 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13495 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13496 | EXPECT_EQ("hello!", response_data); |
| 13497 | |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13498 | // Preload mail.example.com into HostCache. |
| 13499 | HostPortPair host_port("mail.example.com", 443); |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 13500 | HostResolver::RequestInfo resolve_info(host_port); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13501 | AddressList ignored; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 13502 | std::unique_ptr<HostResolver::Request> request; |
| 13503 | rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 13504 | &ignored, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13505 | &request, NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13506 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 13507 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13508 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13509 | |
| 13510 | HttpRequestInfo request2; |
| 13511 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13512 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13513 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13514 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13515 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13516 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13517 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13518 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13519 | |
| 13520 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13521 | ASSERT_TRUE(response); |
| 13522 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13523 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13524 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13525 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13526 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13527 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13528 | } |
| 13529 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13530 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) { |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13531 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13532 | session_deps_.host_resolver = base::MakeUnique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13533 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13534 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13535 | AddSSLSocketData(); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13536 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13537 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13538 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13539 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13540 | SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13541 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13542 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13543 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13544 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13545 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13546 | SpdySerializedFrame host1_resp_body( |
| 13547 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13548 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13549 | SpdySerializedFrame host2_resp_body( |
| 13550 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13551 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13552 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 13553 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13554 | MockRead(ASYNC, 0, 6), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13555 | }; |
| 13556 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 13557 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13558 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13559 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 13560 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13561 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13562 | |
| 13563 | TestCompletionCallback callback; |
| 13564 | HttpRequestInfo request1; |
| 13565 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13566 | request1.url = GURL("https://www.example.org/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13567 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13568 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13569 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13570 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13571 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13572 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13573 | |
| 13574 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13575 | ASSERT_TRUE(response); |
| 13576 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13577 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13578 | |
| 13579 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13580 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13581 | EXPECT_EQ("hello!", response_data); |
| 13582 | |
| 13583 | HttpRequestInfo request2; |
| 13584 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13585 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13586 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13587 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13588 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13589 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13590 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13591 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13592 | |
| 13593 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13594 | ASSERT_TRUE(response); |
| 13595 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13596 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13597 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13598 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13599 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13600 | EXPECT_EQ("hello!", response_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13601 | } |
| 13602 | |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 13603 | // Regression test for https://crbug.com/546991. |
| 13604 | // The server might not be able to serve an IP pooled request, and might send a |
| 13605 | // 421 Misdirected Request response status to indicate this. |
| 13606 | // HttpNetworkTransaction should reset the request and retry without IP pooling. |
| 13607 | TEST_F(HttpNetworkTransactionTest, RetryWithoutConnectionPooling) { |
| 13608 | // Two hosts resolve to the same IP address. |
| 13609 | const std::string ip_addr = "1.2.3.4"; |
| 13610 | IPAddress ip; |
| 13611 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 13612 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 13613 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13614 | session_deps_.host_resolver = base::MakeUnique<MockCachingHostResolver>(); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 13615 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 13616 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 13617 | |
| 13618 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13619 | |
| 13620 | // Two requests on the first connection. |
| 13621 | SpdySerializedFrame req1( |
| 13622 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 13623 | spdy_util_.UpdateWithStreamDestruction(1); |
| 13624 | SpdySerializedFrame req2( |
| 13625 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
| 13626 | SpdySerializedFrame rst( |
| 13627 | spdy_util_.ConstructSpdyRstStream(3, ERROR_CODE_CANCEL)); |
| 13628 | MockWrite writes1[] = { |
| 13629 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 13630 | CreateMockWrite(rst, 6), |
| 13631 | }; |
| 13632 | |
| 13633 | // The first one succeeds, the second gets error 421 Misdirected Request. |
| 13634 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 13635 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 13636 | SpdyHeaderBlock response_headers; |
| 13637 | response_headers[SpdyTestUtil::GetStatusKey()] = "421"; |
| 13638 | SpdySerializedFrame resp2( |
| 13639 | spdy_util_.ConstructSpdyReply(3, std::move(response_headers))); |
| 13640 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 13641 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 13642 | |
| 13643 | MockConnect connect1(ASYNC, OK, peer_addr); |
| 13644 | SequencedSocketData data1(connect1, reads1, arraysize(reads1), writes1, |
| 13645 | arraysize(writes1)); |
| 13646 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 13647 | |
| 13648 | AddSSLSocketData(); |
| 13649 | |
| 13650 | // Retry the second request on a second connection. |
| 13651 | SpdyTestUtil spdy_util2; |
| 13652 | SpdySerializedFrame req3( |
| 13653 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 13654 | MockWrite writes2[] = { |
| 13655 | CreateMockWrite(req3, 0), |
| 13656 | }; |
| 13657 | |
| 13658 | SpdySerializedFrame resp3(spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 13659 | SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 13660 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 13661 | MockRead(ASYNC, 0, 3)}; |
| 13662 | |
| 13663 | MockConnect connect2(ASYNC, OK, peer_addr); |
| 13664 | SequencedSocketData data2(connect2, reads2, arraysize(reads2), writes2, |
| 13665 | arraysize(writes2)); |
| 13666 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 13667 | |
| 13668 | AddSSLSocketData(); |
| 13669 | |
| 13670 | // Preload mail.example.org into HostCache. |
| 13671 | HostPortPair host_port("mail.example.org", 443); |
| 13672 | HostResolver::RequestInfo resolve_info(host_port); |
| 13673 | AddressList ignored; |
| 13674 | std::unique_ptr<HostResolver::Request> request; |
| 13675 | TestCompletionCallback callback; |
| 13676 | int rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 13677 | &ignored, callback.callback(), |
| 13678 | &request, NetLogWithSource()); |
| 13679 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13680 | rv = callback.WaitForResult(); |
| 13681 | EXPECT_THAT(rv, IsOk()); |
| 13682 | |
| 13683 | HttpRequestInfo request1; |
| 13684 | request1.method = "GET"; |
| 13685 | request1.url = GURL("https://www.example.org/"); |
| 13686 | request1.load_flags = 0; |
| 13687 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 13688 | |
| 13689 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 13690 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13691 | rv = callback.WaitForResult(); |
| 13692 | EXPECT_THAT(rv, IsOk()); |
| 13693 | |
| 13694 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 13695 | ASSERT_TRUE(response); |
| 13696 | ASSERT_TRUE(response->headers); |
| 13697 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 13698 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 13699 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 13700 | std::string response_data; |
| 13701 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 13702 | EXPECT_EQ("hello!", response_data); |
| 13703 | |
| 13704 | HttpRequestInfo request2; |
| 13705 | request2.method = "GET"; |
| 13706 | request2.url = GURL("https://mail.example.org/"); |
| 13707 | request2.load_flags = 0; |
| 13708 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 13709 | |
| 13710 | BoundTestNetLog log; |
| 13711 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 13712 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13713 | rv = callback.WaitForResult(); |
| 13714 | EXPECT_THAT(rv, IsOk()); |
| 13715 | |
| 13716 | response = trans2.GetResponseInfo(); |
| 13717 | ASSERT_TRUE(response); |
| 13718 | ASSERT_TRUE(response->headers); |
| 13719 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 13720 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 13721 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 13722 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 13723 | EXPECT_EQ("hello!", response_data); |
| 13724 | |
| 13725 | TestNetLogEntry::List entries; |
| 13726 | log.GetEntries(&entries); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 13727 | ExpectLogContainsSomewhere( |
| 13728 | entries, 0, NetLogEventType::HTTP_TRANSACTION_RESTART_MISDIRECTED_REQUEST, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 13729 | NetLogEventPhase::NONE); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 13730 | } |
| 13731 | |
| 13732 | // Test that HTTP 421 responses are properly returned to the caller if received |
| 13733 | // on the retry as well. HttpNetworkTransaction should not infinite loop or lose |
| 13734 | // portions of the response. |
| 13735 | TEST_F(HttpNetworkTransactionTest, ReturnHTTP421OnRetry) { |
| 13736 | // Two hosts resolve to the same IP address. |
| 13737 | const std::string ip_addr = "1.2.3.4"; |
| 13738 | IPAddress ip; |
| 13739 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 13740 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 13741 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13742 | session_deps_.host_resolver = base::MakeUnique<MockCachingHostResolver>(); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 13743 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 13744 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 13745 | |
| 13746 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13747 | |
| 13748 | // Two requests on the first connection. |
| 13749 | SpdySerializedFrame req1( |
| 13750 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 13751 | spdy_util_.UpdateWithStreamDestruction(1); |
| 13752 | SpdySerializedFrame req2( |
| 13753 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
| 13754 | SpdySerializedFrame rst( |
| 13755 | spdy_util_.ConstructSpdyRstStream(3, ERROR_CODE_CANCEL)); |
| 13756 | MockWrite writes1[] = { |
| 13757 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 13758 | CreateMockWrite(rst, 6), |
| 13759 | }; |
| 13760 | |
| 13761 | // The first one succeeds, the second gets error 421 Misdirected Request. |
| 13762 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 13763 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 13764 | SpdyHeaderBlock response_headers; |
| 13765 | response_headers[SpdyTestUtil::GetStatusKey()] = "421"; |
| 13766 | SpdySerializedFrame resp2( |
| 13767 | spdy_util_.ConstructSpdyReply(3, response_headers.Clone())); |
| 13768 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 13769 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 13770 | |
| 13771 | MockConnect connect1(ASYNC, OK, peer_addr); |
| 13772 | SequencedSocketData data1(connect1, reads1, arraysize(reads1), writes1, |
| 13773 | arraysize(writes1)); |
| 13774 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 13775 | |
| 13776 | AddSSLSocketData(); |
| 13777 | |
| 13778 | // Retry the second request on a second connection. It returns 421 Misdirected |
| 13779 | // Retry again. |
| 13780 | SpdyTestUtil spdy_util2; |
| 13781 | SpdySerializedFrame req3( |
| 13782 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 13783 | MockWrite writes2[] = { |
| 13784 | CreateMockWrite(req3, 0), |
| 13785 | }; |
| 13786 | |
| 13787 | SpdySerializedFrame resp3( |
| 13788 | spdy_util2.ConstructSpdyReply(1, std::move(response_headers))); |
| 13789 | SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 13790 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 13791 | MockRead(ASYNC, 0, 3)}; |
| 13792 | |
| 13793 | MockConnect connect2(ASYNC, OK, peer_addr); |
| 13794 | SequencedSocketData data2(connect2, reads2, arraysize(reads2), writes2, |
| 13795 | arraysize(writes2)); |
| 13796 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 13797 | |
| 13798 | AddSSLSocketData(); |
| 13799 | |
| 13800 | // Preload mail.example.org into HostCache. |
| 13801 | HostPortPair host_port("mail.example.org", 443); |
| 13802 | HostResolver::RequestInfo resolve_info(host_port); |
| 13803 | AddressList ignored; |
| 13804 | std::unique_ptr<HostResolver::Request> request; |
| 13805 | TestCompletionCallback callback; |
| 13806 | int rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 13807 | &ignored, callback.callback(), |
| 13808 | &request, NetLogWithSource()); |
| 13809 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13810 | rv = callback.WaitForResult(); |
| 13811 | EXPECT_THAT(rv, IsOk()); |
| 13812 | |
| 13813 | HttpRequestInfo request1; |
| 13814 | request1.method = "GET"; |
| 13815 | request1.url = GURL("https://www.example.org/"); |
| 13816 | request1.load_flags = 0; |
| 13817 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 13818 | |
| 13819 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 13820 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13821 | rv = callback.WaitForResult(); |
| 13822 | EXPECT_THAT(rv, IsOk()); |
| 13823 | |
| 13824 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 13825 | ASSERT_TRUE(response); |
| 13826 | ASSERT_TRUE(response->headers); |
| 13827 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 13828 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 13829 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 13830 | std::string response_data; |
| 13831 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 13832 | EXPECT_EQ("hello!", response_data); |
| 13833 | |
| 13834 | HttpRequestInfo request2; |
| 13835 | request2.method = "GET"; |
| 13836 | request2.url = GURL("https://mail.example.org/"); |
| 13837 | request2.load_flags = 0; |
| 13838 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 13839 | |
| 13840 | BoundTestNetLog log; |
| 13841 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 13842 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13843 | rv = callback.WaitForResult(); |
| 13844 | EXPECT_THAT(rv, IsOk()); |
| 13845 | |
| 13846 | // After a retry, the 421 Misdirected Request is reported back up to the |
| 13847 | // caller. |
| 13848 | response = trans2.GetResponseInfo(); |
| 13849 | ASSERT_TRUE(response); |
| 13850 | ASSERT_TRUE(response->headers); |
| 13851 | EXPECT_EQ("HTTP/1.1 421", response->headers->GetStatusLine()); |
| 13852 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 13853 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 13854 | EXPECT_TRUE(response->ssl_info.cert); |
| 13855 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 13856 | EXPECT_EQ("hello!", response_data); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 13857 | } |
| 13858 | |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 13859 | class OneTimeCachingHostResolver : public MockHostResolverBase { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13860 | public: |
| 13861 | explicit OneTimeCachingHostResolver(const HostPortPair& host_port) |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 13862 | : MockHostResolverBase(/* use_caching = */ true), host_port_(host_port) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13863 | ~OneTimeCachingHostResolver() override {} |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13864 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13865 | int ResolveFromCache(const RequestInfo& info, |
| 13866 | AddressList* addresses, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13867 | const NetLogWithSource& net_log) override { |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 13868 | int rv = MockHostResolverBase::ResolveFromCache(info, addresses, net_log); |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 13869 | if (rv == OK && info.host_port_pair().Equals(host_port_)) |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 13870 | GetHostCache()->clear(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13871 | return rv; |
| 13872 | } |
| 13873 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13874 | private: |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13875 | const HostPortPair host_port_; |
| 13876 | }; |
| 13877 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13878 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 13879 | UseIPConnectionPoolingWithHostCacheExpiration) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13880 | // Set up a special HttpNetworkSession with a OneTimeCachingHostResolver. |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 13881 | session_deps_.host_resolver = base::MakeUnique<OneTimeCachingHostResolver>( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13882 | HostPortPair("mail.example.com", 443)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13883 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13884 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13885 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13886 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13887 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13888 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13889 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13890 | SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13891 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13892 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13893 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13894 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13895 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13896 | SpdySerializedFrame host1_resp_body( |
| 13897 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13898 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13899 | SpdySerializedFrame host2_resp_body( |
| 13900 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13901 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13902 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 13903 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13904 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13905 | }; |
| 13906 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 13907 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13908 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13909 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 13910 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13911 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13912 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 13913 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13914 | HttpRequestInfo request1; |
| 13915 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13916 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13917 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13918 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13919 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13920 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13921 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13922 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13923 | |
| 13924 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13925 | ASSERT_TRUE(response); |
| 13926 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13927 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13928 | |
| 13929 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13930 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13931 | EXPECT_EQ("hello!", response_data); |
| 13932 | |
| 13933 | // Preload cache entries into HostCache. |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13934 | HostResolver::RequestInfo resolve_info(HostPortPair("mail.example.com", 443)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13935 | AddressList ignored; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 13936 | std::unique_ptr<HostResolver::Request> request; |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 13937 | rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 13938 | &ignored, callback.callback(), |
| 13939 | &request, NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13940 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 13941 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13942 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13943 | |
| 13944 | HttpRequestInfo request2; |
| 13945 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13946 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13947 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13948 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13949 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13950 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13951 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13952 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13953 | |
| 13954 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13955 | ASSERT_TRUE(response); |
| 13956 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13957 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13958 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13959 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13960 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13961 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13962 | } |
| 13963 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13964 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13965 | const std::string https_url = "https://www.example.org:8080/"; |
| 13966 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13967 | |
| 13968 | // SPDY GET for HTTPS URL |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13969 | SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13970 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13971 | |
| 13972 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13973 | CreateMockWrite(req1, 0), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13974 | }; |
| 13975 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13976 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13977 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 13978 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 13979 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3)}; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13980 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13981 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 13982 | arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13983 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 13984 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13985 | |
| 13986 | // HTTP GET for the HTTP URL |
| 13987 | MockWrite writes2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13988 | MockWrite(ASYNC, 0, |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 13989 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13990 | "Host: www.example.org:8080\r\n" |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 13991 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13992 | }; |
| 13993 | |
| 13994 | MockRead reads2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13995 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 13996 | MockRead(ASYNC, 2, "hello"), |
| 13997 | MockRead(ASYNC, OK, 3), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 13998 | }; |
| 13999 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14000 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 14001 | arraysize(writes2)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14002 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14003 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14004 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14005 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14006 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 14007 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14008 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14009 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14010 | |
| 14011 | // Start the first transaction to set up the SpdySession |
| 14012 | HttpRequestInfo request1; |
| 14013 | request1.method = "GET"; |
| 14014 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14015 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14016 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14017 | TestCompletionCallback callback1; |
| 14018 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14019 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 14020 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14021 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14022 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14023 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 14024 | |
| 14025 | // Now, start the HTTP request |
| 14026 | HttpRequestInfo request2; |
| 14027 | request2.method = "GET"; |
| 14028 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14029 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14030 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14031 | TestCompletionCallback callback2; |
| 14032 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14033 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 14034 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14035 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14036 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14037 | EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 14038 | } |
| 14039 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14040 | // Alternative service requires HTTP/2 (or SPDY), but HTTP/1.1 is negotiated |
| 14041 | // with the alternative server. That connection should not be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14042 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceNotOnHttp11) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14043 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 14044 | HostPortPair alternative("www.example.org", 444); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14045 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14046 | // Negotiate HTTP/1.1 with alternative. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14047 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14048 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14049 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14050 | |
| 14051 | // No data should be read from the alternative, because HTTP/1.1 is |
| 14052 | // negotiated. |
| 14053 | StaticSocketDataProvider data; |
| 14054 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14055 | |
| 14056 | // 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] | 14057 | // negotiated. In order to test this, a failed connection to the server is |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14058 | // mocked. This way the request relies on the alternate Job. |
| 14059 | StaticSocketDataProvider data_refused; |
| 14060 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 14061 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 14062 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14063 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14064 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 14065 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14066 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 14067 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 14068 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14069 | http_server_properties->SetAlternativeService(server, alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 14070 | expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14071 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14072 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 14073 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14074 | request.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14075 | request.url = GURL("https://www.example.org:443"); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14076 | TestCompletionCallback callback; |
| 14077 | |
| 14078 | // HTTP/2 (or SPDY) is required for alternative service, if HTTP/1.1 is |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14079 | // negotiated, the alternate Job should fail with ERR_ALPN_NEGOTIATION_FAILED. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14080 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14081 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_ALPN_NEGOTIATION_FAILED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14082 | } |
| 14083 | |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14084 | // 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] | 14085 | // server, and an alternate one to the alternative server. If the former |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14086 | // succeeds, the request should succeed, even if the latter fails because |
| 14087 | // HTTP/1.1 is negotiated which is insufficient for alternative service. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14088 | TEST_F(HttpNetworkTransactionTest, FailedAlternativeServiceIsNotUserVisible) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14089 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 14090 | HostPortPair alternative("www.example.org", 444); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14091 | |
| 14092 | // Negotiate HTTP/1.1 with alternative. |
| 14093 | SSLSocketDataProvider alternative_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14094 | alternative_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14095 | session_deps_.socket_factory->AddSSLSocketDataProvider(&alternative_ssl); |
| 14096 | |
| 14097 | // No data should be read from the alternative, because HTTP/1.1 is |
| 14098 | // negotiated. |
| 14099 | StaticSocketDataProvider data; |
| 14100 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14101 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14102 | // Negotiate HTTP/1.1 with server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14103 | SSLSocketDataProvider origin_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14104 | origin_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14105 | session_deps_.socket_factory->AddSSLSocketDataProvider(&origin_ssl); |
| 14106 | |
| 14107 | MockWrite http_writes[] = { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14108 | MockWrite("GET / HTTP/1.1\r\n" |
| 14109 | "Host: www.example.org\r\n" |
| 14110 | "Connection: keep-alive\r\n\r\n"), |
| 14111 | MockWrite("GET /second HTTP/1.1\r\n" |
| 14112 | "Host: www.example.org\r\n" |
| 14113 | "Connection: keep-alive\r\n\r\n"), |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14114 | }; |
| 14115 | |
| 14116 | MockRead http_reads[] = { |
| 14117 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14118 | MockRead("Content-Type: text/html\r\n"), |
| 14119 | MockRead("Content-Length: 6\r\n\r\n"), |
| 14120 | MockRead("foobar"), |
| 14121 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14122 | MockRead("Content-Type: text/html\r\n"), |
| 14123 | MockRead("Content-Length: 7\r\n\r\n"), |
| 14124 | MockRead("another"), |
| 14125 | }; |
| 14126 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 14127 | http_writes, arraysize(http_writes)); |
| 14128 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 14129 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14130 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14131 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 14132 | HttpServerProperties* http_server_properties = |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14133 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 14134 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 14135 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14136 | http_server_properties->SetAlternativeService(server, alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 14137 | expiration); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14138 | |
| 14139 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 14140 | HttpRequestInfo request1; |
| 14141 | request1.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14142 | request1.url = GURL("https://www.example.org:443"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14143 | request1.load_flags = 0; |
| 14144 | TestCompletionCallback callback1; |
| 14145 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14146 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14147 | rv = callback1.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14148 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14149 | |
| 14150 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14151 | ASSERT_TRUE(response1); |
| 14152 | ASSERT_TRUE(response1->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14153 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 14154 | |
| 14155 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14156 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14157 | EXPECT_EQ("foobar", response_data1); |
| 14158 | |
| 14159 | // Alternative should be marked as broken, because HTTP/1.1 is not sufficient |
| 14160 | // for alternative service. |
| 14161 | EXPECT_TRUE( |
| 14162 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
| 14163 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14164 | // Since |alternative_service| is broken, a second transaction to server |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14165 | // should not start an alternate Job. It should pool to existing connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14166 | // to server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14167 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 14168 | HttpRequestInfo request2; |
| 14169 | request2.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14170 | request2.url = GURL("https://www.example.org:443/second"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14171 | request2.load_flags = 0; |
| 14172 | TestCompletionCallback callback2; |
| 14173 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14174 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14175 | rv = callback2.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14176 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14177 | |
| 14178 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14179 | ASSERT_TRUE(response2); |
| 14180 | ASSERT_TRUE(response2->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14181 | EXPECT_EQ("HTTP/1.1 200 OK", response2->headers->GetStatusLine()); |
| 14182 | |
| 14183 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14184 | ASSERT_THAT(ReadTransaction(&trans2, &response_data2), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14185 | EXPECT_EQ("another", response_data2); |
| 14186 | } |
| 14187 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14188 | // Alternative service requires HTTP/2 (or SPDY), but there is already a |
| 14189 | // HTTP/1.1 socket open to the alternative server. That socket should not be |
| 14190 | // used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14191 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceShouldNotPoolToHttp11) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14192 | url::SchemeHostPort server("https", "origin.example.org", 443); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14193 | HostPortPair alternative("alternative.example.org", 443); |
| 14194 | std::string origin_url = "https://origin.example.org:443"; |
| 14195 | std::string alternative_url = "https://alternative.example.org:443"; |
| 14196 | |
| 14197 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 14198 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14199 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14200 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14201 | |
| 14202 | // HTTP/1.1 data for |request1| and |request2|. |
| 14203 | MockWrite http_writes[] = { |
| 14204 | MockWrite( |
| 14205 | "GET / HTTP/1.1\r\n" |
| 14206 | "Host: alternative.example.org\r\n" |
| 14207 | "Connection: keep-alive\r\n\r\n"), |
| 14208 | MockWrite( |
| 14209 | "GET / HTTP/1.1\r\n" |
| 14210 | "Host: alternative.example.org\r\n" |
| 14211 | "Connection: keep-alive\r\n\r\n"), |
| 14212 | }; |
| 14213 | |
| 14214 | MockRead http_reads[] = { |
| 14215 | MockRead( |
| 14216 | "HTTP/1.1 200 OK\r\n" |
| 14217 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 14218 | "Content-Length: 40\r\n\r\n" |
| 14219 | "first HTTP/1.1 response from alternative"), |
| 14220 | MockRead( |
| 14221 | "HTTP/1.1 200 OK\r\n" |
| 14222 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 14223 | "Content-Length: 41\r\n\r\n" |
| 14224 | "second HTTP/1.1 response from alternative"), |
| 14225 | }; |
| 14226 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 14227 | http_writes, arraysize(http_writes)); |
| 14228 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 14229 | |
| 14230 | // This test documents that an alternate Job should not pool to an already |
| 14231 | // existing HTTP/1.1 connection. In order to test this, a failed connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14232 | // to the server is mocked. This way |request2| relies on the alternate Job. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14233 | StaticSocketDataProvider data_refused; |
| 14234 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 14235 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 14236 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14237 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14238 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 14239 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14240 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 14241 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 14242 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14243 | http_server_properties->SetAlternativeService(server, alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 14244 | expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14245 | |
| 14246 | // First transaction to alternative to open an HTTP/1.1 socket. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14247 | HttpRequestInfo request1; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 14248 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14249 | request1.method = "GET"; |
| 14250 | request1.url = GURL(alternative_url); |
| 14251 | request1.load_flags = 0; |
| 14252 | TestCompletionCallback callback1; |
| 14253 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14254 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14255 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14256 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14257 | ASSERT_TRUE(response1); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14258 | ASSERT_TRUE(response1->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14259 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14260 | EXPECT_TRUE(response1->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14261 | EXPECT_FALSE(response1->was_fetched_via_spdy); |
| 14262 | std::string response_data1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14263 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14264 | EXPECT_EQ("first HTTP/1.1 response from alternative", response_data1); |
| 14265 | |
| 14266 | // Request for origin.example.org, which has an alternative service. This |
| 14267 | // will start two Jobs: the alternative looks for connections to pool to, |
| 14268 | // 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] | 14269 | // open other connections to alternative server. The Job to server fails, so |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14270 | // this request fails. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14271 | HttpRequestInfo request2; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 14272 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14273 | request2.method = "GET"; |
| 14274 | request2.url = GURL(origin_url); |
| 14275 | request2.load_flags = 0; |
| 14276 | TestCompletionCallback callback2; |
| 14277 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14278 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14279 | EXPECT_THAT(callback2.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14280 | |
| 14281 | // Another transaction to alternative. This is to test that the HTTP/1.1 |
| 14282 | // socket is still open and in the pool. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14283 | HttpRequestInfo request3; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 14284 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14285 | request3.method = "GET"; |
| 14286 | request3.url = GURL(alternative_url); |
| 14287 | request3.load_flags = 0; |
| 14288 | TestCompletionCallback callback3; |
| 14289 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14290 | rv = trans3.Start(&request3, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14291 | EXPECT_THAT(callback3.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14292 | const HttpResponseInfo* response3 = trans3.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14293 | ASSERT_TRUE(response3); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14294 | ASSERT_TRUE(response3->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14295 | EXPECT_EQ("HTTP/1.1 200 OK", response3->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14296 | EXPECT_TRUE(response3->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14297 | EXPECT_FALSE(response3->was_fetched_via_spdy); |
| 14298 | std::string response_data3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14299 | ASSERT_THAT(ReadTransaction(&trans3, &response_data3), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14300 | EXPECT_EQ("second HTTP/1.1 response from alternative", response_data3); |
| 14301 | } |
| 14302 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14303 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14304 | const std::string https_url = "https://www.example.org:8080/"; |
| 14305 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14306 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14307 | // Separate SPDY util instance for naked and wrapped requests. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14308 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14309 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14310 | // SPDY GET for HTTPS URL (through CONNECT tunnel) |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14311 | const HostPortPair host_port_pair("www.example.org", 8080); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14312 | SpdySerializedFrame connect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 14313 | spdy_util_.ConstructSpdyConnect(NULL, 0, 1, LOWEST, host_port_pair)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14314 | SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14315 | spdy_util_wrapped.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14316 | SpdySerializedFrame wrapped_req1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 14317 | spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 14318 | |
| 14319 | // SPDY GET for HTTP URL (through the proxy, but not the tunnel). |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 14320 | SpdyHeaderBlock req2_block; |
| 14321 | req2_block[spdy_util_.GetMethodKey()] = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14322 | req2_block[spdy_util_.GetHostKey()] = "www.example.org:8080"; |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 14323 | req2_block[spdy_util_.GetSchemeKey()] = "http"; |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 14324 | req2_block[spdy_util_.GetPathKey()] = "/"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14325 | SpdySerializedFrame req2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14326 | spdy_util_.ConstructSpdyHeaders(3, std::move(req2_block), MEDIUM, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14327 | |
| 14328 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14329 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_req1, 2), |
| 14330 | CreateMockWrite(req2, 6), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14331 | }; |
| 14332 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14333 | SpdySerializedFrame conn_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14334 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14335 | SpdySerializedFrame resp1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14336 | spdy_util_wrapped.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14337 | SpdySerializedFrame body1(spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 14338 | SpdySerializedFrame wrapped_resp1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14339 | spdy_util_wrapped.ConstructWrappedSpdyFrame(resp1, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14340 | SpdySerializedFrame wrapped_body1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14341 | spdy_util_wrapped.ConstructWrappedSpdyFrame(body1, 1)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14342 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14343 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14344 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14345 | CreateMockRead(conn_resp, 1), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14346 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14347 | CreateMockRead(wrapped_resp1, 4), |
| 14348 | CreateMockRead(wrapped_body1, 5), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14349 | MockRead(ASYNC, ERR_IO_PENDING, 7), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14350 | CreateMockRead(resp2, 8), |
| 14351 | CreateMockRead(body2, 9), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14352 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 10), |
| 14353 | }; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14354 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14355 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 14356 | arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14357 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 14358 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14359 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 14360 | session_deps_.proxy_service = |
| 14361 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14362 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14363 | session_deps_.net_log = &log; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14364 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14365 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14366 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14367 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14368 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14369 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 14370 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14371 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14372 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14373 | |
| 14374 | // Start the first transaction to set up the SpdySession |
| 14375 | HttpRequestInfo request1; |
| 14376 | request1.method = "GET"; |
| 14377 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14378 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14379 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14380 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14381 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14382 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14383 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 14384 | data1.RunUntilPaused(); |
| 14385 | base::RunLoop().RunUntilIdle(); |
| 14386 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14387 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14388 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 14389 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 14390 | LoadTimingInfo load_timing_info1; |
| 14391 | EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); |
| 14392 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 14393 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 14394 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14395 | // Now, start the HTTP request. |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14396 | HttpRequestInfo request2; |
| 14397 | request2.method = "GET"; |
| 14398 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14399 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14400 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14401 | TestCompletionCallback callback2; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14402 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14403 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14404 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 14405 | data1.RunUntilPaused(); |
| 14406 | base::RunLoop().RunUntilIdle(); |
| 14407 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14408 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14409 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14410 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 14411 | |
| 14412 | LoadTimingInfo load_timing_info2; |
| 14413 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
| 14414 | // The established SPDY sessions is considered reused by the HTTP request. |
| 14415 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 14416 | // HTTP requests over a SPDY session should have a different connection |
| 14417 | // socket_log_id than requests over a tunnel. |
| 14418 | 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] | 14419 | } |
| 14420 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14421 | // Test that in the case where we have a SPDY session to a SPDY proxy |
| 14422 | // that we do not pool other origins that resolve to the same IP when |
| 14423 | // the certificate does not match the new origin. |
| 14424 | // http://crbug.com/134690 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14425 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14426 | const std::string url1 = "http://www.example.org/"; |
| 14427 | const std::string url2 = "https://news.example.org/"; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14428 | const std::string ip_addr = "1.2.3.4"; |
| 14429 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14430 | // Second SpdyTestUtil instance for the second socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14431 | SpdyTestUtil spdy_util_secure; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14432 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14433 | // SPDY GET for HTTP URL (through SPDY proxy) |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 14434 | SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14435 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14436 | SpdySerializedFrame req1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14437 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14438 | |
| 14439 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14440 | CreateMockWrite(req1, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14441 | }; |
| 14442 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14443 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14444 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14445 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14446 | MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(resp1, 2), |
| 14447 | CreateMockRead(body1, 3), MockRead(ASYNC, OK, 4), // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14448 | }; |
| 14449 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14450 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 14451 | arraysize(writes1)); |
martijn | fe9636e | 2016-02-06 14:33:32 | [diff] [blame] | 14452 | IPAddress ip; |
martijn | 654c8c4 | 2016-02-10 22:10:59 | [diff] [blame] | 14453 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14454 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 14455 | MockConnect connect_data1(ASYNC, OK, peer_addr); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14456 | data1.set_connect_data(connect_data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14457 | |
| 14458 | // SPDY GET for HTTPS URL (direct) |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14459 | SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14460 | spdy_util_secure.ConstructSpdyGet(url2.c_str(), 1, MEDIUM)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14461 | |
| 14462 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14463 | CreateMockWrite(req2, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14464 | }; |
| 14465 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14466 | SpdySerializedFrame resp2(spdy_util_secure.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14467 | SpdySerializedFrame body2(spdy_util_secure.ConstructSpdyDataFrame(1, true)); |
| 14468 | MockRead reads2[] = {CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14469 | MockRead(ASYNC, OK, 3)}; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14470 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14471 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 14472 | arraysize(writes2)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14473 | MockConnect connect_data2(ASYNC, OK); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14474 | data2.set_connect_data(connect_data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14475 | |
| 14476 | // Set up a proxy config that sends HTTP requests to a proxy, and |
| 14477 | // all others direct. |
| 14478 | ProxyConfig proxy_config; |
| 14479 | proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14480 | session_deps_.proxy_service = base::MakeUnique<ProxyService>( |
| 14481 | base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), nullptr, |
| 14482 | nullptr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14483 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14484 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14485 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14486 | // Load a valid cert. Note, that this does not need to |
| 14487 | // be valid for proxy because the MockSSLClientSocket does |
| 14488 | // not actually verify it. But SpdySession will use this |
| 14489 | // to see if it is valid for the new origin |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14490 | ssl1.cert = ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem"); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14491 | ASSERT_TRUE(ssl1.cert); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14492 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 14493 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14494 | |
| 14495 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14496 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14497 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 14498 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14499 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14500 | session_deps_.host_resolver = base::MakeUnique<MockCachingHostResolver>(); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14501 | session_deps_.host_resolver->rules()->AddRule("news.example.org", ip_addr); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14502 | session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14503 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14504 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14505 | |
| 14506 | // Start the first transaction to set up the SpdySession |
| 14507 | HttpRequestInfo request1; |
| 14508 | request1.method = "GET"; |
| 14509 | request1.url = GURL(url1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14510 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14511 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14512 | TestCompletionCallback callback1; |
| 14513 | ASSERT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14514 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14515 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 14516 | data1.RunUntilPaused(); |
| 14517 | base::RunLoop().RunUntilIdle(); |
| 14518 | data1.Resume(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14519 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14520 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14521 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 14522 | |
| 14523 | // Now, start the HTTP request |
| 14524 | HttpRequestInfo request2; |
| 14525 | request2.method = "GET"; |
| 14526 | request2.url = GURL(url2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14527 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14528 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14529 | TestCompletionCallback callback2; |
| 14530 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14531 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 14532 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14533 | |
| 14534 | ASSERT_TRUE(callback2.have_result()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14535 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14536 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 14537 | } |
| 14538 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14539 | // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 14540 | // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 14541 | // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 14542 | // SpdySession) do work. http://crbug.com/224701 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14543 | TEST_F(HttpNetworkTransactionTest, ErrorSocketNotConnected) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14544 | const std::string https_url = "https://www.example.org/"; |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14545 | |
| 14546 | MockRead reads1[] = { |
| 14547 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 14548 | }; |
| 14549 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14550 | SequencedSocketData data1(reads1, arraysize(reads1), NULL, 0); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14551 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14552 | SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14553 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, MEDIUM)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14554 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14555 | CreateMockWrite(req2, 0), |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14556 | }; |
| 14557 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14558 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14559 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14560 | MockRead reads2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14561 | CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
| 14562 | MockRead(ASYNC, OK, 3) // EOF |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14563 | }; |
| 14564 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14565 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 14566 | arraysize(writes2)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14567 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14568 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14569 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14570 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 14571 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14572 | |
| 14573 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14574 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14575 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 14576 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14577 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14578 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14579 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14580 | |
| 14581 | // Start the first transaction to set up the SpdySession and verify that |
| 14582 | // connection was closed. |
| 14583 | HttpRequestInfo request1; |
| 14584 | request1.method = "GET"; |
| 14585 | request1.url = GURL(https_url); |
| 14586 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14587 | HttpNetworkTransaction trans1(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14588 | TestCompletionCallback callback1; |
| 14589 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14590 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14591 | EXPECT_THAT(callback1.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14592 | |
| 14593 | // Now, start the second request and make sure it succeeds. |
| 14594 | HttpRequestInfo request2; |
| 14595 | request2.method = "GET"; |
| 14596 | request2.url = GURL(https_url); |
| 14597 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14598 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14599 | TestCompletionCallback callback2; |
| 14600 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14601 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14602 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14603 | ASSERT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14604 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 14605 | } |
| 14606 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14607 | TEST_F(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14608 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 14609 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14610 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 14611 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14612 | |
| 14613 | // Use two different hosts with different IPs so they don't get pooled. |
| 14614 | session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); |
| 14615 | session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14616 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14617 | |
| 14618 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14619 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14620 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14621 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14622 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 14623 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 14624 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14625 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14626 | spdy_util_.ConstructSpdyGet("https://www.a.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14627 | MockWrite spdy1_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14628 | CreateMockWrite(host1_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14629 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14630 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14631 | SpdySerializedFrame host1_resp_body( |
| 14632 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14633 | MockRead spdy1_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14634 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 14635 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14636 | }; |
| 14637 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14638 | // Use a separate test instance for the separate SpdySession that will be |
| 14639 | // created. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14640 | SpdyTestUtil spdy_util_2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14641 | auto spdy1_data = base::MakeUnique<SequencedSocketData>( |
| 14642 | spdy1_reads, arraysize(spdy1_reads), spdy1_writes, |
| 14643 | arraysize(spdy1_writes)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14644 | session_deps_.socket_factory->AddSocketDataProvider(spdy1_data.get()); |
| 14645 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14646 | SpdySerializedFrame host2_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14647 | spdy_util_2.ConstructSpdyGet("https://www.b.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14648 | MockWrite spdy2_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14649 | CreateMockWrite(host2_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14650 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14651 | SpdySerializedFrame host2_resp(spdy_util_2.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14652 | SpdySerializedFrame host2_resp_body( |
| 14653 | spdy_util_2.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14654 | MockRead spdy2_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14655 | CreateMockRead(host2_resp, 1), CreateMockRead(host2_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 14656 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14657 | }; |
| 14658 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14659 | auto spdy2_data = base::MakeUnique<SequencedSocketData>( |
| 14660 | spdy2_reads, arraysize(spdy2_reads), spdy2_writes, |
| 14661 | arraysize(spdy2_writes)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14662 | session_deps_.socket_factory->AddSocketDataProvider(spdy2_data.get()); |
| 14663 | |
| 14664 | MockWrite http_write[] = { |
| 14665 | MockWrite("GET / HTTP/1.1\r\n" |
| 14666 | "Host: www.a.com\r\n" |
| 14667 | "Connection: keep-alive\r\n\r\n"), |
| 14668 | }; |
| 14669 | |
| 14670 | MockRead http_read[] = { |
| 14671 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14672 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 14673 | MockRead("Content-Length: 6\r\n\r\n"), |
| 14674 | MockRead("hello!"), |
| 14675 | }; |
| 14676 | StaticSocketDataProvider http_data(http_read, arraysize(http_read), |
| 14677 | http_write, arraysize(http_write)); |
| 14678 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 14679 | |
| 14680 | HostPortPair host_port_pair_a("www.a.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 14681 | SpdySessionKey spdy_session_key_a( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 14682 | host_port_pair_a, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14683 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14684 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14685 | |
| 14686 | TestCompletionCallback callback; |
| 14687 | HttpRequestInfo request1; |
| 14688 | request1.method = "GET"; |
| 14689 | request1.url = GURL("https://www.a.com/"); |
| 14690 | request1.load_flags = 0; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14691 | auto trans = |
| 14692 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14693 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14694 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14695 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14696 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14697 | |
| 14698 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14699 | ASSERT_TRUE(response); |
| 14700 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14701 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14702 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14703 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14704 | |
| 14705 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14706 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14707 | EXPECT_EQ("hello!", response_data); |
| 14708 | trans.reset(); |
| 14709 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14710 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14711 | |
| 14712 | HostPortPair host_port_pair_b("www.b.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 14713 | SpdySessionKey spdy_session_key_b( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 14714 | host_port_pair_b, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14715 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14716 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14717 | HttpRequestInfo request2; |
| 14718 | request2.method = "GET"; |
| 14719 | request2.url = GURL("https://www.b.com/"); |
| 14720 | request2.load_flags = 0; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14721 | trans = |
| 14722 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14723 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14724 | rv = trans->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14725 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14726 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14727 | |
| 14728 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14729 | ASSERT_TRUE(response); |
| 14730 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14731 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14732 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14733 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14734 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14735 | EXPECT_EQ("hello!", response_data); |
| 14736 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14737 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14738 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14739 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14740 | |
| 14741 | HostPortPair host_port_pair_a1("www.a.com", 80); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 14742 | SpdySessionKey spdy_session_key_a1( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 14743 | host_port_pair_a1, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14744 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14745 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14746 | HttpRequestInfo request3; |
| 14747 | request3.method = "GET"; |
| 14748 | request3.url = GURL("http://www.a.com/"); |
| 14749 | request3.load_flags = 0; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14750 | trans = |
| 14751 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14752 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14753 | rv = trans->Start(&request3, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14754 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14755 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14756 | |
| 14757 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14758 | ASSERT_TRUE(response); |
| 14759 | ASSERT_TRUE(response->headers); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14760 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 14761 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14762 | EXPECT_FALSE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14763 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14764 | EXPECT_EQ("hello!", response_data); |
| 14765 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14766 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14767 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14768 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14769 | } |
| 14770 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14771 | TEST_F(HttpNetworkTransactionTest, HttpSyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14772 | HttpRequestInfo request; |
| 14773 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14774 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14775 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14776 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14777 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14778 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14779 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14780 | StaticSocketDataProvider data; |
| 14781 | data.set_connect_data(mock_connect); |
| 14782 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14783 | |
| 14784 | TestCompletionCallback callback; |
| 14785 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14786 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14787 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14788 | |
| 14789 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14790 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14791 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14792 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 14793 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14794 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 14795 | |
| 14796 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14797 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 14798 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14799 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14800 | |
| 14801 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14802 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14803 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14804 | } |
| 14805 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14806 | TEST_F(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14807 | HttpRequestInfo request; |
| 14808 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14809 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14810 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14811 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14812 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14813 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14814 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14815 | StaticSocketDataProvider data; |
| 14816 | data.set_connect_data(mock_connect); |
| 14817 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14818 | |
| 14819 | TestCompletionCallback callback; |
| 14820 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14821 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14822 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14823 | |
| 14824 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14825 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14826 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14827 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 14828 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14829 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 14830 | |
| 14831 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14832 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 14833 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14834 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14835 | |
| 14836 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14837 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14838 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14839 | } |
| 14840 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14841 | TEST_F(HttpNetworkTransactionTest, HttpSyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14842 | HttpRequestInfo request; |
| 14843 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14844 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14845 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14846 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14847 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14848 | |
| 14849 | MockWrite data_writes[] = { |
| 14850 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14851 | }; |
| 14852 | MockRead data_reads[] = { |
| 14853 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 14854 | }; |
| 14855 | |
| 14856 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14857 | data_writes, arraysize(data_writes)); |
| 14858 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14859 | |
| 14860 | TestCompletionCallback callback; |
| 14861 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14862 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14863 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14864 | |
| 14865 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14866 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14867 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14868 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14869 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14870 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 14871 | } |
| 14872 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14873 | TEST_F(HttpNetworkTransactionTest, HttpAsyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14874 | HttpRequestInfo request; |
| 14875 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14876 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14877 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14878 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14879 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14880 | |
| 14881 | MockWrite data_writes[] = { |
| 14882 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
| 14883 | }; |
| 14884 | MockRead data_reads[] = { |
| 14885 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 14886 | }; |
| 14887 | |
| 14888 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14889 | data_writes, arraysize(data_writes)); |
| 14890 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14891 | |
| 14892 | TestCompletionCallback callback; |
| 14893 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14894 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14895 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14896 | |
| 14897 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14898 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14899 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14900 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14901 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14902 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 14903 | } |
| 14904 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14905 | TEST_F(HttpNetworkTransactionTest, HttpSyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14906 | HttpRequestInfo request; |
| 14907 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14908 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14909 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14910 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14911 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14912 | |
| 14913 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14914 | MockWrite( |
| 14915 | "GET / HTTP/1.1\r\n" |
| 14916 | "Host: www.example.org\r\n" |
| 14917 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14918 | }; |
| 14919 | MockRead data_reads[] = { |
| 14920 | MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 14921 | }; |
| 14922 | |
| 14923 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14924 | data_writes, arraysize(data_writes)); |
| 14925 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14926 | |
| 14927 | TestCompletionCallback callback; |
| 14928 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14929 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14930 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14931 | |
| 14932 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14933 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14934 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14935 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14936 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14937 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 14938 | } |
| 14939 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14940 | TEST_F(HttpNetworkTransactionTest, HttpAsyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14941 | HttpRequestInfo request; |
| 14942 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14943 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14944 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14945 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14946 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14947 | |
| 14948 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14949 | MockWrite( |
| 14950 | "GET / HTTP/1.1\r\n" |
| 14951 | "Host: www.example.org\r\n" |
| 14952 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14953 | }; |
| 14954 | MockRead data_reads[] = { |
| 14955 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 14956 | }; |
| 14957 | |
| 14958 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14959 | data_writes, arraysize(data_writes)); |
| 14960 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14961 | |
| 14962 | TestCompletionCallback callback; |
| 14963 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14964 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14965 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14966 | |
| 14967 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14968 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14969 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14970 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14971 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14972 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 14973 | } |
| 14974 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14975 | TEST_F(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14976 | HttpRequestInfo request; |
| 14977 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14978 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14979 | request.extra_headers.SetHeader("X-Foo", "bar"); |
| 14980 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14981 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14982 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14983 | |
| 14984 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14985 | MockWrite( |
| 14986 | "GET / HTTP/1.1\r\n" |
| 14987 | "Host: www.example.org\r\n" |
| 14988 | "Connection: keep-alive\r\n" |
| 14989 | "X-Foo: bar\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14990 | }; |
| 14991 | MockRead data_reads[] = { |
| 14992 | MockRead("HTTP/1.1 200 OK\r\n" |
| 14993 | "Content-Length: 5\r\n\r\n" |
| 14994 | "hello"), |
| 14995 | MockRead(ASYNC, ERR_UNEXPECTED), |
| 14996 | }; |
| 14997 | |
| 14998 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 14999 | data_writes, arraysize(data_writes)); |
| 15000 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15001 | |
| 15002 | TestCompletionCallback callback; |
| 15003 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15004 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15005 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15006 | |
| 15007 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15008 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15009 | |
| 15010 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15011 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15012 | std::string foo; |
| 15013 | EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo)); |
| 15014 | EXPECT_EQ("bar", foo); |
| 15015 | } |
| 15016 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15017 | namespace { |
| 15018 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 15019 | // Fake HttpStream that simply records calls to SetPriority(). |
| 15020 | class FakeStream : public HttpStream, |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15021 | public base::SupportsWeakPtr<FakeStream> { |
| 15022 | public: |
| 15023 | explicit FakeStream(RequestPriority priority) : priority_(priority) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15024 | ~FakeStream() override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15025 | |
| 15026 | RequestPriority priority() const { return priority_; } |
| 15027 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15028 | int InitializeStream(const HttpRequestInfo* request_info, |
| 15029 | RequestPriority priority, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15030 | const NetLogWithSource& net_log, |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15031 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15032 | return ERR_IO_PENDING; |
| 15033 | } |
| 15034 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15035 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 15036 | HttpResponseInfo* response, |
| 15037 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15038 | ADD_FAILURE(); |
| 15039 | return ERR_UNEXPECTED; |
| 15040 | } |
| 15041 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15042 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15043 | ADD_FAILURE(); |
| 15044 | return ERR_UNEXPECTED; |
| 15045 | } |
| 15046 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15047 | int ReadResponseBody(IOBuffer* buf, |
| 15048 | int buf_len, |
| 15049 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15050 | ADD_FAILURE(); |
| 15051 | return ERR_UNEXPECTED; |
| 15052 | } |
| 15053 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15054 | void Close(bool not_reusable) override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15055 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15056 | bool IsResponseBodyComplete() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15057 | ADD_FAILURE(); |
| 15058 | return false; |
| 15059 | } |
| 15060 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15061 | bool IsConnectionReused() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15062 | ADD_FAILURE(); |
| 15063 | return false; |
| 15064 | } |
| 15065 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15066 | void SetConnectionReused() override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15067 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 15068 | bool CanReuseConnection() const override { return false; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15069 | |
sclittle | 4de1bab9 | 2015-09-22 21:28:24 | [diff] [blame] | 15070 | int64_t GetTotalReceivedBytes() const override { |
[email protected] | bc92bc97 | 2013-12-13 08:32:59 | [diff] [blame] | 15071 | ADD_FAILURE(); |
| 15072 | return 0; |
| 15073 | } |
| 15074 | |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 15075 | int64_t GetTotalSentBytes() const override { |
| 15076 | ADD_FAILURE(); |
| 15077 | return 0; |
| 15078 | } |
| 15079 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15080 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15081 | ADD_FAILURE(); |
| 15082 | return false; |
| 15083 | } |
| 15084 | |
rch | cd37901 | 2017-04-12 21:53:32 | [diff] [blame] | 15085 | bool GetAlternativeService( |
| 15086 | AlternativeService* alternative_service) const override { |
| 15087 | ADD_FAILURE(); |
| 15088 | return false; |
| 15089 | } |
| 15090 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15091 | void GetSSLInfo(SSLInfo* ssl_info) override { ADD_FAILURE(); } |
| 15092 | |
| 15093 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15094 | ADD_FAILURE(); |
| 15095 | } |
| 15096 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15097 | bool GetRemoteEndpoint(IPEndPoint* endpoint) override { return false; } |
| 15098 | |
nharper | 78e6d2b | 2016-09-21 05:42:35 | [diff] [blame] | 15099 | Error GetTokenBindingSignature(crypto::ECPrivateKey* key, |
| 15100 | TokenBindingType tb_type, |
| 15101 | std::vector<uint8_t>* out) override { |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 15102 | ADD_FAILURE(); |
| 15103 | return ERR_NOT_IMPLEMENTED; |
| 15104 | } |
| 15105 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15106 | void Drain(HttpNetworkSession* session) override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15107 | |
zhongyi | ca364fbb | 2015-12-12 03:39:12 | [diff] [blame] | 15108 | void PopulateNetErrorDetails(NetErrorDetails* details) override { return; } |
| 15109 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15110 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15111 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 15112 | HttpStream* RenewStreamForAuth() override { return NULL; } |
| 15113 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15114 | private: |
| 15115 | RequestPriority priority_; |
| 15116 | |
| 15117 | DISALLOW_COPY_AND_ASSIGN(FakeStream); |
| 15118 | }; |
| 15119 | |
| 15120 | // Fake HttpStreamRequest that simply records calls to SetPriority() |
| 15121 | // and vends FakeStreams with its current priority. |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15122 | class FakeStreamRequest : public HttpStreamRequest, |
| 15123 | public base::SupportsWeakPtr<FakeStreamRequest> { |
| 15124 | public: |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15125 | FakeStreamRequest(RequestPriority priority, |
| 15126 | HttpStreamRequest::Delegate* delegate) |
| 15127 | : priority_(priority), |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15128 | delegate_(delegate), |
| 15129 | websocket_stream_create_helper_(NULL) {} |
| 15130 | |
| 15131 | FakeStreamRequest(RequestPriority priority, |
| 15132 | HttpStreamRequest::Delegate* delegate, |
| 15133 | WebSocketHandshakeStreamBase::CreateHelper* create_helper) |
| 15134 | : priority_(priority), |
| 15135 | delegate_(delegate), |
| 15136 | websocket_stream_create_helper_(create_helper) {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15137 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15138 | ~FakeStreamRequest() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15139 | |
| 15140 | RequestPriority priority() const { return priority_; } |
| 15141 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15142 | const WebSocketHandshakeStreamBase::CreateHelper* |
| 15143 | websocket_stream_create_helper() const { |
| 15144 | return websocket_stream_create_helper_; |
| 15145 | } |
| 15146 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15147 | // Create a new FakeStream and pass it to the request's |
| 15148 | // delegate. Returns a weak pointer to the FakeStream. |
| 15149 | base::WeakPtr<FakeStream> FinishStreamRequest() { |
bnc | 5029f463 | 2017-06-08 16:19:00 | [diff] [blame^] | 15150 | auto fake_stream = base::MakeUnique<FakeStream>(priority_); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15151 | // Do this before calling OnStreamReady() as OnStreamReady() may |
| 15152 | // immediately delete |fake_stream|. |
| 15153 | base::WeakPtr<FakeStream> weak_stream = fake_stream->AsWeakPtr(); |
bnc | 5029f463 | 2017-06-08 16:19:00 | [diff] [blame^] | 15154 | delegate_->OnStreamReady(SSLConfig(), ProxyInfo(), std::move(fake_stream)); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15155 | return weak_stream; |
| 15156 | } |
| 15157 | |
asanka | 681f02d | 2017-02-22 17:06:39 | [diff] [blame] | 15158 | int RestartTunnelWithProxyAuth() override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15159 | ADD_FAILURE(); |
| 15160 | return ERR_UNEXPECTED; |
| 15161 | } |
| 15162 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15163 | LoadState GetLoadState() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15164 | ADD_FAILURE(); |
| 15165 | return LoadState(); |
| 15166 | } |
| 15167 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15168 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15169 | |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15170 | bool was_alpn_negotiated() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15171 | |
bnc | 6227b26e | 2016-08-12 02:00:43 | [diff] [blame] | 15172 | NextProto negotiated_protocol() const override { return kProtoUnknown; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15173 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15174 | bool using_spdy() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15175 | |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 15176 | const ConnectionAttempts& connection_attempts() const override { |
| 15177 | static ConnectionAttempts no_attempts; |
| 15178 | return no_attempts; |
| 15179 | } |
| 15180 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15181 | private: |
| 15182 | RequestPriority priority_; |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15183 | HttpStreamRequest::Delegate* const delegate_; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15184 | WebSocketHandshakeStreamBase::CreateHelper* websocket_stream_create_helper_; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15185 | |
| 15186 | DISALLOW_COPY_AND_ASSIGN(FakeStreamRequest); |
| 15187 | }; |
| 15188 | |
| 15189 | // Fake HttpStreamFactory that vends FakeStreamRequests. |
| 15190 | class FakeStreamFactory : public HttpStreamFactory { |
| 15191 | public: |
| 15192 | FakeStreamFactory() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15193 | ~FakeStreamFactory() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15194 | |
| 15195 | // Returns a WeakPtr<> to the last HttpStreamRequest returned by |
| 15196 | // RequestStream() (which may be NULL if it was destroyed already). |
| 15197 | base::WeakPtr<FakeStreamRequest> last_stream_request() { |
| 15198 | return last_stream_request_; |
| 15199 | } |
| 15200 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15201 | std::unique_ptr<HttpStreamRequest> RequestStream( |
| 15202 | const HttpRequestInfo& info, |
| 15203 | RequestPriority priority, |
| 15204 | const SSLConfig& server_ssl_config, |
| 15205 | const SSLConfig& proxy_ssl_config, |
| 15206 | HttpStreamRequest::Delegate* delegate, |
| 15207 | bool enable_ip_based_pooling, |
| 15208 | bool enable_alternative_services, |
| 15209 | const NetLogWithSource& net_log) override { |
| 15210 | auto fake_request = base::MakeUnique<FakeStreamRequest>(priority, delegate); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15211 | last_stream_request_ = fake_request->AsWeakPtr(); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15212 | return std::move(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15213 | } |
| 15214 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15215 | std::unique_ptr<HttpStreamRequest> RequestBidirectionalStreamImpl( |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 15216 | const HttpRequestInfo& info, |
| 15217 | RequestPriority priority, |
| 15218 | const SSLConfig& server_ssl_config, |
| 15219 | const SSLConfig& proxy_ssl_config, |
| 15220 | HttpStreamRequest::Delegate* delegate, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15221 | bool enable_ip_based_pooling, |
bnc | accd496 | 2017-04-06 21:00:26 | [diff] [blame] | 15222 | bool enable_alternative_services, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15223 | const NetLogWithSource& net_log) override { |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 15224 | NOTREACHED(); |
| 15225 | return nullptr; |
| 15226 | } |
| 15227 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15228 | std::unique_ptr<HttpStreamRequest> RequestWebSocketHandshakeStream( |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15229 | const HttpRequestInfo& info, |
| 15230 | RequestPriority priority, |
| 15231 | const SSLConfig& server_ssl_config, |
| 15232 | const SSLConfig& proxy_ssl_config, |
| 15233 | HttpStreamRequest::Delegate* delegate, |
[email protected] | 467086b | 2013-11-12 08:19:46 | [diff] [blame] | 15234 | WebSocketHandshakeStreamBase::CreateHelper* create_helper, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15235 | bool enable_ip_based_pooling, |
bnc | accd496 | 2017-04-06 21:00:26 | [diff] [blame] | 15236 | bool enable_alternative_services, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15237 | const NetLogWithSource& net_log) override { |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15238 | auto fake_request = |
| 15239 | base::MakeUnique<FakeStreamRequest>(priority, delegate, create_helper); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15240 | last_stream_request_ = fake_request->AsWeakPtr(); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15241 | return std::move(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15242 | } |
| 15243 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15244 | void PreconnectStreams(int num_streams, |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 15245 | const HttpRequestInfo& info) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15246 | ADD_FAILURE(); |
| 15247 | } |
| 15248 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15249 | const HostMappingRules* GetHostMappingRules() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15250 | ADD_FAILURE(); |
| 15251 | return NULL; |
| 15252 | } |
| 15253 | |
xunjieli | f5267de | 2017-01-20 21:18:57 | [diff] [blame] | 15254 | void DumpMemoryStats(base::trace_event::ProcessMemoryDump* pmd, |
| 15255 | const std::string& parent_absolute_name) const override { |
| 15256 | ADD_FAILURE(); |
| 15257 | } |
| 15258 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15259 | private: |
| 15260 | base::WeakPtr<FakeStreamRequest> last_stream_request_; |
| 15261 | |
| 15262 | DISALLOW_COPY_AND_ASSIGN(FakeStreamFactory); |
| 15263 | }; |
| 15264 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15265 | // TODO(ricea): Maybe unify this with the one in |
| 15266 | // url_request_http_job_unittest.cc ? |
| 15267 | class FakeWebSocketBasicHandshakeStream : public WebSocketHandshakeStreamBase { |
| 15268 | public: |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15269 | FakeWebSocketBasicHandshakeStream( |
| 15270 | std::unique_ptr<ClientSocketHandle> connection, |
| 15271 | bool using_proxy) |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 15272 | : state_(std::move(connection), using_proxy, false) {} |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15273 | |
| 15274 | // Fake implementation of HttpStreamBase methods. |
| 15275 | // This ends up being quite "real" because this object has to really send data |
| 15276 | // on the mock socket. It might be easier to use the real implementation, but |
| 15277 | // the fact that the WebSocket code is not compiled on iOS makes that |
| 15278 | // difficult. |
| 15279 | int InitializeStream(const HttpRequestInfo* request_info, |
| 15280 | RequestPriority priority, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15281 | const NetLogWithSource& net_log, |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15282 | const CompletionCallback& callback) override { |
| 15283 | state_.Initialize(request_info, priority, net_log, callback); |
| 15284 | return OK; |
| 15285 | } |
| 15286 | |
| 15287 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 15288 | HttpResponseInfo* response, |
| 15289 | const CompletionCallback& callback) override { |
| 15290 | return parser()->SendRequest(state_.GenerateRequestLine(), request_headers, |
| 15291 | response, callback); |
| 15292 | } |
| 15293 | |
| 15294 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
| 15295 | return parser()->ReadResponseHeaders(callback); |
| 15296 | } |
| 15297 | |
| 15298 | int ReadResponseBody(IOBuffer* buf, |
| 15299 | int buf_len, |
| 15300 | const CompletionCallback& callback) override { |
| 15301 | NOTREACHED(); |
| 15302 | return ERR_IO_PENDING; |
| 15303 | } |
| 15304 | |
| 15305 | void Close(bool not_reusable) override { |
| 15306 | if (parser()) |
| 15307 | parser()->Close(true); |
| 15308 | } |
| 15309 | |
| 15310 | bool IsResponseBodyComplete() const override { |
| 15311 | NOTREACHED(); |
| 15312 | return false; |
| 15313 | } |
| 15314 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15315 | bool IsConnectionReused() const override { |
| 15316 | NOTREACHED(); |
| 15317 | return false; |
| 15318 | } |
| 15319 | void SetConnectionReused() override { NOTREACHED(); } |
| 15320 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 15321 | bool CanReuseConnection() const override { return false; } |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15322 | |
sclittle | 4de1bab9 | 2015-09-22 21:28:24 | [diff] [blame] | 15323 | int64_t GetTotalReceivedBytes() const override { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15324 | NOTREACHED(); |
| 15325 | return 0; |
| 15326 | } |
| 15327 | |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 15328 | int64_t GetTotalSentBytes() const override { |
| 15329 | NOTREACHED(); |
| 15330 | return 0; |
| 15331 | } |
| 15332 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15333 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
| 15334 | NOTREACHED(); |
| 15335 | return false; |
| 15336 | } |
| 15337 | |
rch | cd37901 | 2017-04-12 21:53:32 | [diff] [blame] | 15338 | bool GetAlternativeService( |
| 15339 | AlternativeService* alternative_service) const override { |
| 15340 | ADD_FAILURE(); |
| 15341 | return false; |
| 15342 | } |
| 15343 | |
Adam Rice | cb76ac6 | 2015-02-20 05:33:25 | [diff] [blame] | 15344 | void GetSSLInfo(SSLInfo* ssl_info) override {} |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15345 | |
| 15346 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
| 15347 | NOTREACHED(); |
| 15348 | } |
| 15349 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15350 | bool GetRemoteEndpoint(IPEndPoint* endpoint) override { return false; } |
| 15351 | |
nharper | 78e6d2b | 2016-09-21 05:42:35 | [diff] [blame] | 15352 | Error GetTokenBindingSignature(crypto::ECPrivateKey* key, |
| 15353 | TokenBindingType tb_type, |
| 15354 | std::vector<uint8_t>* out) override { |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 15355 | ADD_FAILURE(); |
| 15356 | return ERR_NOT_IMPLEMENTED; |
| 15357 | } |
| 15358 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15359 | void Drain(HttpNetworkSession* session) override { NOTREACHED(); } |
| 15360 | |
zhongyi | ca364fbb | 2015-12-12 03:39:12 | [diff] [blame] | 15361 | void PopulateNetErrorDetails(NetErrorDetails* details) override { return; } |
| 15362 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15363 | void SetPriority(RequestPriority priority) override { NOTREACHED(); } |
| 15364 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15365 | HttpStream* RenewStreamForAuth() override { |
| 15366 | NOTREACHED(); |
| 15367 | return nullptr; |
| 15368 | } |
| 15369 | |
| 15370 | // Fake implementation of WebSocketHandshakeStreamBase method(s) |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15371 | std::unique_ptr<WebSocketStream> Upgrade() override { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15372 | NOTREACHED(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15373 | return std::unique_ptr<WebSocketStream>(); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15374 | } |
| 15375 | |
| 15376 | private: |
| 15377 | HttpStreamParser* parser() const { return state_.parser(); } |
| 15378 | HttpBasicState state_; |
| 15379 | |
| 15380 | DISALLOW_COPY_AND_ASSIGN(FakeWebSocketBasicHandshakeStream); |
| 15381 | }; |
| 15382 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15383 | // TODO(yhirano): Split this class out into a net/websockets file, if it is |
| 15384 | // worth doing. |
| 15385 | class FakeWebSocketStreamCreateHelper : |
| 15386 | public WebSocketHandshakeStreamBase::CreateHelper { |
| 15387 | public: |
bnc | 615cf2f | 2017-05-19 18:53:26 | [diff] [blame] | 15388 | std::unique_ptr<WebSocketHandshakeStreamBase> CreateBasicStream( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15389 | std::unique_ptr<ClientSocketHandle> connection, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 15390 | bool using_proxy) override { |
bnc | 615cf2f | 2017-05-19 18:53:26 | [diff] [blame] | 15391 | return base::MakeUnique<FakeWebSocketBasicHandshakeStream>( |
| 15392 | std::move(connection), using_proxy); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15393 | } |
| 15394 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15395 | ~FakeWebSocketStreamCreateHelper() override {} |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15396 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15397 | virtual std::unique_ptr<WebSocketStream> Upgrade() { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15398 | NOTREACHED(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15399 | return std::unique_ptr<WebSocketStream>(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15400 | } |
| 15401 | }; |
| 15402 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15403 | } // namespace |
| 15404 | |
| 15405 | // Make sure that HttpNetworkTransaction passes on its priority to its |
| 15406 | // stream request on start. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15407 | TEST_F(HttpNetworkTransactionTest, SetStreamRequestPriorityOnStart) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15408 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15409 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15410 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15411 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15412 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15413 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15414 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15415 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15416 | ASSERT_FALSE(fake_factory->last_stream_request()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15417 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15418 | TestCompletionCallback callback; |
| 15419 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15420 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15421 | |
| 15422 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 15423 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15424 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15425 | EXPECT_EQ(LOW, fake_request->priority()); |
| 15426 | } |
| 15427 | |
| 15428 | // Make sure that HttpNetworkTransaction passes on its priority |
| 15429 | // updates to its stream request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15430 | TEST_F(HttpNetworkTransactionTest, SetStreamRequestPriority) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15431 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15432 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15433 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15434 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15435 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15436 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15437 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15438 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15439 | TestCompletionCallback callback; |
| 15440 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15441 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15442 | |
| 15443 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 15444 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15445 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15446 | EXPECT_EQ(LOW, fake_request->priority()); |
| 15447 | |
| 15448 | trans.SetPriority(LOWEST); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15449 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15450 | EXPECT_EQ(LOWEST, fake_request->priority()); |
| 15451 | } |
| 15452 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15453 | // Make sure that HttpNetworkTransaction passes on its priority |
| 15454 | // updates to its stream. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15455 | TEST_F(HttpNetworkTransactionTest, SetStreamPriority) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15456 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15457 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15458 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15459 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15460 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15461 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15462 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15463 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15464 | TestCompletionCallback callback; |
| 15465 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15466 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15467 | |
| 15468 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 15469 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15470 | ASSERT_TRUE(fake_request); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15471 | base::WeakPtr<FakeStream> fake_stream = fake_request->FinishStreamRequest(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15472 | ASSERT_TRUE(fake_stream); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15473 | EXPECT_EQ(LOW, fake_stream->priority()); |
| 15474 | |
| 15475 | trans.SetPriority(LOWEST); |
| 15476 | EXPECT_EQ(LOWEST, fake_stream->priority()); |
| 15477 | } |
| 15478 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15479 | TEST_F(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15480 | // The same logic needs to be tested for both ws: and wss: schemes, but this |
| 15481 | // test is already parameterised on NextProto, so it uses a loop to verify |
| 15482 | // that the different schemes work. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15483 | std::string test_cases[] = {"ws://www.example.org/", |
| 15484 | "wss://www.example.org/"}; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15485 | for (size_t i = 0; i < arraysize(test_cases); ++i) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15486 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15487 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15488 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
| 15489 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
[email protected] | 0191b51c | 2013-11-18 10:55:23 | [diff] [blame] | 15490 | peer.SetHttpStreamFactoryForWebSocket( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15491 | std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15492 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15493 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15494 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15495 | trans.SetWebSocketHandshakeStreamCreateHelper( |
| 15496 | &websocket_stream_create_helper); |
| 15497 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15498 | TestCompletionCallback callback; |
| 15499 | request.method = "GET"; |
| 15500 | request.url = GURL(test_cases[i]); |
| 15501 | |
| 15502 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15503 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15504 | |
| 15505 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 15506 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15507 | ASSERT_TRUE(fake_request); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15508 | EXPECT_EQ(&websocket_stream_create_helper, |
| 15509 | fake_request->websocket_stream_create_helper()); |
| 15510 | } |
| 15511 | } |
| 15512 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15513 | // Tests that when a used socket is returned to the SSL socket pool, it's closed |
| 15514 | // if the transport socket pool is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15515 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15516 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 15517 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15518 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 15519 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15520 | |
| 15521 | // Set up SSL request. |
| 15522 | |
| 15523 | HttpRequestInfo ssl_request; |
| 15524 | ssl_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15525 | ssl_request.url = GURL("https://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15526 | |
| 15527 | MockWrite ssl_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15528 | MockWrite( |
| 15529 | "GET / HTTP/1.1\r\n" |
| 15530 | "Host: www.example.org\r\n" |
| 15531 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15532 | }; |
| 15533 | MockRead ssl_reads[] = { |
| 15534 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15535 | MockRead("Content-Length: 11\r\n\r\n"), |
| 15536 | MockRead("hello world"), |
| 15537 | MockRead(SYNCHRONOUS, OK), |
| 15538 | }; |
| 15539 | StaticSocketDataProvider ssl_data(ssl_reads, arraysize(ssl_reads), |
| 15540 | ssl_writes, arraysize(ssl_writes)); |
| 15541 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 15542 | |
| 15543 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 15544 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15545 | |
| 15546 | // Set up HTTP request. |
| 15547 | |
| 15548 | HttpRequestInfo http_request; |
| 15549 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15550 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15551 | |
| 15552 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15553 | MockWrite( |
| 15554 | "GET / HTTP/1.1\r\n" |
| 15555 | "Host: www.example.org\r\n" |
| 15556 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15557 | }; |
| 15558 | MockRead http_reads[] = { |
| 15559 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15560 | MockRead("Content-Length: 7\r\n\r\n"), |
| 15561 | MockRead("falafel"), |
| 15562 | MockRead(SYNCHRONOUS, OK), |
| 15563 | }; |
| 15564 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 15565 | http_writes, arraysize(http_writes)); |
| 15566 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 15567 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15568 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15569 | |
| 15570 | // Start the SSL request. |
| 15571 | TestCompletionCallback ssl_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15572 | HttpNetworkTransaction ssl_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15573 | ASSERT_EQ(ERR_IO_PENDING, |
| 15574 | ssl_trans.Start(&ssl_request, ssl_callback.callback(), |
| 15575 | NetLogWithSource())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15576 | |
| 15577 | // Start the HTTP request. Pool should stall. |
| 15578 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15579 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15580 | ASSERT_EQ(ERR_IO_PENDING, |
| 15581 | http_trans.Start(&http_request, http_callback.callback(), |
| 15582 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15583 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15584 | |
| 15585 | // Wait for response from SSL request. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15586 | ASSERT_THAT(ssl_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15587 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15588 | ASSERT_THAT(ReadTransaction(&ssl_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15589 | EXPECT_EQ("hello world", response_data); |
| 15590 | |
| 15591 | // The SSL socket should automatically be closed, so the HTTP request can |
| 15592 | // start. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15593 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 15594 | ASSERT_FALSE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15595 | |
| 15596 | // The HTTP request can now complete. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15597 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15598 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15599 | EXPECT_EQ("falafel", response_data); |
| 15600 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15601 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15602 | } |
| 15603 | |
| 15604 | // Tests that when a SSL connection is established but there's no corresponding |
| 15605 | // request that needs it, the new socket is closed if the transport socket pool |
| 15606 | // is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15607 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15608 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 15609 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15610 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 15611 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15612 | |
| 15613 | // Set up an ssl request. |
| 15614 | |
| 15615 | HttpRequestInfo ssl_request; |
| 15616 | ssl_request.method = "GET"; |
| 15617 | ssl_request.url = GURL("https://www.foopy.com/"); |
| 15618 | |
| 15619 | // No data will be sent on the SSL socket. |
| 15620 | StaticSocketDataProvider ssl_data; |
| 15621 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 15622 | |
| 15623 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 15624 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15625 | |
| 15626 | // Set up HTTP request. |
| 15627 | |
| 15628 | HttpRequestInfo http_request; |
| 15629 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15630 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15631 | |
| 15632 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15633 | MockWrite( |
| 15634 | "GET / HTTP/1.1\r\n" |
| 15635 | "Host: www.example.org\r\n" |
| 15636 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15637 | }; |
| 15638 | MockRead http_reads[] = { |
| 15639 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15640 | MockRead("Content-Length: 7\r\n\r\n"), |
| 15641 | MockRead("falafel"), |
| 15642 | MockRead(SYNCHRONOUS, OK), |
| 15643 | }; |
| 15644 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 15645 | http_writes, arraysize(http_writes)); |
| 15646 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 15647 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15648 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15649 | |
| 15650 | // Preconnect an SSL socket. A preconnect is needed because connect jobs are |
| 15651 | // cancelled when a normal transaction is cancelled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15652 | HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 15653 | http_stream_factory->PreconnectStreams(1, ssl_request); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15654 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15655 | |
| 15656 | // Start the HTTP request. Pool should stall. |
| 15657 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15658 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15659 | ASSERT_EQ(ERR_IO_PENDING, |
| 15660 | http_trans.Start(&http_request, http_callback.callback(), |
| 15661 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15662 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15663 | |
| 15664 | // The SSL connection will automatically be closed once the connection is |
| 15665 | // established, to let the HTTP request start. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15666 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15667 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15668 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15669 | EXPECT_EQ("falafel", response_data); |
| 15670 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15671 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15672 | } |
| 15673 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15674 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15675 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15676 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 15677 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15678 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15679 | |
| 15680 | HttpRequestInfo request; |
| 15681 | request.method = "POST"; |
| 15682 | request.url = GURL("http://www.foo.com/"); |
| 15683 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15684 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15685 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15686 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15687 | // Send headers successfully, but get an error while sending the body. |
| 15688 | MockWrite data_writes[] = { |
| 15689 | MockWrite("POST / HTTP/1.1\r\n" |
| 15690 | "Host: www.foo.com\r\n" |
| 15691 | "Connection: keep-alive\r\n" |
| 15692 | "Content-Length: 3\r\n\r\n"), |
| 15693 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15694 | }; |
| 15695 | |
| 15696 | MockRead data_reads[] = { |
| 15697 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 15698 | MockRead("hello world"), |
| 15699 | MockRead(SYNCHRONOUS, OK), |
| 15700 | }; |
| 15701 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15702 | arraysize(data_writes)); |
| 15703 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15704 | |
| 15705 | TestCompletionCallback callback; |
| 15706 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15707 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15708 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15709 | |
| 15710 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15711 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15712 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15713 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15714 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15715 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15716 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15717 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 15718 | |
| 15719 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15720 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15721 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15722 | EXPECT_EQ("hello world", response_data); |
| 15723 | } |
| 15724 | |
| 15725 | // This test makes sure the retry logic doesn't trigger when reading an error |
| 15726 | // response from a server that rejected a POST with a CONNECTION_RESET. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15727 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15728 | PostReadsErrorResponseAfterResetOnReusedSocket) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15729 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15730 | MockWrite data_writes[] = { |
| 15731 | MockWrite("GET / HTTP/1.1\r\n" |
| 15732 | "Host: www.foo.com\r\n" |
| 15733 | "Connection: keep-alive\r\n\r\n"), |
| 15734 | MockWrite("POST / HTTP/1.1\r\n" |
| 15735 | "Host: www.foo.com\r\n" |
| 15736 | "Connection: keep-alive\r\n" |
| 15737 | "Content-Length: 3\r\n\r\n"), |
| 15738 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15739 | }; |
| 15740 | |
| 15741 | MockRead data_reads[] = { |
| 15742 | MockRead("HTTP/1.1 200 Peachy\r\n" |
| 15743 | "Content-Length: 14\r\n\r\n"), |
| 15744 | MockRead("first response"), |
| 15745 | MockRead("HTTP/1.1 400 Not OK\r\n" |
| 15746 | "Content-Length: 15\r\n\r\n"), |
| 15747 | MockRead("second response"), |
| 15748 | MockRead(SYNCHRONOUS, OK), |
| 15749 | }; |
| 15750 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15751 | arraysize(data_writes)); |
| 15752 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15753 | |
| 15754 | TestCompletionCallback callback; |
| 15755 | HttpRequestInfo request1; |
| 15756 | request1.method = "GET"; |
| 15757 | request1.url = GURL("http://www.foo.com/"); |
| 15758 | request1.load_flags = 0; |
| 15759 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15760 | auto trans1 = |
| 15761 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15762 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15763 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15764 | |
| 15765 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15766 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15767 | |
| 15768 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15769 | ASSERT_TRUE(response1); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15770 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15771 | EXPECT_TRUE(response1->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15772 | EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine()); |
| 15773 | |
| 15774 | std::string response_data1; |
| 15775 | rv = ReadTransaction(trans1.get(), &response_data1); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15776 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15777 | EXPECT_EQ("first response", response_data1); |
| 15778 | // Delete the transaction to release the socket back into the socket pool. |
| 15779 | trans1.reset(); |
| 15780 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15781 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15782 | element_readers.push_back( |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15783 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15784 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15785 | |
| 15786 | HttpRequestInfo request2; |
| 15787 | request2.method = "POST"; |
| 15788 | request2.url = GURL("http://www.foo.com/"); |
| 15789 | request2.upload_data_stream = &upload_data_stream; |
| 15790 | request2.load_flags = 0; |
| 15791 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15792 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15793 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15794 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15795 | |
| 15796 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15797 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15798 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15799 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15800 | ASSERT_TRUE(response2); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15801 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15802 | EXPECT_TRUE(response2->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15803 | EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine()); |
| 15804 | |
| 15805 | std::string response_data2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15806 | rv = ReadTransaction(&trans2, &response_data2); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15807 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15808 | EXPECT_EQ("second response", response_data2); |
| 15809 | } |
| 15810 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15811 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15812 | PostReadsErrorResponseAfterResetPartialBodySent) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15813 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15814 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 15815 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15816 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15817 | |
| 15818 | HttpRequestInfo request; |
| 15819 | request.method = "POST"; |
| 15820 | request.url = GURL("http://www.foo.com/"); |
| 15821 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15822 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15823 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15824 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15825 | // Send headers successfully, but get an error while sending the body. |
| 15826 | MockWrite data_writes[] = { |
| 15827 | MockWrite("POST / HTTP/1.1\r\n" |
| 15828 | "Host: www.foo.com\r\n" |
| 15829 | "Connection: keep-alive\r\n" |
| 15830 | "Content-Length: 3\r\n\r\n" |
| 15831 | "fo"), |
| 15832 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15833 | }; |
| 15834 | |
| 15835 | MockRead data_reads[] = { |
| 15836 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 15837 | MockRead("hello world"), |
| 15838 | MockRead(SYNCHRONOUS, OK), |
| 15839 | }; |
| 15840 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15841 | arraysize(data_writes)); |
| 15842 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15843 | |
| 15844 | TestCompletionCallback callback; |
| 15845 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15846 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15847 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15848 | |
| 15849 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15850 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15851 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15852 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15853 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15854 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15855 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15856 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 15857 | |
| 15858 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15859 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15860 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15861 | EXPECT_EQ("hello world", response_data); |
| 15862 | } |
| 15863 | |
| 15864 | // This tests the more common case than the previous test, where headers and |
| 15865 | // body are not merged into a single request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15866 | TEST_F(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) { |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 15867 | ChunkedUploadDataStream upload_data_stream(0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15868 | |
| 15869 | HttpRequestInfo request; |
| 15870 | request.method = "POST"; |
| 15871 | request.url = GURL("http://www.foo.com/"); |
| 15872 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15873 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15874 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15875 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15876 | // Send headers successfully, but get an error while sending the body. |
| 15877 | MockWrite data_writes[] = { |
| 15878 | MockWrite("POST / HTTP/1.1\r\n" |
| 15879 | "Host: www.foo.com\r\n" |
| 15880 | "Connection: keep-alive\r\n" |
| 15881 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 15882 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15883 | }; |
| 15884 | |
| 15885 | MockRead data_reads[] = { |
| 15886 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 15887 | MockRead("hello world"), |
| 15888 | MockRead(SYNCHRONOUS, OK), |
| 15889 | }; |
| 15890 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15891 | arraysize(data_writes)); |
| 15892 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15893 | |
| 15894 | TestCompletionCallback callback; |
| 15895 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15896 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15897 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15898 | // Make sure the headers are sent before adding a chunk. This ensures that |
| 15899 | // they can't be merged with the body in a single send. Not currently |
| 15900 | // necessary since a chunked body is never merged with headers, but this makes |
| 15901 | // the test more future proof. |
| 15902 | base::RunLoop().RunUntilIdle(); |
| 15903 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 15904 | upload_data_stream.AppendData("last chunk", 10, true); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15905 | |
| 15906 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15907 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15908 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15909 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15910 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15911 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15912 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15913 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 15914 | |
| 15915 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15916 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15917 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15918 | EXPECT_EQ("hello world", response_data); |
| 15919 | } |
| 15920 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15921 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15922 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15923 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 15924 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15925 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15926 | |
| 15927 | HttpRequestInfo request; |
| 15928 | request.method = "POST"; |
| 15929 | request.url = GURL("http://www.foo.com/"); |
| 15930 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15931 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15932 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15933 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15934 | |
| 15935 | MockWrite data_writes[] = { |
| 15936 | MockWrite("POST / HTTP/1.1\r\n" |
| 15937 | "Host: www.foo.com\r\n" |
| 15938 | "Connection: keep-alive\r\n" |
| 15939 | "Content-Length: 3\r\n\r\n"), |
| 15940 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15941 | }; |
| 15942 | |
| 15943 | MockRead data_reads[] = { |
| 15944 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 15945 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 15946 | MockRead("hello world"), |
| 15947 | MockRead(SYNCHRONOUS, OK), |
| 15948 | }; |
| 15949 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15950 | arraysize(data_writes)); |
| 15951 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15952 | |
| 15953 | TestCompletionCallback callback; |
| 15954 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15955 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15956 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15957 | |
| 15958 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15959 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15960 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15961 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15962 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15963 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15964 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15965 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 15966 | |
| 15967 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15968 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15969 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15970 | EXPECT_EQ("hello world", response_data); |
| 15971 | } |
| 15972 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15973 | TEST_F(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15974 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15975 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 15976 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15977 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15978 | |
| 15979 | HttpRequestInfo request; |
| 15980 | request.method = "POST"; |
| 15981 | request.url = GURL("http://www.foo.com/"); |
| 15982 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15983 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15984 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15985 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15986 | // Send headers successfully, but get an error while sending the body. |
| 15987 | MockWrite data_writes[] = { |
| 15988 | MockWrite("POST / HTTP/1.1\r\n" |
| 15989 | "Host: www.foo.com\r\n" |
| 15990 | "Connection: keep-alive\r\n" |
| 15991 | "Content-Length: 3\r\n\r\n"), |
| 15992 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15993 | }; |
| 15994 | |
| 15995 | MockRead data_reads[] = { |
| 15996 | MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"), |
| 15997 | MockRead("hello world"), |
| 15998 | MockRead(SYNCHRONOUS, OK), |
| 15999 | }; |
| 16000 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16001 | arraysize(data_writes)); |
| 16002 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16003 | |
| 16004 | TestCompletionCallback callback; |
| 16005 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16006 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16007 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16008 | |
| 16009 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16010 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16011 | } |
| 16012 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16013 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16014 | PostIgnoresNonErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16015 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16016 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 16017 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16018 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16019 | |
| 16020 | HttpRequestInfo request; |
| 16021 | request.method = "POST"; |
| 16022 | request.url = GURL("http://www.foo.com/"); |
| 16023 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16024 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16025 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16026 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16027 | // Send headers successfully, but get an error while sending the body. |
| 16028 | MockWrite data_writes[] = { |
| 16029 | MockWrite("POST / HTTP/1.1\r\n" |
| 16030 | "Host: www.foo.com\r\n" |
| 16031 | "Connection: keep-alive\r\n" |
| 16032 | "Content-Length: 3\r\n\r\n"), |
| 16033 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16034 | }; |
| 16035 | |
| 16036 | MockRead data_reads[] = { |
| 16037 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 16038 | MockRead("HTTP/1.0 302 Redirect\r\n"), |
| 16039 | MockRead("Location: http://somewhere-else.com/\r\n"), |
| 16040 | MockRead("Content-Length: 0\r\n\r\n"), |
| 16041 | MockRead(SYNCHRONOUS, OK), |
| 16042 | }; |
| 16043 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16044 | arraysize(data_writes)); |
| 16045 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16046 | |
| 16047 | TestCompletionCallback callback; |
| 16048 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16049 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16050 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16051 | |
| 16052 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16053 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16054 | } |
| 16055 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16056 | TEST_F(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16057 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16058 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 16059 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16060 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16061 | |
| 16062 | HttpRequestInfo request; |
| 16063 | request.method = "POST"; |
| 16064 | request.url = GURL("http://www.foo.com/"); |
| 16065 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16066 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16067 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16068 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16069 | // Send headers successfully, but get an error while sending the body. |
| 16070 | MockWrite data_writes[] = { |
| 16071 | MockWrite("POST / HTTP/1.1\r\n" |
| 16072 | "Host: www.foo.com\r\n" |
| 16073 | "Connection: keep-alive\r\n" |
| 16074 | "Content-Length: 3\r\n\r\n"), |
| 16075 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16076 | }; |
| 16077 | |
| 16078 | MockRead data_reads[] = { |
| 16079 | MockRead("HTTP 0.9 rocks!"), |
| 16080 | MockRead(SYNCHRONOUS, OK), |
| 16081 | }; |
| 16082 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16083 | arraysize(data_writes)); |
| 16084 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16085 | |
| 16086 | TestCompletionCallback callback; |
| 16087 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16088 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16089 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16090 | |
| 16091 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16092 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16093 | } |
| 16094 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16095 | TEST_F(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16096 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16097 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 16098 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16099 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16100 | |
| 16101 | HttpRequestInfo request; |
| 16102 | request.method = "POST"; |
| 16103 | request.url = GURL("http://www.foo.com/"); |
| 16104 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16105 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16106 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16107 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16108 | // Send headers successfully, but get an error while sending the body. |
| 16109 | MockWrite data_writes[] = { |
| 16110 | MockWrite("POST / HTTP/1.1\r\n" |
| 16111 | "Host: www.foo.com\r\n" |
| 16112 | "Connection: keep-alive\r\n" |
| 16113 | "Content-Length: 3\r\n\r\n"), |
| 16114 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16115 | }; |
| 16116 | |
| 16117 | MockRead data_reads[] = { |
| 16118 | MockRead("HTTP/1.0 400 Not a Full Response\r\n"), |
| 16119 | MockRead(SYNCHRONOUS, OK), |
| 16120 | }; |
| 16121 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16122 | arraysize(data_writes)); |
| 16123 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16124 | |
| 16125 | TestCompletionCallback callback; |
| 16126 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16127 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16128 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16129 | |
| 16130 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16131 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16132 | } |
| 16133 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16134 | // Verify that proxy headers are not sent to the destination server when |
| 16135 | // establishing a tunnel for a secure WebSocket connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16136 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWssTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16137 | HttpRequestInfo request; |
| 16138 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16139 | request.url = GURL("wss://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16140 | AddWebSocketHeaders(&request.extra_headers); |
| 16141 | |
| 16142 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 16143 | session_deps_.proxy_service = |
| 16144 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16145 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16146 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16147 | |
| 16148 | // Since a proxy is configured, try to establish a tunnel. |
| 16149 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16150 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 16151 | "Host: www.example.org:443\r\n" |
| 16152 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16153 | |
| 16154 | // After calling trans->RestartWithAuth(), this is the request we should |
| 16155 | // be issuing -- the final header line contains the credentials. |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16156 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 16157 | "Host: www.example.org:443\r\n" |
| 16158 | "Proxy-Connection: keep-alive\r\n" |
| 16159 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16160 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16161 | MockWrite("GET / HTTP/1.1\r\n" |
| 16162 | "Host: www.example.org\r\n" |
| 16163 | "Connection: Upgrade\r\n" |
| 16164 | "Upgrade: websocket\r\n" |
| 16165 | "Origin: http://www.example.org\r\n" |
| 16166 | "Sec-WebSocket-Version: 13\r\n" |
| 16167 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16168 | }; |
| 16169 | |
| 16170 | // The proxy responds to the connect with a 407, using a persistent |
| 16171 | // connection. |
| 16172 | MockRead data_reads[] = { |
| 16173 | // No credentials. |
| 16174 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 16175 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 16176 | MockRead("Content-Length: 0\r\n"), |
| 16177 | MockRead("Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16178 | |
| 16179 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 16180 | |
| 16181 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 16182 | MockRead("Upgrade: websocket\r\n"), |
| 16183 | MockRead("Connection: Upgrade\r\n"), |
| 16184 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 16185 | }; |
| 16186 | |
| 16187 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16188 | arraysize(data_writes)); |
| 16189 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16190 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 16191 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16192 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16193 | auto trans = |
| 16194 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16195 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 16196 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 16197 | &websocket_stream_create_helper); |
| 16198 | |
| 16199 | { |
| 16200 | TestCompletionCallback callback; |
| 16201 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16202 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16203 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16204 | |
| 16205 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16206 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16207 | } |
| 16208 | |
| 16209 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 16210 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16211 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16212 | EXPECT_EQ(407, response->headers->response_code()); |
| 16213 | |
| 16214 | { |
| 16215 | TestCompletionCallback callback; |
| 16216 | |
| 16217 | int rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 16218 | callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16219 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16220 | |
| 16221 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16222 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16223 | } |
| 16224 | |
| 16225 | response = trans->GetResponseInfo(); |
| 16226 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16227 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16228 | |
| 16229 | EXPECT_EQ(101, response->headers->response_code()); |
| 16230 | |
| 16231 | trans.reset(); |
| 16232 | session->CloseAllConnections(); |
| 16233 | } |
| 16234 | |
| 16235 | // Verify that proxy headers are not sent to the destination server when |
| 16236 | // establishing a tunnel for an insecure WebSocket connection. |
| 16237 | // This requires the authentication info to be injected into the auth cache |
| 16238 | // due to crbug.com/395064 |
| 16239 | // TODO(ricea): Change to use a 407 response once issue 395064 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16240 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWsTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16241 | HttpRequestInfo request; |
| 16242 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16243 | request.url = GURL("ws://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16244 | AddWebSocketHeaders(&request.extra_headers); |
| 16245 | |
| 16246 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 16247 | session_deps_.proxy_service = |
| 16248 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16249 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16250 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16251 | |
| 16252 | MockWrite data_writes[] = { |
| 16253 | // Try to establish a tunnel for the WebSocket connection, with |
| 16254 | // credentials. Because WebSockets have a separate set of socket pools, |
| 16255 | // they cannot and will not use the same TCP/IP connection as the |
| 16256 | // preflight HTTP request. |
| 16257 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16258 | "CONNECT www.example.org:80 HTTP/1.1\r\n" |
| 16259 | "Host: www.example.org:80\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16260 | "Proxy-Connection: keep-alive\r\n" |
| 16261 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 16262 | |
| 16263 | MockWrite( |
| 16264 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16265 | "Host: www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16266 | "Connection: Upgrade\r\n" |
| 16267 | "Upgrade: websocket\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16268 | "Origin: http://www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16269 | "Sec-WebSocket-Version: 13\r\n" |
| 16270 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
| 16271 | }; |
| 16272 | |
| 16273 | MockRead data_reads[] = { |
| 16274 | // HTTP CONNECT with credentials. |
| 16275 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 16276 | |
| 16277 | // WebSocket connection established inside tunnel. |
| 16278 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 16279 | MockRead("Upgrade: websocket\r\n"), |
| 16280 | MockRead("Connection: Upgrade\r\n"), |
| 16281 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 16282 | }; |
| 16283 | |
| 16284 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16285 | arraysize(data_writes)); |
| 16286 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16287 | |
| 16288 | session->http_auth_cache()->Add( |
| 16289 | GURL("http://myproxy:70/"), "MyRealm1", HttpAuth::AUTH_SCHEME_BASIC, |
| 16290 | "Basic realm=MyRealm1", AuthCredentials(kFoo, kBar), "/"); |
| 16291 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16292 | auto trans = |
| 16293 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16294 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 16295 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 16296 | &websocket_stream_create_helper); |
| 16297 | |
| 16298 | TestCompletionCallback callback; |
| 16299 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16300 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16301 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16302 | |
| 16303 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16304 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16305 | |
| 16306 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 16307 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16308 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16309 | |
| 16310 | EXPECT_EQ(101, response->headers->response_code()); |
| 16311 | |
| 16312 | trans.reset(); |
| 16313 | session->CloseAllConnections(); |
| 16314 | } |
| 16315 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16316 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16317 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16318 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 16319 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16320 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16321 | |
| 16322 | HttpRequestInfo request; |
| 16323 | request.method = "POST"; |
| 16324 | request.url = GURL("http://www.foo.com/"); |
| 16325 | request.upload_data_stream = &upload_data_stream; |
| 16326 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16327 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16328 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16329 | MockWrite data_writes[] = { |
| 16330 | MockWrite("POST / HTTP/1.1\r\n" |
| 16331 | "Host: www.foo.com\r\n" |
| 16332 | "Connection: keep-alive\r\n" |
| 16333 | "Content-Length: 3\r\n\r\n"), |
| 16334 | MockWrite("foo"), |
| 16335 | }; |
| 16336 | |
| 16337 | MockRead data_reads[] = { |
| 16338 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16339 | MockRead(SYNCHRONOUS, OK), |
| 16340 | }; |
| 16341 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16342 | arraysize(data_writes)); |
| 16343 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16344 | |
| 16345 | TestCompletionCallback callback; |
| 16346 | |
| 16347 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16348 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16349 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16350 | |
| 16351 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16352 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16353 | |
| 16354 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16355 | trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16356 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16357 | trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16358 | } |
| 16359 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16360 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost100Continue) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16361 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16362 | element_readers.push_back( |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 16363 | base::MakeUnique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16364 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16365 | |
| 16366 | HttpRequestInfo request; |
| 16367 | request.method = "POST"; |
| 16368 | request.url = GURL("http://www.foo.com/"); |
| 16369 | request.upload_data_stream = &upload_data_stream; |
| 16370 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16371 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16372 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16373 | MockWrite data_writes[] = { |
| 16374 | MockWrite("POST / HTTP/1.1\r\n" |
| 16375 | "Host: www.foo.com\r\n" |
| 16376 | "Connection: keep-alive\r\n" |
| 16377 | "Content-Length: 3\r\n\r\n"), |
| 16378 | MockWrite("foo"), |
| 16379 | }; |
| 16380 | |
| 16381 | MockRead data_reads[] = { |
| 16382 | MockRead("HTTP/1.1 100 Continue\r\n\r\n"), |
| 16383 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16384 | MockRead(SYNCHRONOUS, OK), |
| 16385 | }; |
| 16386 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16387 | arraysize(data_writes)); |
| 16388 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16389 | |
| 16390 | TestCompletionCallback callback; |
| 16391 | |
| 16392 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16393 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16394 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16395 | |
| 16396 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16397 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16398 | |
| 16399 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16400 | trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16401 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16402 | trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16403 | } |
| 16404 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16405 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesChunkedPost) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16406 | ChunkedUploadDataStream upload_data_stream(0); |
| 16407 | |
| 16408 | HttpRequestInfo request; |
| 16409 | request.method = "POST"; |
| 16410 | request.url = GURL("http://www.foo.com/"); |
| 16411 | request.upload_data_stream = &upload_data_stream; |
| 16412 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16413 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16414 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16415 | // Send headers successfully, but get an error while sending the body. |
| 16416 | MockWrite data_writes[] = { |
| 16417 | MockWrite("POST / HTTP/1.1\r\n" |
| 16418 | "Host: www.foo.com\r\n" |
| 16419 | "Connection: keep-alive\r\n" |
| 16420 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 16421 | MockWrite("1\r\nf\r\n"), MockWrite("2\r\noo\r\n"), MockWrite("0\r\n\r\n"), |
| 16422 | }; |
| 16423 | |
| 16424 | MockRead data_reads[] = { |
| 16425 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16426 | MockRead(SYNCHRONOUS, OK), |
| 16427 | }; |
| 16428 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16429 | arraysize(data_writes)); |
| 16430 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16431 | |
| 16432 | TestCompletionCallback callback; |
| 16433 | |
| 16434 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16435 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16436 | |
| 16437 | base::RunLoop().RunUntilIdle(); |
| 16438 | upload_data_stream.AppendData("f", 1, false); |
| 16439 | |
| 16440 | base::RunLoop().RunUntilIdle(); |
| 16441 | upload_data_stream.AppendData("oo", 2, true); |
| 16442 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16443 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16444 | |
| 16445 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16446 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16447 | |
| 16448 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16449 | trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16450 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16451 | trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16452 | } |
| 16453 | |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16454 | // Confirm that transactions whose throttle is created in (and stays in) |
| 16455 | // the unthrottled state are not blocked. |
| 16456 | TEST_F(HttpNetworkTransactionTest, ThrottlingUnthrottled) { |
| 16457 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16458 | std::unique_ptr<HttpNetworkSession> session( |
| 16459 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16460 | |
| 16461 | // Send a simple request and make sure it goes through. |
| 16462 | HttpRequestInfo request; |
| 16463 | request.method = "GET"; |
| 16464 | request.url = GURL("http://www.example.org/"); |
| 16465 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16466 | auto trans = |
| 16467 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16468 | |
| 16469 | MockWrite data_writes[] = { |
| 16470 | MockWrite("GET / HTTP/1.1\r\n" |
| 16471 | "Host: www.example.org\r\n" |
| 16472 | "Connection: keep-alive\r\n\r\n"), |
| 16473 | }; |
| 16474 | MockRead data_reads[] = { |
| 16475 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16476 | MockRead(SYNCHRONOUS, OK), |
| 16477 | }; |
| 16478 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16479 | arraysize(data_writes)); |
| 16480 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16481 | |
| 16482 | TestCompletionCallback callback; |
| 16483 | trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16484 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 16485 | } |
| 16486 | |
| 16487 | // Confirm requests can be blocked by a throttler, and are resumed |
| 16488 | // when the throttle is unblocked. |
| 16489 | TEST_F(HttpNetworkTransactionTest, ThrottlingBasic) { |
| 16490 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16491 | std::unique_ptr<HttpNetworkSession> session( |
| 16492 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16493 | |
| 16494 | // Send a simple request and make sure it goes through. |
| 16495 | HttpRequestInfo request; |
| 16496 | request.method = "GET"; |
| 16497 | request.url = GURL("http://www.example.org/"); |
| 16498 | |
| 16499 | MockWrite data_writes[] = { |
| 16500 | MockWrite("GET / HTTP/1.1\r\n" |
| 16501 | "Host: www.example.org\r\n" |
| 16502 | "Connection: keep-alive\r\n\r\n"), |
| 16503 | }; |
| 16504 | MockRead data_reads[] = { |
| 16505 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16506 | MockRead(SYNCHRONOUS, OK), |
| 16507 | }; |
| 16508 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16509 | arraysize(data_writes)); |
| 16510 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16511 | |
| 16512 | // Start a request that will be throttled at start; confirm it |
| 16513 | // doesn't complete. |
| 16514 | throttler->set_throttle_new_requests(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16515 | auto trans = |
| 16516 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16517 | |
| 16518 | TestCompletionCallback callback; |
| 16519 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16520 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16521 | |
| 16522 | base::RunLoop().RunUntilIdle(); |
| 16523 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 16524 | EXPECT_FALSE(callback.have_result()); |
| 16525 | |
| 16526 | // Confirm the request goes on to complete when unthrottled. |
| 16527 | throttler->UnthrottleAllRequests(); |
| 16528 | base::RunLoop().RunUntilIdle(); |
| 16529 | ASSERT_TRUE(callback.have_result()); |
| 16530 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 16531 | } |
| 16532 | |
| 16533 | // Destroy a request while it's throttled. |
| 16534 | TEST_F(HttpNetworkTransactionTest, ThrottlingDestruction) { |
| 16535 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16536 | std::unique_ptr<HttpNetworkSession> session( |
| 16537 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16538 | |
| 16539 | // Send a simple request and make sure it goes through. |
| 16540 | HttpRequestInfo request; |
| 16541 | request.method = "GET"; |
| 16542 | request.url = GURL("http://www.example.org/"); |
| 16543 | |
| 16544 | MockWrite data_writes[] = { |
| 16545 | MockWrite("GET / HTTP/1.1\r\n" |
| 16546 | "Host: www.example.org\r\n" |
| 16547 | "Connection: keep-alive\r\n\r\n"), |
| 16548 | }; |
| 16549 | MockRead data_reads[] = { |
| 16550 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16551 | MockRead(SYNCHRONOUS, OK), |
| 16552 | }; |
| 16553 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16554 | arraysize(data_writes)); |
| 16555 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16556 | |
| 16557 | // Start a request that will be throttled at start; confirm it |
| 16558 | // doesn't complete. |
| 16559 | throttler->set_throttle_new_requests(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16560 | auto trans = |
| 16561 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16562 | |
| 16563 | TestCompletionCallback callback; |
| 16564 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16565 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16566 | |
| 16567 | base::RunLoop().RunUntilIdle(); |
| 16568 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 16569 | EXPECT_FALSE(callback.have_result()); |
| 16570 | |
| 16571 | EXPECT_EQ(1u, throttler->num_outstanding_requests()); |
| 16572 | trans.reset(); |
| 16573 | EXPECT_EQ(0u, throttler->num_outstanding_requests()); |
| 16574 | } |
| 16575 | |
| 16576 | // Confirm the throttler receives SetPriority calls. |
| 16577 | TEST_F(HttpNetworkTransactionTest, ThrottlingPrioritySet) { |
| 16578 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16579 | std::unique_ptr<HttpNetworkSession> session( |
| 16580 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16581 | |
| 16582 | // Send a simple request and make sure it goes through. |
| 16583 | HttpRequestInfo request; |
| 16584 | request.method = "GET"; |
| 16585 | request.url = GURL("http://www.example.org/"); |
| 16586 | |
| 16587 | MockWrite data_writes[] = { |
| 16588 | MockWrite("GET / HTTP/1.1\r\n" |
| 16589 | "Host: www.example.org\r\n" |
| 16590 | "Connection: keep-alive\r\n\r\n"), |
| 16591 | }; |
| 16592 | MockRead data_reads[] = { |
| 16593 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16594 | MockRead(SYNCHRONOUS, OK), |
| 16595 | }; |
| 16596 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16597 | arraysize(data_writes)); |
| 16598 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16599 | |
| 16600 | throttler->set_throttle_new_requests(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16601 | auto trans = base::MakeUnique<HttpNetworkTransaction>(IDLE, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16602 | // Start the transaction to associate a throttle with it. |
| 16603 | TestCompletionCallback callback; |
| 16604 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16605 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16606 | |
| 16607 | EXPECT_EQ(0, throttler->num_set_priority_calls()); |
| 16608 | trans->SetPriority(LOW); |
| 16609 | EXPECT_EQ(1, throttler->num_set_priority_calls()); |
| 16610 | EXPECT_EQ(LOW, throttler->last_priority_set()); |
| 16611 | |
| 16612 | throttler->UnthrottleAllRequests(); |
| 16613 | base::RunLoop().RunUntilIdle(); |
| 16614 | ASSERT_TRUE(callback.have_result()); |
| 16615 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 16616 | } |
| 16617 | |
| 16618 | // Confirm that unthrottling from a SetPriority call by the |
| 16619 | // throttler works properly. |
| 16620 | TEST_F(HttpNetworkTransactionTest, ThrottlingPrioritySetUnthrottle) { |
| 16621 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16622 | std::unique_ptr<HttpNetworkSession> session( |
| 16623 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16624 | |
| 16625 | // Send a simple request and make sure it goes through. |
| 16626 | HttpRequestInfo request; |
| 16627 | request.method = "GET"; |
| 16628 | request.url = GURL("http://www.example.org/"); |
| 16629 | |
| 16630 | MockWrite data_writes[] = { |
| 16631 | MockWrite("GET / HTTP/1.1\r\n" |
| 16632 | "Host: www.example.org\r\n" |
| 16633 | "Connection: keep-alive\r\n\r\n"), |
| 16634 | }; |
| 16635 | MockRead data_reads[] = { |
| 16636 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16637 | MockRead(SYNCHRONOUS, OK), |
| 16638 | }; |
| 16639 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16640 | arraysize(data_writes)); |
| 16641 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16642 | |
| 16643 | StaticSocketDataProvider reads1(data_reads, arraysize(data_reads), |
| 16644 | data_writes, arraysize(data_writes)); |
| 16645 | session_deps_.socket_factory->AddSocketDataProvider(&reads1); |
| 16646 | |
| 16647 | // Start a request that will be throttled at start; confirm it |
| 16648 | // doesn't complete. |
| 16649 | throttler->set_throttle_new_requests(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16650 | auto trans = |
| 16651 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16652 | |
| 16653 | TestCompletionCallback callback; |
| 16654 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16655 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16656 | |
| 16657 | base::RunLoop().RunUntilIdle(); |
| 16658 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 16659 | EXPECT_FALSE(callback.have_result()); |
| 16660 | |
| 16661 | // Create a new request, call SetPriority on it to unthrottle, |
| 16662 | // and make sure that allows the original request to complete. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16663 | auto trans1 = base::MakeUnique<HttpNetworkTransaction>(LOW, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16664 | throttler->set_priority_change_closure( |
| 16665 | base::Bind(&TestNetworkStreamThrottler::UnthrottleAllRequests, |
| 16666 | base::Unretained(throttler))); |
| 16667 | |
| 16668 | // Start the transaction to associate a throttle with it. |
| 16669 | TestCompletionCallback callback1; |
| 16670 | rv = trans1->Start(&request, callback1.callback(), NetLogWithSource()); |
| 16671 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16672 | |
| 16673 | trans1->SetPriority(IDLE); |
| 16674 | |
| 16675 | base::RunLoop().RunUntilIdle(); |
| 16676 | ASSERT_TRUE(callback.have_result()); |
| 16677 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 16678 | ASSERT_TRUE(callback1.have_result()); |
| 16679 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 16680 | } |
| 16681 | |
| 16682 | // Transaction will be destroyed when the unique_ptr goes out of scope. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16683 | void DestroyTransaction(std::unique_ptr<HttpNetworkTransaction> transaction) {} |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16684 | |
| 16685 | // Confirm that destroying a transaction from a SetPriority call by the |
| 16686 | // throttler works properly. |
| 16687 | TEST_F(HttpNetworkTransactionTest, ThrottlingPrioritySetDestroy) { |
| 16688 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16689 | std::unique_ptr<HttpNetworkSession> session( |
| 16690 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16691 | |
| 16692 | // Send a simple request and make sure it goes through. |
| 16693 | HttpRequestInfo request; |
| 16694 | request.method = "GET"; |
| 16695 | request.url = GURL("http://www.example.org/"); |
| 16696 | |
| 16697 | MockWrite data_writes[] = { |
| 16698 | MockWrite("GET / HTTP/1.1\r\n" |
| 16699 | "Host: www.example.org\r\n" |
| 16700 | "Connection: keep-alive\r\n\r\n"), |
| 16701 | }; |
| 16702 | MockRead data_reads[] = { |
| 16703 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16704 | MockRead(SYNCHRONOUS, OK), |
| 16705 | }; |
| 16706 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16707 | arraysize(data_writes)); |
| 16708 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16709 | |
| 16710 | StaticSocketDataProvider reads1(data_reads, arraysize(data_reads), |
| 16711 | data_writes, arraysize(data_writes)); |
| 16712 | session_deps_.socket_factory->AddSocketDataProvider(&reads1); |
| 16713 | |
| 16714 | // Start a request that will be throttled at start; confirm it |
| 16715 | // doesn't complete. |
| 16716 | throttler->set_throttle_new_requests(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16717 | auto trans = |
| 16718 | base::MakeUnique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16719 | |
| 16720 | TestCompletionCallback callback; |
| 16721 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16722 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16723 | |
| 16724 | base::RunLoop().RunUntilIdle(); |
| 16725 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 16726 | EXPECT_FALSE(callback.have_result()); |
| 16727 | |
| 16728 | // Arrange for the set priority call on the above transaction to delete |
| 16729 | // the transaction. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16730 | HttpNetworkTransaction* trans_ptr(trans.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16731 | throttler->set_priority_change_closure( |
| 16732 | base::Bind(&DestroyTransaction, base::Passed(&trans))); |
| 16733 | |
| 16734 | // Call it and check results (partially a "doesn't crash" test). |
| 16735 | trans_ptr->SetPriority(IDLE); |
| 16736 | trans_ptr = nullptr; // No longer a valid pointer. |
| 16737 | |
| 16738 | base::RunLoop().RunUntilIdle(); |
| 16739 | ASSERT_FALSE(callback.have_result()); |
| 16740 | } |
| 16741 | |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16742 | #if !defined(OS_IOS) |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16743 | TEST_F(HttpNetworkTransactionTest, TokenBindingSpdy) { |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16744 | const std::string https_url = "https://www.example.com"; |
| 16745 | HttpRequestInfo request; |
| 16746 | request.url = GURL(https_url); |
| 16747 | request.method = "GET"; |
| 16748 | |
| 16749 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 16750 | ssl.token_binding_negotiated = true; |
| 16751 | ssl.token_binding_key_param = TB_PARAM_ECDSAP256; |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16752 | ssl.next_proto = kProtoHTTP2; |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16753 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16754 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16755 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16756 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 16757 | MockRead reads[] = {CreateMockRead(resp), CreateMockRead(body), |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16758 | MockRead(ASYNC, ERR_IO_PENDING)}; |
| 16759 | StaticSocketDataProvider data(reads, arraysize(reads), nullptr, 0); |
| 16760 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16761 | session_deps_.channel_id_service = |
| 16762 | base::MakeUnique<ChannelIDService>(new DefaultChannelIDStore(nullptr)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16763 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16764 | |
| 16765 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 16766 | TestCompletionCallback callback; |
| 16767 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16768 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
fdoray | f33fede | 2017-05-11 21:18:10 | [diff] [blame] | 16769 | |
| 16770 | NetTestSuite::GetScopedTaskEnvironment()->RunUntilIdle(); |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16771 | |
| 16772 | EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); |
| 16773 | HttpRequestHeaders headers; |
| 16774 | ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); |
| 16775 | EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); |
| 16776 | } |
| 16777 | #endif // !defined(OS_IOS) |
| 16778 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 16779 | void CheckContentEncodingMatching(SpdySessionDependencies* session_deps, |
| 16780 | const std::string& accept_encoding, |
| 16781 | const std::string& content_encoding, |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 16782 | const std::string& location, |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 16783 | bool should_match) { |
| 16784 | HttpRequestInfo request; |
| 16785 | request.method = "GET"; |
| 16786 | request.url = GURL("http://www.foo.com/"); |
| 16787 | request.extra_headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, |
| 16788 | accept_encoding); |
| 16789 | |
| 16790 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps)); |
| 16791 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 16792 | // Send headers successfully, but get an error while sending the body. |
| 16793 | MockWrite data_writes[] = { |
| 16794 | MockWrite("GET / HTTP/1.1\r\n" |
| 16795 | "Host: www.foo.com\r\n" |
| 16796 | "Connection: keep-alive\r\n" |
| 16797 | "Accept-Encoding: "), |
| 16798 | MockWrite(accept_encoding.data()), MockWrite("\r\n\r\n"), |
| 16799 | }; |
| 16800 | |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 16801 | std::string response_code = "200 OK"; |
| 16802 | std::string extra; |
| 16803 | if (!location.empty()) { |
| 16804 | response_code = "301 Redirect\r\nLocation: "; |
| 16805 | response_code.append(location); |
| 16806 | } |
| 16807 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 16808 | MockRead data_reads[] = { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 16809 | MockRead("HTTP/1.0 "), |
| 16810 | MockRead(response_code.data()), |
| 16811 | MockRead("\r\nContent-Encoding: "), |
| 16812 | MockRead(content_encoding.data()), |
| 16813 | MockRead("\r\n\r\n"), |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 16814 | MockRead(SYNCHRONOUS, OK), |
| 16815 | }; |
| 16816 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16817 | arraysize(data_writes)); |
| 16818 | session_deps->socket_factory->AddSocketDataProvider(&data); |
| 16819 | |
| 16820 | TestCompletionCallback callback; |
| 16821 | |
| 16822 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 16823 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16824 | |
| 16825 | rv = callback.WaitForResult(); |
| 16826 | if (should_match) { |
| 16827 | EXPECT_THAT(rv, IsOk()); |
| 16828 | } else { |
| 16829 | EXPECT_THAT(rv, IsError(ERR_CONTENT_DECODING_FAILED)); |
| 16830 | } |
| 16831 | } |
| 16832 | |
| 16833 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding1) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 16834 | CheckContentEncodingMatching(&session_deps_, "gzip,sdch", "br", "", false); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 16835 | } |
| 16836 | |
| 16837 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding2) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 16838 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "", "", |
| 16839 | true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 16840 | } |
| 16841 | |
| 16842 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding3) { |
| 16843 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 16844 | "", false); |
| 16845 | } |
| 16846 | |
| 16847 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding4) { |
| 16848 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
| 16849 | "www.foo.com/other", true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 16850 | } |
| 16851 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 16852 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsSync) { |
| 16853 | ProxyConfig proxy_config; |
| 16854 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 16855 | proxy_config.set_pac_mandatory(true); |
| 16856 | MockAsyncProxyResolver resolver; |
| 16857 | session_deps_.proxy_service.reset(new ProxyService( |
| 16858 | base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), |
| 16859 | base::WrapUnique(new FailingProxyResolverFactory), nullptr)); |
| 16860 | |
| 16861 | HttpRequestInfo request; |
| 16862 | request.method = "GET"; |
| 16863 | request.url = GURL("http://www.example.org/"); |
| 16864 | |
| 16865 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 16866 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 16867 | |
| 16868 | TestCompletionCallback callback; |
| 16869 | |
| 16870 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 16871 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16872 | EXPECT_THAT(callback.WaitForResult(), |
| 16873 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 16874 | } |
| 16875 | |
| 16876 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsAsync) { |
| 16877 | ProxyConfig proxy_config; |
| 16878 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 16879 | proxy_config.set_pac_mandatory(true); |
| 16880 | MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 16881 | new MockAsyncProxyResolverFactory(false); |
| 16882 | MockAsyncProxyResolver resolver; |
| 16883 | session_deps_.proxy_service.reset( |
| 16884 | new ProxyService(base::MakeUnique<ProxyConfigServiceFixed>(proxy_config), |
| 16885 | base::WrapUnique(proxy_resolver_factory), nullptr)); |
| 16886 | HttpRequestInfo request; |
| 16887 | request.method = "GET"; |
| 16888 | request.url = GURL("http://www.example.org/"); |
| 16889 | |
| 16890 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 16891 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 16892 | |
| 16893 | TestCompletionCallback callback; |
| 16894 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 16895 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16896 | |
| 16897 | proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder( |
| 16898 | ERR_FAILED, &resolver); |
| 16899 | EXPECT_THAT(callback.WaitForResult(), |
| 16900 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 16901 | } |
| 16902 | |
| 16903 | TEST_F(HttpNetworkTransactionTest, NoSupportedProxies) { |
| 16904 | session_deps_.proxy_service = |
| 16905 | ProxyService::CreateFixedFromPacResult("QUIC myproxy.org:443"); |
| 16906 | session_deps_.enable_quic = false; |
| 16907 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 16908 | |
| 16909 | HttpRequestInfo request; |
| 16910 | request.method = "GET"; |
| 16911 | request.url = GURL("http://www.example.org/"); |
| 16912 | |
| 16913 | TestCompletionCallback callback; |
| 16914 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 16915 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 16916 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16917 | |
| 16918 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_NO_SUPPORTED_PROXIES)); |
| 16919 | } |
| 16920 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 16921 | } // namespace net |