[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 4 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 5 | #include "net/http/http_network_transaction.h" |
| 6 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 7 | #include <math.h> // ceil |
[email protected] | 5285d97 | 2011-10-18 18:56:34 | [diff] [blame] | 8 | #include <stdarg.h> |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 9 | #include <stdint.h> |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10 | |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 11 | #include <limits> |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 12 | #include <set> |
[email protected] | 5285d97 | 2011-10-18 18:56:34 | [diff] [blame] | 13 | #include <string> |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 14 | #include <utility> |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 15 | #include <vector> |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 16 | |
[email protected] | 68bf915 | 2008-09-25 19:47:30 | [diff] [blame] | 17 | #include "base/compiler_specific.h" |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 18 | #include "base/files/file_path.h" |
thestig | d8df033 | 2014-09-04 06:33:29 | [diff] [blame] | 19 | #include "base/files/file_util.h" |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 20 | #include "base/json/json_writer.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 21 | #include "base/logging.h" |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 22 | #include "base/macros.h" |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 23 | #include "base/memory/ptr_util.h" |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 24 | #include "base/memory/weak_ptr.h" |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 25 | #include "base/run_loop.h" |
[email protected] | 125ef48 | 2013-06-11 18:32:47 | [diff] [blame] | 26 | #include "base/strings/string_util.h" |
[email protected] | 750b2f3c | 2013-06-07 18:41:05 | [diff] [blame] | 27 | #include "base/strings/utf_string_conversions.h" |
fdoray | f33fede | 2017-05-11 21:18:10 | [diff] [blame] | 28 | #include "base/test/scoped_task_environment.h" |
[email protected] | f36a813 | 2011-09-02 18:36:33 | [diff] [blame] | 29 | #include "base/test/test_file_util.h" |
gab | f767595f | 2016-05-11 18:50:35 | [diff] [blame] | 30 | #include "base/threading/thread_task_runner_handle.h" |
[email protected] | 277d594 | 2010-08-11 21:02:35 | [diff] [blame] | 31 | #include "net/base/auth.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 32 | #include "net/base/chunked_upload_data_stream.h" |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 33 | #include "net/base/completion_callback.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 34 | #include "net/base/elements_upload_data_stream.h" |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 35 | #include "net/base/load_timing_info.h" |
| 36 | #include "net/base/load_timing_info_test_util.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 37 | #include "net/base/net_errors.h" |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 38 | #include "net/base/network_throttle_manager.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 39 | #include "net/base/proxy_delegate.h" |
[email protected] | ac790b4 | 2009-12-02 04:31:31 | [diff] [blame] | 40 | #include "net/base/request_priority.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 41 | #include "net/base/test_completion_callback.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 42 | #include "net/base/test_proxy_delegate.h" |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 43 | #include "net/base/upload_bytes_element_reader.h" |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 44 | #include "net/base/upload_file_element_reader.h" |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 45 | #include "net/cert/cert_status_flags.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 46 | #include "net/cert/mock_cert_verifier.h" |
[email protected] | bc71b877 | 2013-04-10 20:55:16 | [diff] [blame] | 47 | #include "net/dns/host_cache.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 48 | #include "net/dns/mock_host_resolver.h" |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 49 | #include "net/http/http_auth_challenge_tokenizer.h" |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 50 | #include "net/http/http_auth_handler_digest.h" |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 51 | #include "net/http/http_auth_handler_mock.h" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 52 | #include "net/http/http_auth_handler_ntlm.h" |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 53 | #include "net/http/http_auth_scheme.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 54 | #include "net/http/http_basic_state.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 55 | #include "net/http/http_basic_stream.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 56 | #include "net/http/http_network_session.h" |
[email protected] | 87bfa3f | 2010-09-30 14:54:56 | [diff] [blame] | 57 | #include "net/http/http_network_session_peer.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 58 | #include "net/http/http_request_headers.h" |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 59 | #include "net/http/http_response_info.h" |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 60 | #include "net/http/http_server_properties_impl.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 61 | #include "net/http/http_stream.h" |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 62 | #include "net/http/http_stream_factory.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 63 | #include "net/http/http_stream_parser.h" |
[email protected] | c41737d | 2014-05-14 07:47:19 | [diff] [blame] | 64 | #include "net/http/http_transaction_test_util.h" |
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 65 | #include "net/log/net_log.h" |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 66 | #include "net/log/net_log_event_type.h" |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 67 | #include "net/log/net_log_source.h" |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 68 | #include "net/log/test_net_log.h" |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 69 | #include "net/log/test_net_log_entry.h" |
| 70 | #include "net/log/test_net_log_util.h" |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 71 | #include "net/proxy/mock_proxy_resolver.h" |
[email protected] | 51fff29d | 2008-12-19 22:17:53 | [diff] [blame] | 72 | #include "net/proxy/proxy_config_service_fixed.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 73 | #include "net/proxy/proxy_info.h" |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 74 | #include "net/proxy/proxy_resolver.h" |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 75 | #include "net/proxy/proxy_resolver_factory.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 76 | #include "net/proxy/proxy_server.h" |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 77 | #include "net/proxy/proxy_service.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 78 | #include "net/socket/client_socket_factory.h" |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 79 | #include "net/socket/client_socket_pool.h" |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 80 | #include "net/socket/client_socket_pool_manager.h" |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 81 | #include "net/socket/connection_attempts.h" |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 82 | #include "net/socket/mock_client_socket_pool_manager.h" |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 83 | #include "net/socket/next_proto.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 84 | #include "net/socket/socket_test_util.h" |
| 85 | #include "net/socket/ssl_client_socket.h" |
bnc | 8f8f7d30 | 2017-04-24 18:08:06 | [diff] [blame] | 86 | #include "net/spdy/chromium/spdy_session.h" |
| 87 | #include "net/spdy/chromium/spdy_session_pool.h" |
| 88 | #include "net/spdy/chromium/spdy_test_util_common.h" |
| 89 | #include "net/spdy/core/spdy_framer.h" |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 90 | #include "net/ssl/default_channel_id_store.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 91 | #include "net/ssl/ssl_cert_request_info.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 92 | #include "net/ssl/ssl_config_service.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 93 | #include "net/ssl/ssl_config_service_defaults.h" |
| 94 | #include "net/ssl/ssl_info.h" |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 95 | #include "net/ssl/ssl_private_key.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 96 | #include "net/test/cert_test_util.h" |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 97 | #include "net/test/gtest_util.h" |
fdoray | f33fede | 2017-05-11 21:18:10 | [diff] [blame] | 98 | #include "net/test/net_test_suite.h" |
rsleevi | a69c79a | 2016-06-22 03:28:43 | [diff] [blame] | 99 | #include "net/test/test_data_directory.h" |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 100 | #include "net/websockets/websocket_handshake_stream_base.h" |
bnc | f458840 | 2015-11-24 13:33:18 | [diff] [blame] | 101 | #include "testing/gmock/include/gmock/gmock.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 102 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 23887f04f | 2008-12-02 19:20:15 | [diff] [blame] | 103 | #include "testing/platform_test.h" |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 104 | #include "url/gurl.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 105 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 106 | using net::test::IsError; |
| 107 | using net::test::IsOk; |
| 108 | |
[email protected] | ad65a3e | 2013-12-25 18:18:01 | [diff] [blame] | 109 | using base::ASCIIToUTF16; |
| 110 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 111 | //----------------------------------------------------------------------------- |
| 112 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 113 | namespace net { |
| 114 | |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 115 | namespace { |
| 116 | |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 117 | class TestNetworkStreamThrottler : public NetworkThrottleManager { |
| 118 | public: |
| 119 | TestNetworkStreamThrottler() |
| 120 | : throttle_new_requests_(false), |
| 121 | num_set_priority_calls_(0), |
| 122 | last_priority_set_(IDLE) {} |
| 123 | |
| 124 | ~TestNetworkStreamThrottler() override { |
| 125 | EXPECT_TRUE(outstanding_throttles_.empty()); |
| 126 | } |
| 127 | |
| 128 | // NetworkThrottleManager |
| 129 | std::unique_ptr<Throttle> CreateThrottle(ThrottleDelegate* delegate, |
| 130 | RequestPriority priority, |
| 131 | bool ignore_limits) override { |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 132 | auto test_throttle = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 133 | std::make_unique<TestThrottle>(throttle_new_requests_, delegate, this); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 134 | outstanding_throttles_.insert(test_throttle.get()); |
| 135 | return std::move(test_throttle); |
| 136 | } |
| 137 | |
| 138 | void UnthrottleAllRequests() { |
| 139 | std::set<TestThrottle*> outstanding_throttles_copy(outstanding_throttles_); |
vmpstr | 6d9996c8 | 2017-02-23 00:43:25 | [diff] [blame] | 140 | for (auto* throttle : outstanding_throttles_copy) { |
rdsmith | bf8c3c1 | 2016-11-18 18:16:24 | [diff] [blame] | 141 | if (throttle->IsBlocked()) |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 142 | throttle->Unthrottle(); |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | void set_throttle_new_requests(bool throttle_new_requests) { |
| 147 | throttle_new_requests_ = throttle_new_requests; |
| 148 | } |
| 149 | |
| 150 | // Includes both throttled and unthrottled throttles. |
| 151 | size_t num_outstanding_requests() const { |
| 152 | return outstanding_throttles_.size(); |
| 153 | } |
| 154 | |
| 155 | int num_set_priority_calls() const { return num_set_priority_calls_; } |
| 156 | RequestPriority last_priority_set() const { return last_priority_set_; } |
| 157 | void set_priority_change_closure( |
| 158 | const base::Closure& priority_change_closure) { |
| 159 | priority_change_closure_ = priority_change_closure; |
| 160 | } |
| 161 | |
| 162 | private: |
| 163 | class TestThrottle : public NetworkThrottleManager::Throttle { |
| 164 | public: |
| 165 | ~TestThrottle() override { throttler_->OnThrottleDestroyed(this); } |
| 166 | |
| 167 | // Throttle |
rdsmith | bf8c3c1 | 2016-11-18 18:16:24 | [diff] [blame] | 168 | bool IsBlocked() const override { return throttled_; } |
| 169 | RequestPriority Priority() const override { |
| 170 | NOTREACHED(); |
| 171 | return IDLE; |
| 172 | } |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 173 | void SetPriority(RequestPriority priority) override { |
| 174 | throttler_->SetPriorityCalled(priority); |
| 175 | } |
| 176 | |
| 177 | TestThrottle(bool throttled, |
| 178 | ThrottleDelegate* delegate, |
| 179 | TestNetworkStreamThrottler* throttler) |
| 180 | : throttled_(throttled), delegate_(delegate), throttler_(throttler) {} |
| 181 | |
| 182 | void Unthrottle() { |
| 183 | EXPECT_TRUE(throttled_); |
| 184 | |
| 185 | throttled_ = false; |
rdsmith | bf8c3c1 | 2016-11-18 18:16:24 | [diff] [blame] | 186 | delegate_->OnThrottleUnblocked(this); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | bool throttled_; |
| 190 | ThrottleDelegate* delegate_; |
| 191 | TestNetworkStreamThrottler* throttler_; |
| 192 | }; |
| 193 | |
| 194 | void OnThrottleDestroyed(TestThrottle* throttle) { |
| 195 | EXPECT_NE(0u, outstanding_throttles_.count(throttle)); |
| 196 | outstanding_throttles_.erase(throttle); |
| 197 | } |
| 198 | |
| 199 | void SetPriorityCalled(RequestPriority priority) { |
| 200 | ++num_set_priority_calls_; |
| 201 | last_priority_set_ = priority; |
| 202 | if (!priority_change_closure_.is_null()) |
| 203 | priority_change_closure_.Run(); |
| 204 | } |
| 205 | |
| 206 | // Includes both throttled and unthrottled throttles. |
| 207 | std::set<TestThrottle*> outstanding_throttles_; |
| 208 | bool throttle_new_requests_; |
| 209 | int num_set_priority_calls_; |
| 210 | RequestPriority last_priority_set_; |
| 211 | base::Closure priority_change_closure_; |
| 212 | |
| 213 | DISALLOW_COPY_AND_ASSIGN(TestNetworkStreamThrottler); |
| 214 | }; |
| 215 | |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 216 | const base::string16 kBar(ASCIIToUTF16("bar")); |
| 217 | const base::string16 kBar2(ASCIIToUTF16("bar2")); |
| 218 | const base::string16 kBar3(ASCIIToUTF16("bar3")); |
| 219 | const base::string16 kBaz(ASCIIToUTF16("baz")); |
| 220 | const base::string16 kFirst(ASCIIToUTF16("first")); |
| 221 | const base::string16 kFoo(ASCIIToUTF16("foo")); |
| 222 | const base::string16 kFoo2(ASCIIToUTF16("foo2")); |
| 223 | const base::string16 kFoo3(ASCIIToUTF16("foo3")); |
| 224 | const base::string16 kFou(ASCIIToUTF16("fou")); |
| 225 | const base::string16 kSecond(ASCIIToUTF16("second")); |
| 226 | const base::string16 kTestingNTLM(ASCIIToUTF16("testing-ntlm")); |
| 227 | const base::string16 kWrongPassword(ASCIIToUTF16("wrongpassword")); |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 228 | |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 229 | const char kAlternativeServiceHttpHeader[] = |
| 230 | "Alt-Svc: h2=\"mail.example.org:443\"\r\n"; |
| 231 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 232 | int GetIdleSocketCountInTransportSocketPool(HttpNetworkSession* session) { |
| 233 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 234 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 235 | } |
| 236 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 237 | int GetIdleSocketCountInSSLSocketPool(HttpNetworkSession* session) { |
| 238 | return session->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 239 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 240 | } |
| 241 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 242 | bool IsTransportSocketPoolStalled(HttpNetworkSession* session) { |
| 243 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 244 | ->IsStalled(); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 245 | } |
| 246 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 247 | // Takes in a Value created from a NetLogHttpResponseParameter, and returns |
| 248 | // a JSONified list of headers as a single string. Uses single quotes instead |
| 249 | // of double quotes for easier comparison. Returns false on failure. |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 250 | bool GetHeaders(base::DictionaryValue* params, std::string* headers) { |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 251 | if (!params) |
| 252 | return false; |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 253 | base::ListValue* header_list; |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 254 | if (!params->GetList("headers", &header_list)) |
| 255 | return false; |
| 256 | std::string double_quote_headers; |
estade | 8d04646 | 2015-05-16 01:02:34 | [diff] [blame] | 257 | base::JSONWriter::Write(*header_list, &double_quote_headers); |
[email protected] | 466c986 | 2013-12-03 22:05:28 | [diff] [blame] | 258 | base::ReplaceChars(double_quote_headers, "\"", "'", headers); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 259 | return true; |
| 260 | } |
| 261 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 262 | // Tests LoadTimingInfo in the case a socket is reused and no PAC script is |
| 263 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 264 | void TestLoadTimingReused(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 265 | EXPECT_TRUE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 266 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 267 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 268 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 269 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 270 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 271 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 272 | EXPECT_FALSE(load_timing_info.send_start.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 273 | |
| 274 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 275 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 276 | // Set at a higher level. |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 277 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 278 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 279 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 280 | } |
| 281 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 282 | // Tests LoadTimingInfo in the case a new socket is used and no PAC script is |
| 283 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 284 | void TestLoadTimingNotReused(const LoadTimingInfo& load_timing_info, |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 285 | int connect_timing_flags) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 286 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 287 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 288 | |
| 289 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 290 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 291 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 292 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 293 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 294 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 295 | load_timing_info.send_start); |
| 296 | |
| 297 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 298 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 299 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 300 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 301 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 302 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | // Tests LoadTimingInfo in the case a socket is reused and a PAC script is |
| 306 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 307 | void TestLoadTimingReusedWithPac(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 308 | EXPECT_TRUE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 309 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 310 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 311 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 312 | |
| 313 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 314 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 315 | load_timing_info.proxy_resolve_end); |
| 316 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 317 | load_timing_info.send_start); |
| 318 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 319 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 320 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 321 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 322 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 323 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | // Tests LoadTimingInfo in the case a new socket is used and a PAC script is |
| 327 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 328 | void TestLoadTimingNotReusedWithPac(const LoadTimingInfo& load_timing_info, |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 329 | int connect_timing_flags) { |
| 330 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 331 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 332 | |
| 333 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 334 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 335 | load_timing_info.proxy_resolve_end); |
| 336 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 337 | load_timing_info.connect_timing.connect_start); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 338 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 339 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 340 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 341 | load_timing_info.send_start); |
| 342 | |
| 343 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 344 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 345 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 346 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 347 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 348 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 349 | } |
| 350 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 351 | void AddWebSocketHeaders(HttpRequestHeaders* headers) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 352 | headers->SetHeader("Connection", "Upgrade"); |
| 353 | headers->SetHeader("Upgrade", "websocket"); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 354 | headers->SetHeader("Origin", "http://www.example.org"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 355 | headers->SetHeader("Sec-WebSocket-Version", "13"); |
| 356 | headers->SetHeader("Sec-WebSocket-Key", "dGhlIHNhbXBsZSBub25jZQ=="); |
| 357 | } |
| 358 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 359 | std::unique_ptr<HttpNetworkSession> CreateSession( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 360 | SpdySessionDependencies* session_deps) { |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 361 | return SpdySessionDependencies::SpdyCreateSession(session_deps); |
[email protected] | e8d53619 | 2008-10-17 22:21:14 | [diff] [blame] | 362 | } |
| 363 | |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 364 | // Note that the pointer written into |*throttler| will only be valid |
| 365 | // for the lifetime of the returned HttpNetworkSession. |
| 366 | std::unique_ptr<HttpNetworkSession> CreateSessionWithThrottler( |
| 367 | SpdySessionDependencies* session_deps, |
| 368 | TestNetworkStreamThrottler** throttler) { |
| 369 | std::unique_ptr<HttpNetworkSession> session( |
| 370 | SpdySessionDependencies::SpdyCreateSession(session_deps)); |
| 371 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 372 | auto owned_throttler = std::make_unique<TestNetworkStreamThrottler>(); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 373 | *throttler = owned_throttler.get(); |
| 374 | |
| 375 | HttpNetworkSessionPeer peer(session.get()); |
| 376 | peer.SetNetworkStreamThrottler(std::move(owned_throttler)); |
| 377 | |
| 378 | return session; |
| 379 | } |
| 380 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 381 | class FailingProxyResolverFactory : public ProxyResolverFactory { |
| 382 | public: |
| 383 | FailingProxyResolverFactory() : ProxyResolverFactory(false) {} |
| 384 | |
| 385 | // ProxyResolverFactory override. |
| 386 | int CreateProxyResolver( |
| 387 | const scoped_refptr<ProxyResolverScriptData>& script_data, |
| 388 | std::unique_ptr<ProxyResolver>* result, |
| 389 | const CompletionCallback& callback, |
| 390 | std::unique_ptr<Request>* request) override { |
| 391 | return ERR_PAC_SCRIPT_FAILED; |
| 392 | } |
| 393 | }; |
| 394 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 395 | } // namespace |
| 396 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 397 | class HttpNetworkTransactionTest : public PlatformTest { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 398 | public: |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 399 | ~HttpNetworkTransactionTest() override { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 400 | // Important to restore the per-pool limit first, since the pool limit must |
| 401 | // always be greater than group limit, and the tests reduce both limits. |
| 402 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 403 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_); |
| 404 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 405 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_group_sockets_); |
| 406 | } |
| 407 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 408 | protected: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 409 | HttpNetworkTransactionTest() |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 410 | : ssl_(ASYNC, OK), |
| 411 | old_max_group_sockets_(ClientSocketPoolManager::max_sockets_per_group( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 412 | HttpNetworkSession::NORMAL_SOCKET_POOL)), |
| 413 | old_max_pool_sockets_(ClientSocketPoolManager::max_sockets_per_pool( |
| 414 | HttpNetworkSession::NORMAL_SOCKET_POOL)) { |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 415 | session_deps_.enable_http2_alternative_service = true; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 416 | } |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 417 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 418 | struct SimpleGetHelperResult { |
| 419 | int rv; |
| 420 | std::string status_line; |
| 421 | std::string response_data; |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 422 | int64_t total_received_bytes; |
| 423 | int64_t total_sent_bytes; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 424 | LoadTimingInfo load_timing_info; |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 425 | ConnectionAttempts connection_attempts; |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 426 | IPEndPoint remote_endpoint_after_start; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 427 | }; |
| 428 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 429 | void SetUp() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 430 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 431 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 432 | } |
| 433 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 434 | void TearDown() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 435 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 436 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 437 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 438 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 439 | PlatformTest::TearDown(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 440 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 441 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 442 | } |
| 443 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 444 | // Either |write_failure| specifies a write failure or |read_failure| |
| 445 | // specifies a read failure when using a reused socket. In either case, the |
| 446 | // failure should cause the network transaction to resend the request, and the |
| 447 | // other argument should be NULL. |
| 448 | void KeepAliveConnectionResendRequestTest(const MockWrite* write_failure, |
| 449 | const MockRead* read_failure); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 450 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 451 | // Either |write_failure| specifies a write failure or |read_failure| |
| 452 | // specifies a read failure when using a reused socket. In either case, the |
| 453 | // failure should cause the network transaction to resend the request, and the |
| 454 | // other argument should be NULL. |
| 455 | void PreconnectErrorResendRequestTest(const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 456 | const MockRead* read_failure, |
| 457 | bool use_spdy); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 458 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 459 | SimpleGetHelperResult SimpleGetHelperForData(StaticSocketDataProvider* data[], |
| 460 | size_t data_count) { |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 461 | SimpleGetHelperResult out; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 462 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 463 | HttpRequestInfo request; |
| 464 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 465 | request.url = GURL("http://www.example.org/"); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 466 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 467 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 468 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 469 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 470 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 471 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 472 | for (size_t i = 0; i < data_count; ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 473 | session_deps_.socket_factory->AddSocketDataProvider(data[i]); |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 474 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 475 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 476 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 477 | |
eroman | 24bc6a1 | 2015-05-06 19:55:48 | [diff] [blame] | 478 | EXPECT_TRUE(log.bound().IsCapturing()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 479 | int rv = trans.Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 480 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 481 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 482 | out.rv = callback.WaitForResult(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 483 | out.total_received_bytes = trans.GetTotalReceivedBytes(); |
| 484 | out.total_sent_bytes = trans.GetTotalSentBytes(); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 485 | |
| 486 | // Even in the failure cases that use this function, connections are always |
| 487 | // successfully established before the error. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 488 | EXPECT_TRUE(trans.GetLoadTimingInfo(&out.load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 489 | TestLoadTimingNotReused(out.load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 490 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 491 | if (out.rv != OK) |
| 492 | return out; |
| 493 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 494 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 495 | // Can't use ASSERT_* inside helper functions like this, so |
| 496 | // return an error. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 497 | if (!response || !response->headers) { |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 498 | out.rv = ERR_UNEXPECTED; |
| 499 | return out; |
| 500 | } |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 501 | out.status_line = response->headers->GetStatusLine(); |
| 502 | |
[email protected] | 80a09a8 | 2012-11-16 17:40:06 | [diff] [blame] | 503 | EXPECT_EQ("127.0.0.1", response->socket_address.host()); |
| 504 | EXPECT_EQ(80, response->socket_address.port()); |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 505 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 506 | bool got_endpoint = |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 507 | trans.GetRemoteEndpoint(&out.remote_endpoint_after_start); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 508 | EXPECT_EQ(got_endpoint, |
| 509 | out.remote_endpoint_after_start.address().size() > 0); |
| 510 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 511 | rv = ReadTransaction(&trans, &out.response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 512 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 513 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 514 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 515 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 516 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 517 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_REQUEST_HEADERS, |
| 518 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 519 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 520 | entries, pos, NetLogEventType::HTTP_TRANSACTION_READ_RESPONSE_HEADERS, |
| 521 | NetLogEventPhase::NONE); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 522 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 523 | std::string line; |
| 524 | EXPECT_TRUE(entries[pos].GetStringValue("line", &line)); |
| 525 | EXPECT_EQ("GET / HTTP/1.1\r\n", line); |
| 526 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 527 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 528 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 529 | std::string value; |
| 530 | EXPECT_TRUE(request_headers.GetHeader("Host", &value)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 531 | EXPECT_EQ("www.example.org", value); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 532 | EXPECT_TRUE(request_headers.GetHeader("Connection", &value)); |
| 533 | EXPECT_EQ("keep-alive", value); |
| 534 | |
| 535 | std::string response_headers; |
| 536 | EXPECT_TRUE(GetHeaders(entries[pos].params.get(), &response_headers)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 537 | EXPECT_EQ("['Host: www.example.org','Connection: keep-alive']", |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 538 | response_headers); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 539 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 540 | out.total_received_bytes = trans.GetTotalReceivedBytes(); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 541 | // The total number of sent bytes should not have changed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 542 | EXPECT_EQ(out.total_sent_bytes, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 543 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 544 | trans.GetConnectionAttempts(&out.connection_attempts); |
[email protected] | aecfbf2 | 2008-10-16 02:02:47 | [diff] [blame] | 545 | return out; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 546 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 547 | |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 548 | SimpleGetHelperResult SimpleGetHelper(MockRead data_reads[], |
| 549 | size_t reads_count) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 550 | MockWrite data_writes[] = { |
| 551 | MockWrite("GET / HTTP/1.1\r\n" |
| 552 | "Host: www.example.org\r\n" |
| 553 | "Connection: keep-alive\r\n\r\n"), |
| 554 | }; |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 555 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 556 | StaticSocketDataProvider reads(data_reads, reads_count, data_writes, |
| 557 | arraysize(data_writes)); |
| 558 | StaticSocketDataProvider* data[] = {&reads}; |
| 559 | SimpleGetHelperResult out = SimpleGetHelperForData(data, 1); |
| 560 | |
| 561 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
| 562 | out.total_sent_bytes); |
| 563 | return out; |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 564 | } |
| 565 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 566 | void AddSSLSocketData() { |
| 567 | ssl_.next_proto = kProtoHTTP2; |
| 568 | ssl_.cert = ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 569 | ASSERT_TRUE(ssl_.cert); |
| 570 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_); |
| 571 | } |
| 572 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 573 | void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
| 574 | int expected_status); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 575 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 576 | void ConnectStatusHelper(const MockRead& status); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 577 | |
| 578 | void BypassHostCacheOnRefreshHelper(int load_flags); |
| 579 | |
| 580 | void CheckErrorIsPassedBack(int error, IoMode mode); |
| 581 | |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 582 | SpdyTestUtil spdy_util_; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 583 | SpdySessionDependencies session_deps_; |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 584 | SSLSocketDataProvider ssl_; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 585 | |
| 586 | // Original socket limits. Some tests set these. Safest to always restore |
| 587 | // them once each test has been run. |
| 588 | int old_max_group_sockets_; |
| 589 | int old_max_pool_sockets_; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 590 | }; |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 591 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 592 | namespace { |
| 593 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 594 | class BeforeHeadersSentHandler { |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 595 | public: |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 596 | BeforeHeadersSentHandler() |
| 597 | : observed_before_headers_sent_with_proxy_(false), |
| 598 | observed_before_headers_sent_(false) {} |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 599 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 600 | void OnBeforeHeadersSent(const ProxyInfo& proxy_info, |
| 601 | HttpRequestHeaders* request_headers) { |
| 602 | observed_before_headers_sent_ = true; |
| 603 | if (!proxy_info.is_http() && !proxy_info.is_https() && |
| 604 | !proxy_info.is_quic()) { |
| 605 | return; |
| 606 | } |
| 607 | observed_before_headers_sent_with_proxy_ = true; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 608 | observed_proxy_server_uri_ = proxy_info.proxy_server().ToURI(); |
| 609 | } |
| 610 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 611 | bool observed_before_headers_sent_with_proxy() const { |
| 612 | return observed_before_headers_sent_with_proxy_; |
| 613 | } |
| 614 | |
| 615 | bool observed_before_headers_sent() const { |
| 616 | return observed_before_headers_sent_; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 617 | } |
| 618 | |
| 619 | std::string observed_proxy_server_uri() const { |
| 620 | return observed_proxy_server_uri_; |
| 621 | } |
| 622 | |
| 623 | private: |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 624 | bool observed_before_headers_sent_with_proxy_; |
| 625 | bool observed_before_headers_sent_; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 626 | std::string observed_proxy_server_uri_; |
| 627 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 628 | DISALLOW_COPY_AND_ASSIGN(BeforeHeadersSentHandler); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 629 | }; |
| 630 | |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 631 | // Fill |str| with a long header list that consumes >= |size| bytes. |
| 632 | void FillLargeHeadersString(std::string* str, int size) { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 633 | const char row[] = |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 634 | "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"; |
| 635 | const int sizeof_row = strlen(row); |
| 636 | const int num_rows = static_cast<int>( |
| 637 | ceil(static_cast<float>(size) / sizeof_row)); |
| 638 | const int sizeof_data = num_rows * sizeof_row; |
| 639 | DCHECK(sizeof_data >= size); |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 640 | str->reserve(sizeof_data); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 641 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 642 | for (int i = 0; i < num_rows; ++i) |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 643 | str->append(row, sizeof_row); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 644 | } |
| 645 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 646 | #if defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 647 | // Alternative functions that eliminate randomness and dependency on the local |
| 648 | // host name so that the generated NTLM messages are reproducible. |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 649 | void MockGenerateRandom1(uint8_t* output, size_t n) { |
| 650 | static const uint8_t bytes[] = {0x55, 0x29, 0x66, 0x26, |
| 651 | 0x6b, 0x9c, 0x73, 0x54}; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 652 | static size_t current_byte = 0; |
| 653 | for (size_t i = 0; i < n; ++i) { |
| 654 | output[i] = bytes[current_byte++]; |
| 655 | current_byte %= arraysize(bytes); |
| 656 | } |
| 657 | } |
| 658 | |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 659 | void MockGenerateRandom2(uint8_t* output, size_t n) { |
| 660 | static const uint8_t bytes[] = {0x96, 0x79, 0x85, 0xe7, 0x49, 0x93, |
| 661 | 0x70, 0xa1, 0x4e, 0xe7, 0x87, 0x45, |
| 662 | 0x31, 0x5b, 0xd3, 0x1f}; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 663 | static size_t current_byte = 0; |
| 664 | for (size_t i = 0; i < n; ++i) { |
| 665 | output[i] = bytes[current_byte++]; |
| 666 | current_byte %= arraysize(bytes); |
| 667 | } |
| 668 | } |
| 669 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 670 | std::string MockGetHostName() { |
| 671 | return "WTC-WIN7"; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 672 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 673 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 674 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 675 | template<typename ParentPool> |
| 676 | class CaptureGroupNameSocketPool : public ParentPool { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 677 | public: |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 678 | CaptureGroupNameSocketPool(HostResolver* host_resolver, |
| 679 | CertVerifier* cert_verifier); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 680 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 681 | const std::string last_group_name_received() const { |
| 682 | return last_group_name_; |
| 683 | } |
| 684 | |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 685 | int RequestSocket(const std::string& group_name, |
| 686 | const void* socket_params, |
| 687 | RequestPriority priority, |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 688 | ClientSocketPool::RespectLimits respect_limits, |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 689 | ClientSocketHandle* handle, |
| 690 | const CompletionCallback& callback, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 691 | const NetLogWithSource& net_log) override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 692 | last_group_name_ = group_name; |
| 693 | return ERR_IO_PENDING; |
| 694 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 695 | void CancelRequest(const std::string& group_name, |
| 696 | ClientSocketHandle* handle) override {} |
| 697 | void ReleaseSocket(const std::string& group_name, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 698 | std::unique_ptr<StreamSocket> socket, |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 699 | int id) override {} |
| 700 | void CloseIdleSockets() override {} |
xunjieli | 92feb33 | 2017-03-03 17:19:23 | [diff] [blame] | 701 | void CloseIdleSocketsInGroup(const std::string& group_name) override {} |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 702 | int IdleSocketCount() const override { return 0; } |
| 703 | int IdleSocketCountInGroup(const std::string& group_name) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 704 | return 0; |
| 705 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 706 | LoadState GetLoadState(const std::string& group_name, |
| 707 | const ClientSocketHandle* handle) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 708 | return LOAD_STATE_IDLE; |
| 709 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 710 | base::TimeDelta ConnectionTimeout() const override { |
[email protected] | a796bcec | 2010-03-22 17:17:26 | [diff] [blame] | 711 | return base::TimeDelta(); |
| 712 | } |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 713 | |
| 714 | private: |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 715 | std::string last_group_name_; |
| 716 | }; |
| 717 | |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 718 | typedef CaptureGroupNameSocketPool<TransportClientSocketPool> |
| 719 | CaptureGroupNameTransportSocketPool; |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 720 | typedef CaptureGroupNameSocketPool<HttpProxyClientSocketPool> |
| 721 | CaptureGroupNameHttpProxySocketPool; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 722 | typedef CaptureGroupNameSocketPool<SOCKSClientSocketPool> |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 723 | CaptureGroupNameSOCKSSocketPool; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 724 | typedef CaptureGroupNameSocketPool<SSLClientSocketPool> |
| 725 | CaptureGroupNameSSLSocketPool; |
| 726 | |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 727 | template <typename ParentPool> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 728 | CaptureGroupNameSocketPool<ParentPool>::CaptureGroupNameSocketPool( |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 729 | HostResolver* host_resolver, |
| 730 | CertVerifier* /* cert_verifier */) |
tbansal | 7b403bcc | 2016-04-13 22:33:21 | [diff] [blame] | 731 | : ParentPool(0, 0, host_resolver, NULL, NULL, NULL) {} |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 732 | |
hashimoto | 0d3e4fb | 2015-01-09 05:02:50 | [diff] [blame] | 733 | template <> |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 734 | CaptureGroupNameHttpProxySocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 735 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 736 | CertVerifier* /* cert_verifier */) |
tbansal | 16196a1e | 2017-06-09 01:50:09 | [diff] [blame] | 737 | : HttpProxyClientSocketPool(0, 0, NULL, NULL, NULL, NULL) {} |
[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 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 868 | std::make_unique<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 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 891 | std::make_unique<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( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 1340 | std::make_unique<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 | |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1683 | // Test that we do not retry indefinitely when a server sends an error like |
| 1684 | // ERR_SPDY_PING_FAILED, ERR_SPDY_SERVER_REFUSED_STREAM, |
| 1685 | // ERR_QUIC_HANDSHAKE_FAILED or ERR_QUIC_PROTOCOL_ERROR. |
| 1686 | TEST_F(HttpNetworkTransactionTest, FiniteRetriesOnIOError) { |
| 1687 | HttpRequestInfo request; |
| 1688 | request.method = "GET"; |
| 1689 | request.url = GURL("https://www.foo.com/"); |
| 1690 | |
| 1691 | // Check whether we give up after the third try. |
| 1692 | |
| 1693 | // Construct an HTTP2 request and a "Go away" response. |
| 1694 | SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
| 1695 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
| 1696 | SpdySerializedFrame spdy_response_go_away(spdy_util_.ConstructSpdyGoAway()); |
| 1697 | MockRead data_read1 = CreateMockRead(spdy_response_go_away); |
| 1698 | MockWrite data_write = CreateMockWrite(spdy_request, 0); |
| 1699 | |
| 1700 | // Three go away responses. |
| 1701 | StaticSocketDataProvider data1(&data_read1, 1, &data_write, 1); |
| 1702 | StaticSocketDataProvider data2(&data_read1, 1, &data_write, 1); |
| 1703 | StaticSocketDataProvider data3(&data_read1, 1, &data_write, 1); |
| 1704 | |
| 1705 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1706 | AddSSLSocketData(); |
| 1707 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1708 | AddSSLSocketData(); |
| 1709 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 1710 | AddSSLSocketData(); |
| 1711 | |
| 1712 | TestCompletionCallback callback; |
| 1713 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1714 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1715 | |
| 1716 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1717 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1718 | |
| 1719 | rv = callback.WaitForResult(); |
| 1720 | EXPECT_THAT(rv, IsError(ERR_SPDY_SERVER_REFUSED_STREAM)); |
| 1721 | } |
| 1722 | |
| 1723 | TEST_F(HttpNetworkTransactionTest, RetryTwiceOnIOError) { |
| 1724 | HttpRequestInfo request; |
| 1725 | request.method = "GET"; |
| 1726 | request.url = GURL("https://www.foo.com/"); |
| 1727 | |
| 1728 | // Check whether we try atleast thrice before giving up. |
| 1729 | |
| 1730 | // Construct an HTTP2 request and a "Go away" response. |
| 1731 | SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
| 1732 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
| 1733 | SpdySerializedFrame spdy_response_go_away(spdy_util_.ConstructSpdyGoAway()); |
| 1734 | MockRead data_read1 = CreateMockRead(spdy_response_go_away); |
| 1735 | MockWrite data_write = CreateMockWrite(spdy_request, 0); |
| 1736 | |
| 1737 | // Construct a non error HTTP2 response. |
| 1738 | SpdySerializedFrame spdy_response_no_error( |
| 1739 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 1740 | SpdySerializedFrame spdy_data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 1741 | MockRead data_read2[] = {CreateMockRead(spdy_response_no_error, 1), |
| 1742 | CreateMockRead(spdy_data, 2)}; |
| 1743 | |
| 1744 | // Two error responses. |
| 1745 | StaticSocketDataProvider data1(&data_read1, 1, &data_write, 1); |
| 1746 | StaticSocketDataProvider data2(&data_read1, 1, &data_write, 1); |
| 1747 | // Followed by a success response. |
| 1748 | SequencedSocketData data3(data_read2, 2, &data_write, 1); |
| 1749 | |
| 1750 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1751 | AddSSLSocketData(); |
| 1752 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1753 | AddSSLSocketData(); |
| 1754 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 1755 | AddSSLSocketData(); |
| 1756 | |
| 1757 | TestCompletionCallback callback; |
| 1758 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1759 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1760 | |
| 1761 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1762 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1763 | |
| 1764 | rv = callback.WaitForResult(); |
| 1765 | EXPECT_THAT(rv, IsOk()); |
| 1766 | } |
| 1767 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1768 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionNotConnectedOnWrite) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1769 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1770 | KeepAliveConnectionResendRequestTest(&write_failure, NULL); |
| 1771 | } |
| 1772 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1773 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionReset) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1774 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1775 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1776 | } |
| 1777 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1778 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1779 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1780 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1781 | } |
| 1782 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1783 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1784 | // if the socket was a reused keep alive socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1785 | TEST_F(HttpNetworkTransactionTest, KeepAlive408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1786 | MockRead read_failure(SYNCHRONOUS, |
| 1787 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1788 | "Connection: Keep-Alive\r\n" |
| 1789 | "Content-Length: 6\r\n\r\n" |
| 1790 | "Pickle"); |
| 1791 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1792 | } |
| 1793 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1794 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorNotConnectedOnWrite) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1795 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1796 | PreconnectErrorResendRequestTest(&write_failure, NULL, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1797 | } |
| 1798 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1799 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorReset) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1800 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1801 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1802 | } |
| 1803 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1804 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorEOF) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1805 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1806 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1807 | } |
| 1808 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1809 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1810 | MockRead read_failure(ASYNC, OK); // EOF |
| 1811 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1812 | } |
| 1813 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1814 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1815 | // if the socket was a preconnected (UNUSED_IDLE) socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1816 | TEST_F(HttpNetworkTransactionTest, RetryOnIdle408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1817 | MockRead read_failure(SYNCHRONOUS, |
| 1818 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1819 | "Connection: Keep-Alive\r\n" |
| 1820 | "Content-Length: 6\r\n\r\n" |
| 1821 | "Pickle"); |
| 1822 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1823 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1824 | } |
| 1825 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1826 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorNotConnectedOnWrite) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1827 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
| 1828 | PreconnectErrorResendRequestTest(&write_failure, NULL, true); |
| 1829 | } |
| 1830 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1831 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorReset) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1832 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
| 1833 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1834 | } |
| 1835 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1836 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1837 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
| 1838 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1839 | } |
| 1840 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1841 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1842 | MockRead read_failure(ASYNC, OK); // EOF |
| 1843 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1844 | } |
| 1845 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1846 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1847 | HttpRequestInfo request; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1848 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1849 | request.url = GURL("http://www.example.org/"); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1850 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1851 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1852 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1853 | |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1854 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1855 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1856 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1857 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1858 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1859 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1860 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1861 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1862 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1863 | TestCompletionCallback callback; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1864 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1865 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1866 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1867 | |
| 1868 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1869 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 1870 | |
| 1871 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1872 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 1873 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1874 | } |
| 1875 | |
| 1876 | // What do various browsers do when the server closes a non-keepalive |
| 1877 | // connection without sending any response header or body? |
| 1878 | // |
| 1879 | // IE7: error page |
| 1880 | // Safari 3.1.2 (Windows): error page |
| 1881 | // Firefox 3.0.1: blank page |
| 1882 | // Opera 9.52: after five attempts, blank page |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1883 | // Us with WinHTTP: error page (ERR_INVALID_RESPONSE) |
| 1884 | // Us: error page (EMPTY_RESPONSE) |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1885 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionEOF) { |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1886 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1887 | MockRead(SYNCHRONOUS, OK), // EOF |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1888 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1889 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1890 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1891 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 1892 | SimpleGetHelperResult out = SimpleGetHelper(data_reads, |
| 1893 | arraysize(data_reads)); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1894 | EXPECT_THAT(out.rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1895 | } |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1896 | |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1897 | // Next 2 cases (KeepAliveEarlyClose and KeepAliveEarlyClose2) are regression |
| 1898 | // tests. There was a bug causing HttpNetworkTransaction to hang in the |
| 1899 | // destructor in such situations. |
| 1900 | // See http://crbug.com/154712 and http://crbug.com/156609. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1901 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1902 | HttpRequestInfo request; |
| 1903 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1904 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1905 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1906 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 1907 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 1908 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1909 | |
| 1910 | MockRead data_reads[] = { |
| 1911 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1912 | MockRead("Connection: keep-alive\r\n"), |
| 1913 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1914 | MockRead("hello"), |
| 1915 | MockRead(SYNCHRONOUS, 0), |
| 1916 | }; |
| 1917 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1918 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1919 | |
| 1920 | TestCompletionCallback callback; |
| 1921 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1922 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1923 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1924 | |
| 1925 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1926 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1927 | |
| 1928 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1929 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1930 | if (rv == ERR_IO_PENDING) |
| 1931 | rv = callback.WaitForResult(); |
| 1932 | EXPECT_EQ(5, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1933 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1934 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1935 | |
| 1936 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 1937 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1938 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1939 | } |
| 1940 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1941 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose2) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1942 | HttpRequestInfo request; |
| 1943 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1944 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1945 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1946 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 1947 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 1948 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1949 | |
| 1950 | MockRead data_reads[] = { |
| 1951 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1952 | MockRead("Connection: keep-alive\r\n"), |
| 1953 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1954 | MockRead(SYNCHRONOUS, 0), |
| 1955 | }; |
| 1956 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1957 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1958 | |
| 1959 | TestCompletionCallback callback; |
| 1960 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1961 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1962 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1963 | |
| 1964 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1965 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1966 | |
| 1967 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1968 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1969 | if (rv == ERR_IO_PENDING) |
| 1970 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1971 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1972 | |
| 1973 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 1974 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1975 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1976 | } |
| 1977 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1978 | // Test that we correctly reuse a keep-alive connection after not explicitly |
| 1979 | // reading the body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1980 | TEST_F(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) { |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1981 | HttpRequestInfo request; |
| 1982 | request.method = "GET"; |
| 1983 | request.url = GURL("http://www.foo.com/"); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1984 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1985 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1986 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1987 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1988 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1989 | const char* request_data = |
| 1990 | "GET / HTTP/1.1\r\n" |
| 1991 | "Host: www.foo.com\r\n" |
| 1992 | "Connection: keep-alive\r\n\r\n"; |
| 1993 | MockWrite data_writes[] = { |
| 1994 | MockWrite(ASYNC, 0, request_data), MockWrite(ASYNC, 2, request_data), |
| 1995 | MockWrite(ASYNC, 4, request_data), MockWrite(ASYNC, 6, request_data), |
| 1996 | MockWrite(ASYNC, 8, request_data), MockWrite(ASYNC, 10, request_data), |
| 1997 | MockWrite(ASYNC, 12, request_data), MockWrite(ASYNC, 14, request_data), |
| 1998 | MockWrite(ASYNC, 17, request_data), MockWrite(ASYNC, 20, request_data), |
| 1999 | }; |
| 2000 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2001 | // Note that because all these reads happen in the same |
| 2002 | // StaticSocketDataProvider, it shows that the same socket is being reused for |
| 2003 | // all transactions. |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2004 | MockRead data_reads[] = { |
| 2005 | MockRead(ASYNC, 1, "HTTP/1.1 204 No Content\r\n\r\n"), |
| 2006 | MockRead(ASYNC, 3, "HTTP/1.1 205 Reset Content\r\n\r\n"), |
| 2007 | MockRead(ASYNC, 5, "HTTP/1.1 304 Not Modified\r\n\r\n"), |
| 2008 | MockRead(ASYNC, 7, |
| 2009 | "HTTP/1.1 302 Found\r\n" |
| 2010 | "Content-Length: 0\r\n\r\n"), |
| 2011 | MockRead(ASYNC, 9, |
| 2012 | "HTTP/1.1 302 Found\r\n" |
| 2013 | "Content-Length: 5\r\n\r\n" |
| 2014 | "hello"), |
| 2015 | MockRead(ASYNC, 11, |
| 2016 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 2017 | "Content-Length: 0\r\n\r\n"), |
| 2018 | MockRead(ASYNC, 13, |
| 2019 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 2020 | "Content-Length: 5\r\n\r\n" |
| 2021 | "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2022 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2023 | // In the next two rounds, IsConnectedAndIdle returns false, due to |
| 2024 | // the set_busy_before_sync_reads(true) call, while the |
| 2025 | // HttpNetworkTransaction is being shut down, but the socket is still |
| 2026 | // reuseable. See http://crbug.com/544255. |
| 2027 | MockRead(ASYNC, 15, |
| 2028 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 2029 | "Content-Length: 5\r\n\r\n"), |
| 2030 | MockRead(SYNCHRONOUS, 16, "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2031 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2032 | MockRead(ASYNC, 18, |
| 2033 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 2034 | "Content-Length: 5\r\n\r\n" |
| 2035 | "he"), |
| 2036 | MockRead(SYNCHRONOUS, 19, "llo"), |
| 2037 | |
| 2038 | // The body of the final request is actually read. |
| 2039 | MockRead(ASYNC, 21, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 2040 | MockRead(ASYNC, 22, "hello"), |
| 2041 | }; |
| 2042 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 2043 | arraysize(data_writes)); |
| 2044 | data.set_busy_before_sync_reads(true); |
| 2045 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 2046 | |
| 2047 | const int kNumUnreadBodies = arraysize(data_writes) - 1; |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2048 | std::string response_lines[kNumUnreadBodies]; |
| 2049 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 2050 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2051 | for (size_t i = 0; i < kNumUnreadBodies; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2052 | TestCompletionCallback callback; |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2053 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2054 | auto trans = std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2055 | session.get()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2056 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2057 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2058 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2059 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2060 | LoadTimingInfo load_timing_info; |
| 2061 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2062 | if (i == 0) { |
| 2063 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2064 | first_socket_log_id = load_timing_info.socket_log_id; |
| 2065 | } else { |
| 2066 | TestLoadTimingReused(load_timing_info); |
| 2067 | EXPECT_EQ(first_socket_log_id, load_timing_info.socket_log_id); |
| 2068 | } |
| 2069 | |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2070 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2071 | ASSERT_TRUE(response); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2072 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2073 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2074 | response_lines[i] = response->headers->GetStatusLine(); |
| 2075 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2076 | // Delete the transaction without reading the response bodies. Then spin |
| 2077 | // the message loop, so the response bodies are drained. |
| 2078 | trans.reset(); |
| 2079 | base::RunLoop().RunUntilIdle(); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2080 | } |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2081 | |
| 2082 | const char* const kStatusLines[] = { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2083 | "HTTP/1.1 204 No Content", |
| 2084 | "HTTP/1.1 205 Reset Content", |
| 2085 | "HTTP/1.1 304 Not Modified", |
| 2086 | "HTTP/1.1 302 Found", |
| 2087 | "HTTP/1.1 302 Found", |
| 2088 | "HTTP/1.1 301 Moved Permanently", |
| 2089 | "HTTP/1.1 301 Moved Permanently", |
| 2090 | "HTTP/1.1 200 Hunky-Dory", |
| 2091 | "HTTP/1.1 200 Hunky-Dory", |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2092 | }; |
| 2093 | |
mostynb | 91e0da98 | 2015-01-20 19:17:27 | [diff] [blame] | 2094 | static_assert(kNumUnreadBodies == arraysize(kStatusLines), |
| 2095 | "forgot to update kStatusLines"); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2096 | |
| 2097 | for (int i = 0; i < kNumUnreadBodies; ++i) |
| 2098 | EXPECT_EQ(kStatusLines[i], response_lines[i]); |
| 2099 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2100 | TestCompletionCallback callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2101 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2102 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2103 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2104 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2105 | ASSERT_TRUE(response); |
| 2106 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2107 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 2108 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2109 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2110 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2111 | EXPECT_EQ("hello", response_data); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2112 | } |
| 2113 | |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2114 | // Sockets that receive extra data after a response is complete should not be |
| 2115 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2116 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData1) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2117 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2118 | MockWrite data_writes1[] = { |
| 2119 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 2120 | "Host: www.borked.com\r\n" |
| 2121 | "Connection: keep-alive\r\n\r\n"), |
| 2122 | }; |
| 2123 | |
| 2124 | MockRead data_reads1[] = { |
| 2125 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2126 | "Connection: keep-alive\r\n" |
| 2127 | "Content-Length: 22\r\n\r\n" |
| 2128 | "This server is borked."), |
| 2129 | }; |
| 2130 | |
| 2131 | MockWrite data_writes2[] = { |
| 2132 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2133 | "Host: www.borked.com\r\n" |
| 2134 | "Connection: keep-alive\r\n\r\n"), |
| 2135 | }; |
| 2136 | |
| 2137 | MockRead data_reads2[] = { |
| 2138 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2139 | "Content-Length: 3\r\n\r\n" |
| 2140 | "foo"), |
| 2141 | }; |
| 2142 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2143 | data_writes1, arraysize(data_writes1)); |
| 2144 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2145 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2146 | data_writes2, arraysize(data_writes2)); |
| 2147 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2148 | |
| 2149 | TestCompletionCallback callback; |
| 2150 | HttpRequestInfo request1; |
| 2151 | request1.method = "HEAD"; |
| 2152 | request1.url = GURL("http://www.borked.com/"); |
| 2153 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2154 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2155 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2156 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2157 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2158 | |
| 2159 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2160 | ASSERT_TRUE(response1); |
| 2161 | ASSERT_TRUE(response1->headers); |
| 2162 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2163 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2164 | |
| 2165 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2166 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2167 | EXPECT_EQ("", response_data1); |
| 2168 | // Deleting the transaction attempts to release the socket back into the |
| 2169 | // socket pool. |
| 2170 | trans1.reset(); |
| 2171 | |
| 2172 | HttpRequestInfo request2; |
| 2173 | request2.method = "GET"; |
| 2174 | request2.url = GURL("http://www.borked.com/foo"); |
| 2175 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2176 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2177 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2178 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2179 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2180 | |
| 2181 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2182 | ASSERT_TRUE(response2); |
| 2183 | ASSERT_TRUE(response2->headers); |
| 2184 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2185 | |
| 2186 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2187 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2188 | EXPECT_EQ("foo", response_data2); |
| 2189 | } |
| 2190 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2191 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData2) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2192 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2193 | MockWrite data_writes1[] = { |
| 2194 | MockWrite("GET / HTTP/1.1\r\n" |
| 2195 | "Host: www.borked.com\r\n" |
| 2196 | "Connection: keep-alive\r\n\r\n"), |
| 2197 | }; |
| 2198 | |
| 2199 | MockRead data_reads1[] = { |
| 2200 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2201 | "Connection: keep-alive\r\n" |
| 2202 | "Content-Length: 22\r\n\r\n" |
| 2203 | "This server is borked." |
| 2204 | "Bonus data!"), |
| 2205 | }; |
| 2206 | |
| 2207 | MockWrite data_writes2[] = { |
| 2208 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2209 | "Host: www.borked.com\r\n" |
| 2210 | "Connection: keep-alive\r\n\r\n"), |
| 2211 | }; |
| 2212 | |
| 2213 | MockRead data_reads2[] = { |
| 2214 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2215 | "Content-Length: 3\r\n\r\n" |
| 2216 | "foo"), |
| 2217 | }; |
| 2218 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2219 | data_writes1, arraysize(data_writes1)); |
| 2220 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2221 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2222 | data_writes2, arraysize(data_writes2)); |
| 2223 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2224 | |
| 2225 | TestCompletionCallback callback; |
| 2226 | HttpRequestInfo request1; |
| 2227 | request1.method = "GET"; |
| 2228 | request1.url = GURL("http://www.borked.com/"); |
| 2229 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2230 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2231 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2232 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2233 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2234 | |
| 2235 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2236 | ASSERT_TRUE(response1); |
| 2237 | ASSERT_TRUE(response1->headers); |
| 2238 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2239 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2240 | |
| 2241 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2242 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2243 | EXPECT_EQ("This server is borked.", response_data1); |
| 2244 | // Deleting the transaction attempts to release the socket back into the |
| 2245 | // socket pool. |
| 2246 | trans1.reset(); |
| 2247 | |
| 2248 | HttpRequestInfo request2; |
| 2249 | request2.method = "GET"; |
| 2250 | request2.url = GURL("http://www.borked.com/foo"); |
| 2251 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2252 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2253 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2254 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2255 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2256 | |
| 2257 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2258 | ASSERT_TRUE(response2); |
| 2259 | ASSERT_TRUE(response2->headers); |
| 2260 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2261 | |
| 2262 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2263 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2264 | EXPECT_EQ("foo", response_data2); |
| 2265 | } |
| 2266 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2267 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData3) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2268 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2269 | MockWrite data_writes1[] = { |
| 2270 | MockWrite("GET / HTTP/1.1\r\n" |
| 2271 | "Host: www.borked.com\r\n" |
| 2272 | "Connection: keep-alive\r\n\r\n"), |
| 2273 | }; |
| 2274 | |
| 2275 | MockRead data_reads1[] = { |
| 2276 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2277 | "Connection: keep-alive\r\n" |
| 2278 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2279 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2280 | MockRead("0\r\n\r\nBonus data!"), |
| 2281 | }; |
| 2282 | |
| 2283 | MockWrite data_writes2[] = { |
| 2284 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2285 | "Host: www.borked.com\r\n" |
| 2286 | "Connection: keep-alive\r\n\r\n"), |
| 2287 | }; |
| 2288 | |
| 2289 | MockRead data_reads2[] = { |
| 2290 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2291 | "Content-Length: 3\r\n\r\n" |
| 2292 | "foo"), |
| 2293 | }; |
| 2294 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2295 | data_writes1, arraysize(data_writes1)); |
| 2296 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2297 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2298 | data_writes2, arraysize(data_writes2)); |
| 2299 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2300 | |
| 2301 | TestCompletionCallback callback; |
| 2302 | HttpRequestInfo request1; |
| 2303 | request1.method = "GET"; |
| 2304 | request1.url = GURL("http://www.borked.com/"); |
| 2305 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2306 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2307 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2308 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2309 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2310 | |
| 2311 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2312 | ASSERT_TRUE(response1); |
| 2313 | ASSERT_TRUE(response1->headers); |
| 2314 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2315 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2316 | |
| 2317 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2318 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2319 | EXPECT_EQ("This server is borked.", response_data1); |
| 2320 | // Deleting the transaction attempts to release the socket back into the |
| 2321 | // socket pool. |
| 2322 | trans1.reset(); |
| 2323 | |
| 2324 | HttpRequestInfo request2; |
| 2325 | request2.method = "GET"; |
| 2326 | request2.url = GURL("http://www.borked.com/foo"); |
| 2327 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2328 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2329 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2330 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2331 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2332 | |
| 2333 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2334 | ASSERT_TRUE(response2); |
| 2335 | ASSERT_TRUE(response2->headers); |
| 2336 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2337 | |
| 2338 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2339 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2340 | EXPECT_EQ("foo", response_data2); |
| 2341 | } |
| 2342 | |
| 2343 | // This is a little different from the others - it tests the case that the |
| 2344 | // HttpStreamParser doesn't know if there's extra data on a socket or not when |
| 2345 | // the HttpNetworkTransaction is torn down, because the response body hasn't |
| 2346 | // been read from yet, but the request goes through the HttpResponseBodyDrainer. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2347 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData4) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2348 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2349 | MockWrite data_writes1[] = { |
| 2350 | MockWrite("GET / HTTP/1.1\r\n" |
| 2351 | "Host: www.borked.com\r\n" |
| 2352 | "Connection: keep-alive\r\n\r\n"), |
| 2353 | }; |
| 2354 | |
| 2355 | MockRead data_reads1[] = { |
| 2356 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2357 | "Connection: keep-alive\r\n" |
| 2358 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2359 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2360 | MockRead("0\r\n\r\nBonus data!"), |
| 2361 | }; |
| 2362 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2363 | data_writes1, arraysize(data_writes1)); |
| 2364 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2365 | |
| 2366 | TestCompletionCallback callback; |
| 2367 | HttpRequestInfo request1; |
| 2368 | request1.method = "GET"; |
| 2369 | request1.url = GURL("http://www.borked.com/"); |
| 2370 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2371 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2372 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2373 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2374 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2375 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2376 | const HttpResponseInfo* response1 = trans->GetResponseInfo(); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2377 | ASSERT_TRUE(response1); |
| 2378 | ASSERT_TRUE(response1->headers); |
| 2379 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2380 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2381 | |
| 2382 | // Deleting the transaction creates an HttpResponseBodyDrainer to read the |
| 2383 | // response body. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2384 | trans.reset(); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2385 | |
| 2386 | // Let the HttpResponseBodyDrainer drain the socket. It should determine the |
| 2387 | // socket can't be reused, rather than returning it to the socket pool. |
| 2388 | base::RunLoop().RunUntilIdle(); |
| 2389 | |
| 2390 | // There should be no idle sockets in the pool. |
| 2391 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2392 | } |
| 2393 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2394 | // Test the request-challenge-retry sequence for basic auth. |
| 2395 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2396 | TEST_F(HttpNetworkTransactionTest, BasicAuth) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2397 | HttpRequestInfo request; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2398 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2399 | request.url = GURL("http://www.example.org/"); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2400 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2401 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2402 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2403 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2404 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2405 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2406 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2407 | MockWrite( |
| 2408 | "GET / HTTP/1.1\r\n" |
| 2409 | "Host: www.example.org\r\n" |
| 2410 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2411 | }; |
| 2412 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2413 | MockRead data_reads1[] = { |
| 2414 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2415 | // Give a couple authenticate options (only the middle one is actually |
| 2416 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 2417 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2418 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2419 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2420 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2421 | // Large content-length -- won't matter, as connection will be reset. |
| 2422 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2423 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2424 | }; |
| 2425 | |
| 2426 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2427 | // be issuing -- the final header line contains the credentials. |
| 2428 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2429 | MockWrite( |
| 2430 | "GET / HTTP/1.1\r\n" |
| 2431 | "Host: www.example.org\r\n" |
| 2432 | "Connection: keep-alive\r\n" |
| 2433 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2434 | }; |
| 2435 | |
| 2436 | // Lastly, the server responds with the actual content. |
| 2437 | MockRead data_reads2[] = { |
| 2438 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2439 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2440 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2441 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2442 | }; |
| 2443 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2444 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2445 | data_writes1, arraysize(data_writes1)); |
| 2446 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2447 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2448 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2449 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2450 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2451 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2452 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2453 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2454 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2455 | |
| 2456 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2457 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2458 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2459 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2460 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2461 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2462 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2463 | int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2464 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2465 | int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2466 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2467 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2468 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2469 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2470 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2471 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2472 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2473 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2474 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2475 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2476 | |
| 2477 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2478 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2479 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2480 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2481 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2482 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2483 | // The load timing after restart should have a new socket ID, and times after |
| 2484 | // those of the first load timing. |
| 2485 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2486 | load_timing_info2.connect_timing.connect_start); |
| 2487 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2488 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2489 | int64_t writes_size2 = CountWriteBytes(data_writes2, arraysize(data_writes2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2490 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2491 | int64_t reads_size2 = CountReadBytes(data_reads2, arraysize(data_reads2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2492 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2493 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2494 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2495 | ASSERT_TRUE(response); |
| 2496 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2497 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2498 | } |
| 2499 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2500 | // Test the request-challenge-retry sequence for basic auth. |
| 2501 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2502 | TEST_F(HttpNetworkTransactionTest, BasicAuthWithAddressChange) { |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2503 | HttpRequestInfo request; |
| 2504 | request.method = "GET"; |
| 2505 | request.url = GURL("http://www.example.org/"); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2506 | |
| 2507 | TestNetLog log; |
| 2508 | MockHostResolver* resolver = new MockHostResolver(); |
| 2509 | session_deps_.net_log = &log; |
| 2510 | session_deps_.host_resolver.reset(resolver); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2511 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2512 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2513 | |
| 2514 | resolver->rules()->ClearRules(); |
| 2515 | resolver->rules()->AddRule("www.example.org", "127.0.0.1"); |
| 2516 | |
| 2517 | MockWrite data_writes1[] = { |
| 2518 | MockWrite("GET / HTTP/1.1\r\n" |
| 2519 | "Host: www.example.org\r\n" |
| 2520 | "Connection: keep-alive\r\n\r\n"), |
| 2521 | }; |
| 2522 | |
| 2523 | MockRead data_reads1[] = { |
| 2524 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2525 | // Give a couple authenticate options (only the middle one is actually |
| 2526 | // supported). |
| 2527 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 2528 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2529 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2530 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2531 | // Large content-length -- won't matter, as connection will be reset. |
| 2532 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 2533 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 2534 | }; |
| 2535 | |
| 2536 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2537 | // be issuing -- the final header line contains the credentials. |
| 2538 | MockWrite data_writes2[] = { |
| 2539 | MockWrite("GET / HTTP/1.1\r\n" |
| 2540 | "Host: www.example.org\r\n" |
| 2541 | "Connection: keep-alive\r\n" |
| 2542 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2543 | }; |
| 2544 | |
| 2545 | // Lastly, the server responds with the actual content. |
| 2546 | MockRead data_reads2[] = { |
| 2547 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2548 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2549 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, OK), |
| 2550 | }; |
| 2551 | |
| 2552 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2553 | data_writes1, arraysize(data_writes1)); |
| 2554 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2555 | data_writes2, arraysize(data_writes2)); |
| 2556 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2557 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2558 | |
| 2559 | TestCompletionCallback callback1; |
| 2560 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2561 | EXPECT_EQ(OK, callback1.GetResult(trans.Start(&request, callback1.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2562 | NetLogWithSource()))); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2563 | |
| 2564 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2565 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2566 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2567 | |
| 2568 | int64_t writes_size1 = CountWriteBytes(data_writes1, arraysize(data_writes1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2569 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2570 | int64_t reads_size1 = CountReadBytes(data_reads1, arraysize(data_reads1)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2571 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2572 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2573 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2574 | ASSERT_TRUE(response); |
| 2575 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 2576 | |
| 2577 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2578 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2579 | ASSERT_FALSE(endpoint.address().empty()); |
| 2580 | EXPECT_EQ("127.0.0.1:80", endpoint.ToString()); |
| 2581 | |
| 2582 | resolver->rules()->ClearRules(); |
| 2583 | resolver->rules()->AddRule("www.example.org", "127.0.0.2"); |
| 2584 | |
| 2585 | TestCompletionCallback callback2; |
| 2586 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2587 | EXPECT_EQ(OK, callback2.GetResult(trans.RestartWithAuth( |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2588 | AuthCredentials(kFoo, kBar), callback2.callback()))); |
| 2589 | |
| 2590 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2591 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2592 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2593 | // The load timing after restart should have a new socket ID, and times after |
| 2594 | // those of the first load timing. |
| 2595 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2596 | load_timing_info2.connect_timing.connect_start); |
| 2597 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2598 | |
| 2599 | int64_t writes_size2 = CountWriteBytes(data_writes2, arraysize(data_writes2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2600 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2601 | int64_t reads_size2 = CountReadBytes(data_reads2, arraysize(data_reads2)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2602 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2603 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2604 | response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2605 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2606 | EXPECT_FALSE(response->auth_challenge); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2607 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 2608 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2609 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2610 | ASSERT_FALSE(endpoint.address().empty()); |
| 2611 | EXPECT_EQ("127.0.0.2:80", endpoint.ToString()); |
| 2612 | } |
| 2613 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2614 | TEST_F(HttpNetworkTransactionTest, DoNotSendAuth) { |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2615 | HttpRequestInfo request; |
| 2616 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2617 | request.url = GURL("http://www.example.org/"); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2618 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2619 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2620 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2621 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2622 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2623 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2624 | MockWrite( |
| 2625 | "GET / HTTP/1.1\r\n" |
| 2626 | "Host: www.example.org\r\n" |
| 2627 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2628 | }; |
| 2629 | |
| 2630 | MockRead data_reads[] = { |
| 2631 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2632 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2633 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2634 | // Large content-length -- won't matter, as connection will be reset. |
| 2635 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2636 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2637 | }; |
| 2638 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2639 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 2640 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2641 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2642 | TestCompletionCallback callback; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2643 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2644 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2645 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2646 | |
| 2647 | rv = callback.WaitForResult(); |
| 2648 | EXPECT_EQ(0, rv); |
| 2649 | |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2650 | int64_t writes_size = CountWriteBytes(data_writes, arraysize(data_writes)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2651 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 2652 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2653 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2654 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2655 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2656 | ASSERT_TRUE(response); |
| 2657 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2658 | } |
| 2659 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2660 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2661 | // connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2662 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAlive) { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2663 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 2664 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 2665 | // reused. See http://crbug.com/544255. |
| 2666 | for (int i = 0; i < 2; ++i) { |
| 2667 | HttpRequestInfo request; |
| 2668 | request.method = "GET"; |
| 2669 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2670 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2671 | TestNetLog log; |
| 2672 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2673 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2674 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2675 | MockWrite data_writes[] = { |
| 2676 | MockWrite(ASYNC, 0, |
| 2677 | "GET / HTTP/1.1\r\n" |
| 2678 | "Host: www.example.org\r\n" |
| 2679 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2680 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2681 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2682 | // be issuing -- the final header line contains the credentials. |
| 2683 | MockWrite(ASYNC, 6, |
| 2684 | "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"), |
| 2688 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2689 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2690 | MockRead data_reads[] = { |
| 2691 | MockRead(ASYNC, 1, "HTTP/1.1 401 Unauthorized\r\n"), |
| 2692 | MockRead(ASYNC, 2, "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2693 | MockRead(ASYNC, 3, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2694 | MockRead(ASYNC, 4, "Content-Length: 14\r\n\r\n"), |
| 2695 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 5, "Unauthorized\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2696 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2697 | // Lastly, the server responds with the actual content. |
| 2698 | MockRead(ASYNC, 7, "HTTP/1.1 200 OK\r\n"), |
| 2699 | MockRead(ASYNC, 8, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2700 | MockRead(ASYNC, 9, "Content-Length: 5\r\n\r\n"), |
| 2701 | MockRead(ASYNC, 10, "Hello"), |
| 2702 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2703 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2704 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 2705 | arraysize(data_writes)); |
| 2706 | data.set_busy_before_sync_reads(true); |
| 2707 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2708 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2709 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2710 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2711 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2712 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2713 | ASSERT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2714 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2715 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2716 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2717 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2718 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2719 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2720 | ASSERT_TRUE(response); |
| 2721 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2722 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2723 | TestCompletionCallback callback2; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2724 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2725 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 2726 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2727 | ASSERT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2728 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2729 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2730 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2731 | TestLoadTimingReused(load_timing_info2); |
| 2732 | // The load timing after restart should have the same socket ID, and times |
| 2733 | // those of the first load timing. |
| 2734 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2735 | load_timing_info2.send_start); |
| 2736 | 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] | 2737 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2738 | response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2739 | ASSERT_TRUE(response); |
| 2740 | EXPECT_FALSE(response->auth_challenge); |
| 2741 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2742 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2743 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2744 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2745 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2746 | int64_t writes_size = CountWriteBytes(data_writes, arraysize(data_writes)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2747 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2748 | int64_t reads_size = CountReadBytes(data_reads, arraysize(data_reads)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2749 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2750 | } |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2751 | } |
| 2752 | |
| 2753 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2754 | // connection and with no response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2755 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2756 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2757 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2758 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2759 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2760 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2761 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2762 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2763 | MockWrite("GET / HTTP/1.1\r\n" |
| 2764 | "Host: www.example.org\r\n" |
| 2765 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2766 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2767 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2768 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2769 | MockWrite("GET / HTTP/1.1\r\n" |
| 2770 | "Host: www.example.org\r\n" |
| 2771 | "Connection: keep-alive\r\n" |
| 2772 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2773 | }; |
| 2774 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2775 | MockRead data_reads1[] = { |
| 2776 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2777 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2778 | MockRead("Content-Length: 0\r\n\r\n"), // No response body. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2779 | |
| 2780 | // Lastly, the server responds with the actual content. |
| 2781 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2782 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2783 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2784 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2785 | }; |
| 2786 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2787 | // An incorrect reconnect would cause this to be read. |
| 2788 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2789 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2790 | }; |
| 2791 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2792 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2793 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2794 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2795 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2796 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2797 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2798 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2799 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2800 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2801 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2802 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2803 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2804 | |
| 2805 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2806 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2807 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2808 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2809 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2810 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2811 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2812 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2813 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2814 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2815 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2816 | |
| 2817 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2818 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2819 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2820 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2821 | ASSERT_TRUE(response); |
| 2822 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2823 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2824 | } |
| 2825 | |
| 2826 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2827 | // connection and with a large response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2828 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2829 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2830 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2831 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2832 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2833 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2834 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2835 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2836 | MockWrite("GET / HTTP/1.1\r\n" |
| 2837 | "Host: www.example.org\r\n" |
| 2838 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2839 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2840 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2841 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2842 | MockWrite("GET / HTTP/1.1\r\n" |
| 2843 | "Host: www.example.org\r\n" |
| 2844 | "Connection: keep-alive\r\n" |
| 2845 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2846 | }; |
| 2847 | |
| 2848 | // Respond with 5 kb of response body. |
| 2849 | std::string large_body_string("Unauthorized"); |
| 2850 | large_body_string.append(5 * 1024, ' '); |
| 2851 | large_body_string.append("\r\n"); |
| 2852 | |
| 2853 | MockRead data_reads1[] = { |
| 2854 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2855 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2856 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2857 | // 5134 = 12 + 5 * 1024 + 2 |
| 2858 | MockRead("Content-Length: 5134\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2859 | MockRead(ASYNC, large_body_string.data(), large_body_string.size()), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2860 | |
| 2861 | // Lastly, the server responds with the actual content. |
| 2862 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2863 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2864 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2865 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2866 | }; |
| 2867 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2868 | // An incorrect reconnect would cause this to be read. |
| 2869 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2870 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2871 | }; |
| 2872 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2873 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2874 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2875 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2876 | NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2877 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2878 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2879 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2880 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2881 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2882 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2883 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2884 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2885 | |
| 2886 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2887 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2888 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2889 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2890 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2891 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2892 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2893 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2894 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2895 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2896 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2897 | |
| 2898 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2899 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2900 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2901 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2902 | ASSERT_TRUE(response); |
| 2903 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2904 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2905 | } |
| 2906 | |
| 2907 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2908 | // connection, but the server gets impatient and closes the connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2909 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) { |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2910 | HttpRequestInfo request; |
| 2911 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2912 | request.url = GURL("http://www.example.org/"); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2913 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2914 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2915 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2916 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2917 | MockWrite( |
| 2918 | "GET / HTTP/1.1\r\n" |
| 2919 | "Host: www.example.org\r\n" |
| 2920 | "Connection: keep-alive\r\n\r\n"), |
| 2921 | // This simulates the seemingly successful write to a closed connection |
| 2922 | // if the bug is not fixed. |
| 2923 | MockWrite( |
| 2924 | "GET / HTTP/1.1\r\n" |
| 2925 | "Host: www.example.org\r\n" |
| 2926 | "Connection: keep-alive\r\n" |
| 2927 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2928 | }; |
| 2929 | |
| 2930 | MockRead data_reads1[] = { |
| 2931 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2932 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2933 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2934 | MockRead("Content-Length: 14\r\n\r\n"), |
| 2935 | // Tell MockTCPClientSocket to simulate the server closing the connection. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2936 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2937 | MockRead("Unauthorized\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2938 | MockRead(SYNCHRONOUS, OK), // The server closes the connection. |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2939 | }; |
| 2940 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2941 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2942 | // be issuing -- the final header line contains the credentials. |
| 2943 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2944 | MockWrite( |
| 2945 | "GET / HTTP/1.1\r\n" |
| 2946 | "Host: www.example.org\r\n" |
| 2947 | "Connection: keep-alive\r\n" |
| 2948 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2949 | }; |
| 2950 | |
| 2951 | // Lastly, the server responds with the actual content. |
| 2952 | MockRead data_reads2[] = { |
| 2953 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2954 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2955 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2956 | MockRead("hello"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2957 | }; |
| 2958 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 2959 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 2960 | data_writes1, arraysize(data_writes1)); |
| 2961 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 2962 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2963 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2964 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2965 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2966 | TestCompletionCallback callback1; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2967 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2968 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2969 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2970 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2971 | |
| 2972 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2973 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2974 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2975 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2976 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2977 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2978 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2979 | TestCompletionCallback callback2; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2980 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2981 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2982 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2983 | |
| 2984 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2985 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2986 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2987 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2988 | ASSERT_TRUE(response); |
| 2989 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2990 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2991 | } |
| 2992 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 2993 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 2994 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2995 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp10) { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2996 | HttpRequestInfo request; |
| 2997 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2998 | request.url = GURL("https://www.example.org/"); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 2999 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3000 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3001 | |
| 3002 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3003 | session_deps_.proxy_service = |
| 3004 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3005 | BoundTestNetLog log; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3006 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3007 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3008 | |
| 3009 | // Since we have proxy, should try to establish tunnel. |
| 3010 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3011 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3012 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3013 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3014 | }; |
| 3015 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3016 | // The proxy responds to the connect with a 407, using a non-persistent |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3017 | // connection. |
| 3018 | MockRead data_reads1[] = { |
| 3019 | // No credentials. |
| 3020 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 3021 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3022 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3023 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3024 | // Since the first connection couldn't be reused, need to establish another |
| 3025 | // once given credentials. |
| 3026 | MockWrite data_writes2[] = { |
| 3027 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3028 | // be issuing -- the final header line contains the credentials. |
| 3029 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3030 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3031 | "Proxy-Connection: keep-alive\r\n" |
| 3032 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3033 | |
| 3034 | MockWrite("GET / HTTP/1.1\r\n" |
| 3035 | "Host: www.example.org\r\n" |
| 3036 | "Connection: keep-alive\r\n\r\n"), |
| 3037 | }; |
| 3038 | |
| 3039 | MockRead data_reads2[] = { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3040 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3041 | |
| 3042 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3043 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3044 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3045 | MockRead(SYNCHRONOUS, "hello"), |
| 3046 | }; |
| 3047 | |
| 3048 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3049 | data_writes1, arraysize(data_writes1)); |
| 3050 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3051 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3052 | data_writes2, arraysize(data_writes2)); |
| 3053 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3054 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3055 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3056 | |
| 3057 | TestCompletionCallback callback1; |
| 3058 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3059 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3060 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3061 | |
| 3062 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3063 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3064 | |
| 3065 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3066 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3067 | TestNetLogEntry::List entries; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3068 | log.GetEntries(&entries); |
| 3069 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3070 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3071 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3072 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3073 | entries, pos, |
| 3074 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3075 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3076 | |
| 3077 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3078 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3079 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3080 | ASSERT_TRUE(response->headers); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3081 | EXPECT_EQ(407, response->headers->response_code()); |
| 3082 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3083 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3084 | |
| 3085 | LoadTimingInfo load_timing_info; |
| 3086 | // CONNECT requests and responses are handled at the connect job level, so |
| 3087 | // the transaction does not yet have a connection. |
| 3088 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3089 | |
| 3090 | TestCompletionCallback callback2; |
| 3091 | |
| 3092 | rv = |
| 3093 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3094 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3095 | |
| 3096 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3097 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3098 | |
| 3099 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3100 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3101 | |
| 3102 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3103 | EXPECT_EQ(200, response->headers->response_code()); |
| 3104 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 3105 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3106 | |
| 3107 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3108 | EXPECT_FALSE(response->auth_challenge); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3109 | |
| 3110 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3111 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3112 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3113 | |
| 3114 | trans.reset(); |
| 3115 | session->CloseAllConnections(); |
| 3116 | } |
| 3117 | |
| 3118 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 3119 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3120 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp11) { |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3121 | HttpRequestInfo request; |
| 3122 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3123 | request.url = GURL("https://www.example.org/"); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3124 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3125 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3126 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3127 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3128 | session_deps_.proxy_service = |
| 3129 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3130 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3131 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3132 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3133 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3134 | // Since we have proxy, should try to establish tunnel. |
| 3135 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3136 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3137 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3138 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3139 | }; |
| 3140 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3141 | // The proxy responds to the connect with a 407, using a non-persistent |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3142 | // connection. |
| 3143 | MockRead data_reads1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3144 | // No credentials. |
| 3145 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3146 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3147 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3148 | }; |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3149 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3150 | MockWrite data_writes2[] = { |
| 3151 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3152 | // be issuing -- the final header line contains the credentials. |
| 3153 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3154 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3155 | "Proxy-Connection: keep-alive\r\n" |
| 3156 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3157 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3158 | MockWrite("GET / HTTP/1.1\r\n" |
| 3159 | "Host: www.example.org\r\n" |
| 3160 | "Connection: keep-alive\r\n\r\n"), |
| 3161 | }; |
| 3162 | |
| 3163 | MockRead data_reads2[] = { |
| 3164 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3165 | |
| 3166 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3167 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3168 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3169 | MockRead(SYNCHRONOUS, "hello"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3170 | }; |
| 3171 | |
| 3172 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3173 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3174 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3175 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3176 | data_writes2, arraysize(data_writes2)); |
| 3177 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3178 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3179 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3180 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3181 | TestCompletionCallback callback1; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3182 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3183 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3184 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3185 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3186 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3187 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3188 | |
| 3189 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3190 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3191 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3192 | log.GetEntries(&entries); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3193 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3194 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3195 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3196 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3197 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3198 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3199 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3200 | |
| 3201 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3202 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3203 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3204 | ASSERT_TRUE(response->headers); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3205 | EXPECT_EQ(407, response->headers->response_code()); |
| 3206 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3207 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3208 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3209 | LoadTimingInfo load_timing_info; |
| 3210 | // CONNECT requests and responses are handled at the connect job level, so |
| 3211 | // the transaction does not yet have a connection. |
| 3212 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3213 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3214 | TestCompletionCallback callback2; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3215 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3216 | rv = trans->RestartWithAuth( |
| 3217 | AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3218 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3219 | |
| 3220 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3221 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3222 | |
| 3223 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3224 | ASSERT_TRUE(response); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3225 | |
| 3226 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3227 | EXPECT_EQ(200, response->headers->response_code()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3228 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3229 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3230 | |
| 3231 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3232 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3233 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3234 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3235 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3236 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3237 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3238 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3239 | session->CloseAllConnections(); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3240 | } |
| 3241 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3242 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3243 | // proxy connection with HTTP/1.0 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3244 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp10) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3245 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3246 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3247 | // reused. See http://crbug.com/544255. |
| 3248 | for (int i = 0; i < 2; ++i) { |
| 3249 | HttpRequestInfo request; |
| 3250 | request.method = "GET"; |
| 3251 | request.url = GURL("https://www.example.org/"); |
| 3252 | // Ensure that proxy authentication is attempted even |
| 3253 | // when the no authentication data flag is set. |
| 3254 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3255 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3256 | // Configure against proxy server "myproxy:70". |
| 3257 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
| 3258 | BoundTestNetLog log; |
| 3259 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3260 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3261 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3262 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3263 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3264 | // Since we have proxy, should try to establish tunnel. |
| 3265 | MockWrite data_writes1[] = { |
| 3266 | MockWrite(ASYNC, 0, |
| 3267 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3268 | "Host: www.example.org:443\r\n" |
| 3269 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3270 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3271 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3272 | // be issuing -- the final header line contains the credentials. |
| 3273 | MockWrite(ASYNC, 3, |
| 3274 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3275 | "Host: www.example.org:443\r\n" |
| 3276 | "Proxy-Connection: keep-alive\r\n" |
| 3277 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3278 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3279 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3280 | // The proxy responds to the connect with a 407, using a persistent |
| 3281 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3282 | MockRead data_reads1[] = { |
| 3283 | // No credentials. |
| 3284 | MockRead(ASYNC, 1, |
| 3285 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3286 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3287 | "Proxy-Connection: keep-alive\r\n" |
| 3288 | "Content-Length: 10\r\n\r\n"), |
| 3289 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3290 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3291 | // Wrong credentials (wrong password). |
| 3292 | MockRead(ASYNC, 4, |
| 3293 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3294 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3295 | "Proxy-Connection: keep-alive\r\n" |
| 3296 | "Content-Length: 10\r\n\r\n"), |
| 3297 | // No response body because the test stops reading here. |
| 3298 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3299 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3300 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3301 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3302 | arraysize(data_writes1)); |
| 3303 | data1.set_busy_before_sync_reads(true); |
| 3304 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3305 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3306 | TestCompletionCallback callback1; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3307 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3308 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3309 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3310 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3311 | TestNetLogEntry::List entries; |
| 3312 | log.GetEntries(&entries); |
| 3313 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3314 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3315 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3316 | ExpectLogContainsSomewhere( |
| 3317 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3318 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3319 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3320 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3321 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3322 | ASSERT_TRUE(response); |
| 3323 | ASSERT_TRUE(response->headers); |
| 3324 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3325 | EXPECT_EQ(407, response->headers->response_code()); |
| 3326 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3327 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3328 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3329 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3330 | TestCompletionCallback callback2; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3331 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3332 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3333 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3334 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3335 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3336 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3337 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3338 | ASSERT_TRUE(response); |
| 3339 | ASSERT_TRUE(response->headers); |
| 3340 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3341 | EXPECT_EQ(407, response->headers->response_code()); |
| 3342 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3343 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3344 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3345 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3346 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3347 | // out of scope. |
| 3348 | session->CloseAllConnections(); |
| 3349 | } |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3350 | } |
| 3351 | |
| 3352 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3353 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3354 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp11) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3355 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3356 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3357 | // reused. See http://crbug.com/544255. |
| 3358 | for (int i = 0; i < 2; ++i) { |
| 3359 | HttpRequestInfo request; |
| 3360 | request.method = "GET"; |
| 3361 | request.url = GURL("https://www.example.org/"); |
| 3362 | // Ensure that proxy authentication is attempted even |
| 3363 | // when the no authentication data flag is set. |
| 3364 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
| 3365 | |
| 3366 | // Configure against proxy server "myproxy:70". |
| 3367 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
| 3368 | BoundTestNetLog log; |
| 3369 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3370 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3371 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3372 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3373 | |
| 3374 | // Since we have proxy, should try to establish tunnel. |
| 3375 | MockWrite data_writes1[] = { |
| 3376 | MockWrite(ASYNC, 0, |
| 3377 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3378 | "Host: www.example.org:443\r\n" |
| 3379 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3380 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3381 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3382 | // be issuing -- the final header line contains the credentials. |
| 3383 | MockWrite(ASYNC, 3, |
| 3384 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3385 | "Host: www.example.org:443\r\n" |
| 3386 | "Proxy-Connection: keep-alive\r\n" |
| 3387 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3388 | }; |
| 3389 | |
| 3390 | // The proxy responds to the connect with a 407, using a persistent |
| 3391 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3392 | MockRead data_reads1[] = { |
| 3393 | // No credentials. |
| 3394 | MockRead(ASYNC, 1, |
| 3395 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3396 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3397 | "Content-Length: 10\r\n\r\n"), |
| 3398 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
| 3399 | |
| 3400 | // Wrong credentials (wrong password). |
| 3401 | MockRead(ASYNC, 4, |
| 3402 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3403 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3404 | "Content-Length: 10\r\n\r\n"), |
| 3405 | // No response body because the test stops reading here. |
| 3406 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3407 | }; |
| 3408 | |
| 3409 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3410 | arraysize(data_writes1)); |
| 3411 | data1.set_busy_before_sync_reads(true); |
| 3412 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3413 | |
| 3414 | TestCompletionCallback callback1; |
| 3415 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3416 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3417 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3418 | |
| 3419 | TestNetLogEntry::List entries; |
| 3420 | log.GetEntries(&entries); |
| 3421 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3422 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3423 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3424 | ExpectLogContainsSomewhere( |
| 3425 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3426 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3427 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3428 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3429 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3430 | ASSERT_TRUE(response); |
| 3431 | ASSERT_TRUE(response->headers); |
| 3432 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3433 | EXPECT_EQ(407, response->headers->response_code()); |
| 3434 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3435 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3436 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3437 | |
| 3438 | TestCompletionCallback callback2; |
| 3439 | |
| 3440 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3441 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3442 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3443 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3444 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3445 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3446 | ASSERT_TRUE(response); |
| 3447 | ASSERT_TRUE(response->headers); |
| 3448 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3449 | EXPECT_EQ(407, response->headers->response_code()); |
| 3450 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3451 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3452 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3453 | |
| 3454 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3455 | // out of scope. |
| 3456 | session->CloseAllConnections(); |
| 3457 | } |
| 3458 | } |
| 3459 | |
| 3460 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3461 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel, in |
| 3462 | // the case the server sends extra data on the original socket, so it can't be |
| 3463 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3464 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveExtraData) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3465 | HttpRequestInfo request; |
| 3466 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3467 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3468 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3469 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3470 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3471 | // Configure against proxy server "myproxy:70". |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3472 | session_deps_.proxy_service = |
| 3473 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3474 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3475 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3476 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3477 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3478 | // Since we have proxy, should try to establish tunnel. |
| 3479 | MockWrite data_writes1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3480 | MockWrite(ASYNC, 0, |
| 3481 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3482 | "Host: www.example.org:443\r\n" |
| 3483 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3484 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3485 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3486 | // The proxy responds to the connect with a 407, using a persistent, but sends |
| 3487 | // extra data, so the socket cannot be reused. |
| 3488 | MockRead data_reads1[] = { |
| 3489 | // No credentials. |
| 3490 | MockRead(ASYNC, 1, |
| 3491 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3492 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3493 | "Content-Length: 10\r\n\r\n"), |
| 3494 | MockRead(SYNCHRONOUS, 2, "0123456789"), |
| 3495 | MockRead(SYNCHRONOUS, 3, "I'm broken!"), |
| 3496 | }; |
| 3497 | |
| 3498 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3499 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3500 | // be issuing -- the final header line contains the credentials. |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3501 | MockWrite(ASYNC, 0, |
| 3502 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3503 | "Host: www.example.org:443\r\n" |
| 3504 | "Proxy-Connection: keep-alive\r\n" |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3505 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3506 | |
| 3507 | MockWrite(ASYNC, 2, |
| 3508 | "GET / HTTP/1.1\r\n" |
| 3509 | "Host: www.example.org\r\n" |
| 3510 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3511 | }; |
| 3512 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3513 | MockRead data_reads2[] = { |
| 3514 | MockRead(ASYNC, 1, "HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3515 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3516 | MockRead(ASYNC, 3, |
| 3517 | "HTTP/1.1 200 OK\r\n" |
| 3518 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 3519 | "Content-Length: 5\r\n\r\n"), |
| 3520 | // No response body because the test stops reading here. |
| 3521 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 4), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3522 | }; |
| 3523 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3524 | SequencedSocketData data1(data_reads1, arraysize(data_reads1), data_writes1, |
| 3525 | arraysize(data_writes1)); |
| 3526 | data1.set_busy_before_sync_reads(true); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3527 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3528 | SequencedSocketData data2(data_reads2, arraysize(data_reads2), data_writes2, |
| 3529 | arraysize(data_writes2)); |
| 3530 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3531 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3532 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3533 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3534 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3535 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3536 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3537 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3538 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3539 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3540 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3541 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3542 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3543 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3544 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3545 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3546 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3547 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3548 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3549 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3550 | NetLogEventPhase::NONE); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3551 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3552 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3553 | ASSERT_TRUE(response); |
| 3554 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3555 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3556 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3557 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3558 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3559 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3560 | LoadTimingInfo load_timing_info; |
| 3561 | // CONNECT requests and responses are handled at the connect job level, so |
| 3562 | // the transaction does not yet have a connection. |
| 3563 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3564 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3565 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3566 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3567 | rv = |
| 3568 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3569 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3570 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3571 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3572 | EXPECT_EQ(200, response->headers->response_code()); |
| 3573 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3574 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 3575 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3576 | // The password prompt info should not be set. |
| 3577 | EXPECT_FALSE(response->auth_challenge); |
| 3578 | |
| 3579 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3580 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3581 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3582 | |
| 3583 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3584 | session->CloseAllConnections(); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3585 | } |
| 3586 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3587 | // Test the case a proxy closes a socket while the challenge body is being |
| 3588 | // drained. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3589 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHangupDuringBody) { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3590 | HttpRequestInfo request; |
| 3591 | request.method = "GET"; |
| 3592 | request.url = GURL("https://www.example.org/"); |
| 3593 | // Ensure that proxy authentication is attempted even |
| 3594 | // when the no authentication data flag is set. |
| 3595 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
| 3596 | |
| 3597 | // Configure against proxy server "myproxy:70". |
| 3598 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3599 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3600 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3601 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3602 | |
| 3603 | // Since we have proxy, should try to establish tunnel. |
| 3604 | MockWrite data_writes1[] = { |
| 3605 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3606 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3607 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3608 | }; |
| 3609 | |
| 3610 | // The proxy responds to the connect with a 407, using a persistent |
| 3611 | // connection. |
| 3612 | MockRead data_reads1[] = { |
| 3613 | // No credentials. |
| 3614 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3615 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3616 | MockRead("Content-Length: 10\r\n\r\n"), MockRead("spam!"), |
| 3617 | // Server hands up in the middle of the body. |
| 3618 | MockRead(ASYNC, ERR_CONNECTION_CLOSED), |
| 3619 | }; |
| 3620 | |
| 3621 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3622 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3623 | // be issuing -- the final header line contains the credentials. |
| 3624 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3625 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3626 | "Proxy-Connection: keep-alive\r\n" |
| 3627 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3628 | |
| 3629 | MockWrite("GET / HTTP/1.1\r\n" |
| 3630 | "Host: www.example.org\r\n" |
| 3631 | "Connection: keep-alive\r\n\r\n"), |
| 3632 | }; |
| 3633 | |
| 3634 | MockRead data_reads2[] = { |
| 3635 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3636 | |
| 3637 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3638 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3639 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3640 | MockRead(SYNCHRONOUS, "hello"), |
| 3641 | }; |
| 3642 | |
| 3643 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3644 | data_writes1, arraysize(data_writes1)); |
| 3645 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3646 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3647 | data_writes2, arraysize(data_writes2)); |
| 3648 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3649 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3650 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3651 | |
| 3652 | TestCompletionCallback callback; |
| 3653 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3654 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3655 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3656 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3657 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3658 | ASSERT_TRUE(response); |
| 3659 | ASSERT_TRUE(response->headers); |
| 3660 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3661 | EXPECT_EQ(407, response->headers->response_code()); |
| 3662 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3663 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3664 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3665 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3666 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3667 | response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3668 | ASSERT_TRUE(response); |
| 3669 | ASSERT_TRUE(response->headers); |
| 3670 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3671 | EXPECT_EQ(200, response->headers->response_code()); |
| 3672 | std::string body; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3673 | EXPECT_THAT(ReadTransaction(&trans, &body), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3674 | EXPECT_EQ("hello", body); |
| 3675 | } |
| 3676 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3677 | // Test that we don't read the response body when we fail to establish a tunnel, |
| 3678 | // even if the user cancels the proxy's auth attempt. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3679 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3680 | HttpRequestInfo request; |
| 3681 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3682 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3683 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3684 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3685 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3686 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3687 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3688 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3689 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3690 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3691 | // Since we have proxy, should try to establish tunnel. |
| 3692 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3693 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3694 | "Host: www.example.org:443\r\n" |
| 3695 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3696 | }; |
| 3697 | |
| 3698 | // The proxy responds to the connect with a 407. |
| 3699 | MockRead data_reads[] = { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3700 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3701 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3702 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3703 | MockRead("0123456789"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3704 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3705 | }; |
| 3706 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 3707 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 3708 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3709 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3710 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3711 | TestCompletionCallback callback; |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3712 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3713 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3714 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3715 | |
| 3716 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3717 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3718 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3719 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3720 | ASSERT_TRUE(response); |
| 3721 | ASSERT_TRUE(response->headers); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3722 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3723 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3724 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3725 | |
| 3726 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3727 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3728 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 3729 | |
| 3730 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3731 | session->CloseAllConnections(); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3732 | } |
| 3733 | |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3734 | // Test that we don't pass extraneous headers from the proxy's response to the |
| 3735 | // caller when the proxy responds to CONNECT with 407. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3736 | TEST_F(HttpNetworkTransactionTest, SanitizeProxyAuthHeaders) { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3737 | HttpRequestInfo request; |
| 3738 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3739 | request.url = GURL("https://www.example.org/"); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3740 | |
| 3741 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3742 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3743 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3744 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3745 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3746 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3747 | |
| 3748 | // Since we have proxy, should try to establish tunnel. |
| 3749 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3750 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3751 | "Host: www.example.org:443\r\n" |
| 3752 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3753 | }; |
| 3754 | |
| 3755 | // The proxy responds to the connect with a 407. |
| 3756 | MockRead data_reads[] = { |
| 3757 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3758 | MockRead("X-Foo: bar\r\n"), |
| 3759 | MockRead("Set-Cookie: foo=bar\r\n"), |
| 3760 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3761 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3762 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3763 | }; |
| 3764 | |
| 3765 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 3766 | arraysize(data_writes)); |
| 3767 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 3768 | |
| 3769 | TestCompletionCallback callback; |
| 3770 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3771 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3772 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3773 | |
| 3774 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3775 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3776 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3777 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3778 | ASSERT_TRUE(response); |
| 3779 | ASSERT_TRUE(response->headers); |
| 3780 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3781 | EXPECT_EQ(407, response->headers->response_code()); |
| 3782 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3783 | EXPECT_FALSE(response->headers->HasHeader("X-Foo")); |
| 3784 | EXPECT_FALSE(response->headers->HasHeader("Set-Cookie")); |
| 3785 | |
| 3786 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3787 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3788 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3789 | |
| 3790 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
| 3791 | session->CloseAllConnections(); |
| 3792 | } |
| 3793 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3794 | // Test when a server (non-proxy) returns a 407 (proxy-authenticate). |
| 3795 | // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3796 | TEST_F(HttpNetworkTransactionTest, UnexpectedProxyAuth) { |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3797 | HttpRequestInfo request; |
| 3798 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3799 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3800 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3801 | // We are using a DIRECT connection (i.e. no proxy) for this session. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3802 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3803 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3804 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3805 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3806 | MockWrite( |
| 3807 | "GET / HTTP/1.1\r\n" |
| 3808 | "Host: www.example.org\r\n" |
| 3809 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3810 | }; |
| 3811 | |
| 3812 | MockRead data_reads1[] = { |
| 3813 | MockRead("HTTP/1.0 407 Proxy Auth required\r\n"), |
| 3814 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3815 | // Large content-length -- won't matter, as connection will be reset. |
| 3816 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3817 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3818 | }; |
| 3819 | |
| 3820 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3821 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3822 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3823 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3824 | TestCompletionCallback callback; |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3825 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3826 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3827 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3828 | |
| 3829 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3830 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3831 | } |
| 3832 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3833 | // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) |
| 3834 | // through a non-authenticating proxy. The request should fail with |
| 3835 | // ERR_UNEXPECTED_PROXY_AUTH. |
| 3836 | // Note that it is impossible to detect if an HTTP server returns a 407 through |
| 3837 | // a non-authenticating proxy - there is nothing to indicate whether the |
| 3838 | // response came from the proxy or the server, so it is treated as if the proxy |
| 3839 | // issued the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3840 | TEST_F(HttpNetworkTransactionTest, HttpsServerRequestsProxyAuthThroughProxy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3841 | HttpRequestInfo request; |
| 3842 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3843 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3844 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 3845 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3846 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3847 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3848 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3849 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3850 | // Since we have proxy, should try to establish tunnel. |
| 3851 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3852 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3853 | "Host: www.example.org:443\r\n" |
| 3854 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3855 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3856 | MockWrite("GET / HTTP/1.1\r\n" |
| 3857 | "Host: www.example.org\r\n" |
| 3858 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3859 | }; |
| 3860 | |
| 3861 | MockRead data_reads1[] = { |
| 3862 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3863 | |
| 3864 | MockRead("HTTP/1.1 407 Unauthorized\r\n"), |
| 3865 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3866 | MockRead("\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3867 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3868 | }; |
| 3869 | |
| 3870 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3871 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3872 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3873 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3874 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3875 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3876 | TestCompletionCallback callback1; |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3877 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3878 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3879 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3880 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3881 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3882 | |
| 3883 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3884 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3885 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3886 | log.GetEntries(&entries); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3887 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3888 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3889 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3890 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3891 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3892 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3893 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3894 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3895 | |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3896 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 3897 | // that uses non-persistent connections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3898 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3899 | AuthAllowsDefaultCredentialsTunnelConnectionClose) { |
| 3900 | HttpRequestInfo request; |
| 3901 | request.method = "GET"; |
| 3902 | request.url = GURL("https://www.example.org/"); |
| 3903 | |
| 3904 | // Configure against proxy server "myproxy:70". |
| 3905 | session_deps_.proxy_service = |
| 3906 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 3907 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3908 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3909 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3910 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3911 | mock_handler->set_allows_default_credentials(true); |
| 3912 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3913 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 3914 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3915 | |
| 3916 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 3917 | NetLog net_log; |
| 3918 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3919 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3920 | |
| 3921 | // Since we have proxy, should try to establish tunnel. |
| 3922 | MockWrite data_writes1[] = { |
| 3923 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3924 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3925 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3926 | }; |
| 3927 | |
| 3928 | // The proxy responds to the connect with a 407, using a non-persistent |
| 3929 | // connection. |
| 3930 | MockRead data_reads1[] = { |
| 3931 | // No credentials. |
| 3932 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3933 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 3934 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3935 | }; |
| 3936 | |
| 3937 | // Since the first connection couldn't be reused, need to establish another |
| 3938 | // once given credentials. |
| 3939 | MockWrite data_writes2[] = { |
| 3940 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3941 | // be issuing -- the final header line contains the credentials. |
| 3942 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3943 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3944 | "Proxy-Connection: keep-alive\r\n" |
| 3945 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 3946 | |
| 3947 | MockWrite("GET / HTTP/1.1\r\n" |
| 3948 | "Host: www.example.org\r\n" |
| 3949 | "Connection: keep-alive\r\n\r\n"), |
| 3950 | }; |
| 3951 | |
| 3952 | MockRead data_reads2[] = { |
| 3953 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3954 | |
| 3955 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3956 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3957 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3958 | MockRead(SYNCHRONOUS, "hello"), |
| 3959 | }; |
| 3960 | |
| 3961 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 3962 | data_writes1, arraysize(data_writes1)); |
| 3963 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3964 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 3965 | data_writes2, arraysize(data_writes2)); |
| 3966 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3967 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3968 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3969 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3970 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3971 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3972 | |
| 3973 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3974 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3975 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3976 | |
| 3977 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 3978 | ASSERT_TRUE(response); |
| 3979 | ASSERT_TRUE(response->headers); |
| 3980 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
| 3981 | EXPECT_EQ(407, response->headers->response_code()); |
| 3982 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3983 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3984 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3985 | |
| 3986 | LoadTimingInfo load_timing_info; |
| 3987 | // CONNECT requests and responses are handled at the connect job level, so |
| 3988 | // the transaction does not yet have a connection. |
| 3989 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3990 | |
| 3991 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3992 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3993 | response = trans->GetResponseInfo(); |
| 3994 | ASSERT_TRUE(response); |
| 3995 | ASSERT_TRUE(response->headers); |
| 3996 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3997 | EXPECT_EQ(200, response->headers->response_code()); |
| 3998 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 3999 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4000 | |
| 4001 | // The password prompt info should not be set. |
| 4002 | EXPECT_FALSE(response->auth_challenge); |
| 4003 | |
| 4004 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4005 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4006 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4007 | |
| 4008 | trans.reset(); |
| 4009 | session->CloseAllConnections(); |
| 4010 | } |
| 4011 | |
| 4012 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4013 | // that hangs up when credentials are initially sent. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4014 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4015 | AuthAllowsDefaultCredentialsTunnelServerClosesConnection) { |
| 4016 | HttpRequestInfo request; |
| 4017 | request.method = "GET"; |
| 4018 | request.url = GURL("https://www.example.org/"); |
| 4019 | |
| 4020 | // Configure against proxy server "myproxy:70". |
| 4021 | session_deps_.proxy_service = |
| 4022 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 4023 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4024 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4025 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4026 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4027 | mock_handler->set_allows_default_credentials(true); |
| 4028 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4029 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4030 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4031 | |
| 4032 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4033 | NetLog net_log; |
| 4034 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4035 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4036 | |
| 4037 | // Should try to establish tunnel. |
| 4038 | MockWrite data_writes1[] = { |
| 4039 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4040 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4041 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4042 | |
| 4043 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4044 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4045 | "Proxy-Connection: keep-alive\r\n" |
| 4046 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4047 | }; |
| 4048 | |
| 4049 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4050 | // connection. |
| 4051 | MockRead data_reads1[] = { |
| 4052 | // No credentials. |
| 4053 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4054 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4055 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4056 | }; |
| 4057 | |
| 4058 | // Since the first connection was closed, need to establish another once given |
| 4059 | // credentials. |
| 4060 | MockWrite data_writes2[] = { |
| 4061 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4062 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4063 | "Proxy-Connection: keep-alive\r\n" |
| 4064 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4065 | |
| 4066 | MockWrite("GET / HTTP/1.1\r\n" |
| 4067 | "Host: www.example.org\r\n" |
| 4068 | "Connection: keep-alive\r\n\r\n"), |
| 4069 | }; |
| 4070 | |
| 4071 | MockRead data_reads2[] = { |
| 4072 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 4073 | |
| 4074 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4075 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4076 | MockRead("Content-Length: 5\r\n\r\n"), |
| 4077 | MockRead(SYNCHRONOUS, "hello"), |
| 4078 | }; |
| 4079 | |
| 4080 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4081 | data_writes1, arraysize(data_writes1)); |
| 4082 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4083 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4084 | data_writes2, arraysize(data_writes2)); |
| 4085 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4086 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4087 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4088 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4089 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4090 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4091 | |
| 4092 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4093 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4094 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4095 | |
| 4096 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4097 | ASSERT_TRUE(response); |
| 4098 | ASSERT_TRUE(response->headers); |
| 4099 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4100 | EXPECT_EQ(407, response->headers->response_code()); |
| 4101 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4102 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4103 | EXPECT_FALSE(response->auth_challenge); |
| 4104 | |
| 4105 | LoadTimingInfo load_timing_info; |
| 4106 | // CONNECT requests and responses are handled at the connect job level, so |
| 4107 | // the transaction does not yet have a connection. |
| 4108 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4109 | |
| 4110 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4111 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4112 | |
| 4113 | response = trans->GetResponseInfo(); |
| 4114 | ASSERT_TRUE(response); |
| 4115 | ASSERT_TRUE(response->headers); |
| 4116 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4117 | EXPECT_EQ(200, response->headers->response_code()); |
| 4118 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 4119 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4120 | |
| 4121 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4122 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4123 | |
| 4124 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4125 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4126 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4127 | |
| 4128 | trans.reset(); |
| 4129 | session->CloseAllConnections(); |
| 4130 | } |
| 4131 | |
| 4132 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4133 | // that hangs up when credentials are initially sent, and hangs up again when |
| 4134 | // they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4135 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4136 | AuthAllowsDefaultCredentialsTunnelServerClosesConnectionTwice) { |
| 4137 | HttpRequestInfo request; |
| 4138 | request.method = "GET"; |
| 4139 | request.url = GURL("https://www.example.org/"); |
| 4140 | |
| 4141 | // Configure against proxy server "myproxy:70". |
| 4142 | session_deps_.proxy_service = |
| 4143 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 4144 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4145 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4146 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4147 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4148 | mock_handler->set_allows_default_credentials(true); |
| 4149 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4150 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4151 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4152 | |
| 4153 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4154 | NetLog net_log; |
| 4155 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4156 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4157 | |
| 4158 | // Should try to establish tunnel. |
| 4159 | MockWrite data_writes1[] = { |
| 4160 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4161 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4162 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4163 | |
| 4164 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4165 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4166 | "Proxy-Connection: keep-alive\r\n" |
| 4167 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4168 | }; |
| 4169 | |
| 4170 | // The proxy responds to the connect with a 407, and then hangs up after the |
| 4171 | // second request is sent. |
| 4172 | MockRead data_reads1[] = { |
| 4173 | // No credentials. |
| 4174 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4175 | MockRead("Content-Length: 0\r\n"), |
| 4176 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4177 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4178 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4179 | }; |
| 4180 | |
| 4181 | // HttpNetworkTransaction sees a reused connection that was closed with |
| 4182 | // ERR_CONNECTION_CLOSED, realized it might have been a race, so retries the |
| 4183 | // request. |
| 4184 | MockWrite data_writes2[] = { |
| 4185 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4186 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4187 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4188 | }; |
| 4189 | |
| 4190 | // The proxy, having had more than enough of us, just hangs up. |
| 4191 | MockRead data_reads2[] = { |
| 4192 | // No credentials. |
| 4193 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4194 | }; |
| 4195 | |
| 4196 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4197 | data_writes1, arraysize(data_writes1)); |
| 4198 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4199 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4200 | data_writes2, arraysize(data_writes2)); |
| 4201 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4202 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4203 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4204 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4205 | |
| 4206 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4207 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4208 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4209 | |
| 4210 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4211 | ASSERT_TRUE(response); |
| 4212 | ASSERT_TRUE(response->headers); |
| 4213 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4214 | EXPECT_EQ(407, response->headers->response_code()); |
| 4215 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4216 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4217 | EXPECT_FALSE(response->auth_challenge); |
| 4218 | |
| 4219 | LoadTimingInfo load_timing_info; |
| 4220 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4221 | |
| 4222 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4223 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4224 | |
| 4225 | trans.reset(); |
| 4226 | session->CloseAllConnections(); |
| 4227 | } |
| 4228 | |
| 4229 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4230 | // that hangs up when credentials are initially sent, and sends a challenge |
| 4231 | // again they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4232 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4233 | AuthAllowsDefaultCredentialsTunnelServerChallengesTwice) { |
| 4234 | HttpRequestInfo request; |
| 4235 | request.method = "GET"; |
| 4236 | request.url = GURL("https://www.example.org/"); |
| 4237 | |
| 4238 | // Configure against proxy server "myproxy:70". |
| 4239 | session_deps_.proxy_service = |
| 4240 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 4241 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4242 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4243 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4244 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4245 | mock_handler->set_allows_default_credentials(true); |
| 4246 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4247 | HttpAuth::AUTH_PROXY); |
| 4248 | // Add another handler for the second challenge. It supports default |
| 4249 | // credentials, but they shouldn't be used, since they were already tried. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4250 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4251 | mock_handler->set_allows_default_credentials(true); |
| 4252 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4253 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4254 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4255 | |
| 4256 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4257 | NetLog net_log; |
| 4258 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4259 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4260 | |
| 4261 | // Should try to establish tunnel. |
| 4262 | MockWrite data_writes1[] = { |
| 4263 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4264 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4265 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4266 | }; |
| 4267 | |
| 4268 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4269 | // connection. |
| 4270 | MockRead data_reads1[] = { |
| 4271 | // No credentials. |
| 4272 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4273 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4274 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4275 | }; |
| 4276 | |
| 4277 | // Since the first connection was closed, need to establish another once given |
| 4278 | // credentials. |
| 4279 | MockWrite data_writes2[] = { |
| 4280 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4281 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4282 | "Proxy-Connection: keep-alive\r\n" |
| 4283 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4284 | }; |
| 4285 | |
| 4286 | MockRead data_reads2[] = { |
| 4287 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4288 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4289 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4290 | }; |
| 4291 | |
| 4292 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4293 | data_writes1, arraysize(data_writes1)); |
| 4294 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4295 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4296 | data_writes2, arraysize(data_writes2)); |
| 4297 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4298 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4299 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4300 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4301 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4302 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4303 | |
| 4304 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4305 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4306 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4307 | |
| 4308 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4309 | ASSERT_TRUE(response); |
| 4310 | ASSERT_TRUE(response->headers); |
| 4311 | EXPECT_EQ(407, response->headers->response_code()); |
| 4312 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4313 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4314 | EXPECT_FALSE(response->auth_challenge); |
| 4315 | |
| 4316 | LoadTimingInfo load_timing_info; |
| 4317 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4318 | |
| 4319 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4320 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4321 | response = trans->GetResponseInfo(); |
| 4322 | ASSERT_TRUE(response); |
| 4323 | ASSERT_TRUE(response->headers); |
| 4324 | EXPECT_EQ(407, response->headers->response_code()); |
| 4325 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4326 | EXPECT_TRUE(response->auth_challenge); |
| 4327 | |
| 4328 | trans.reset(); |
| 4329 | session->CloseAllConnections(); |
| 4330 | } |
| 4331 | |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4332 | // A more nuanced test than GenerateAuthToken test which asserts that |
| 4333 | // ERR_INVALID_AUTH_CREDENTIALS does not cause the auth scheme to be |
| 4334 | // unnecessarily invalidated, and that if the server co-operates, the |
| 4335 | // authentication handshake can continue with the same scheme but with a |
| 4336 | // different identity. |
| 4337 | TEST_F(HttpNetworkTransactionTest, NonPermanentGenerateAuthTokenError) { |
| 4338 | HttpRequestInfo request; |
| 4339 | request.method = "GET"; |
| 4340 | request.url = GURL("http://www.example.org/"); |
| 4341 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4342 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4343 | auth_handler_factory->set_do_init_from_challenge(true); |
| 4344 | |
| 4345 | // First handler. Uses default credentials, but barfs at generate auth token. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4346 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4347 | mock_handler->set_allows_default_credentials(true); |
| 4348 | mock_handler->set_allows_explicit_credentials(true); |
| 4349 | mock_handler->set_connection_based(true); |
| 4350 | mock_handler->SetGenerateExpectation(true, ERR_INVALID_AUTH_CREDENTIALS); |
| 4351 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4352 | HttpAuth::AUTH_SERVER); |
| 4353 | |
| 4354 | // Add another handler for the second challenge. It supports default |
| 4355 | // credentials, but they shouldn't be used, since they were already tried. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4356 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4357 | mock_handler->set_allows_default_credentials(true); |
| 4358 | mock_handler->set_allows_explicit_credentials(true); |
| 4359 | mock_handler->set_connection_based(true); |
| 4360 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4361 | HttpAuth::AUTH_SERVER); |
| 4362 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
| 4363 | |
| 4364 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4365 | |
| 4366 | MockWrite data_writes1[] = { |
| 4367 | MockWrite("GET / HTTP/1.1\r\n" |
| 4368 | "Host: www.example.org\r\n" |
| 4369 | "Connection: keep-alive\r\n\r\n"), |
| 4370 | }; |
| 4371 | |
| 4372 | MockRead data_reads1[] = { |
| 4373 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4374 | "WWW-Authenticate: Mock\r\n" |
| 4375 | "Connection: keep-alive\r\n\r\n"), |
| 4376 | }; |
| 4377 | |
| 4378 | // Identical to data_writes1[]. The AuthHandler encounters a |
| 4379 | // ERR_INVALID_AUTH_CREDENTIALS during the GenerateAuthToken stage, so the |
| 4380 | // transaction procceds without an authorization header. |
| 4381 | MockWrite data_writes2[] = { |
| 4382 | MockWrite("GET / HTTP/1.1\r\n" |
| 4383 | "Host: www.example.org\r\n" |
| 4384 | "Connection: keep-alive\r\n\r\n"), |
| 4385 | }; |
| 4386 | |
| 4387 | MockRead data_reads2[] = { |
| 4388 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4389 | "WWW-Authenticate: Mock\r\n" |
| 4390 | "Connection: keep-alive\r\n\r\n"), |
| 4391 | }; |
| 4392 | |
| 4393 | MockWrite data_writes3[] = { |
| 4394 | MockWrite("GET / HTTP/1.1\r\n" |
| 4395 | "Host: www.example.org\r\n" |
| 4396 | "Connection: keep-alive\r\n" |
| 4397 | "Authorization: auth_token\r\n\r\n"), |
| 4398 | }; |
| 4399 | |
| 4400 | MockRead data_reads3[] = { |
| 4401 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4402 | "Content-Length: 5\r\n" |
| 4403 | "Content-Type: text/plain\r\n" |
| 4404 | "Connection: keep-alive\r\n\r\n" |
| 4405 | "Hello"), |
| 4406 | }; |
| 4407 | |
| 4408 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4409 | data_writes1, arraysize(data_writes1)); |
| 4410 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4411 | |
| 4412 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 4413 | data_writes2, arraysize(data_writes2)); |
| 4414 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4415 | |
| 4416 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 4417 | data_writes3, arraysize(data_writes3)); |
| 4418 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 4419 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4420 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4421 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4422 | |
| 4423 | TestCompletionCallback callback; |
| 4424 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 4425 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4426 | |
| 4427 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4428 | ASSERT_TRUE(response); |
| 4429 | ASSERT_TRUE(response->headers); |
| 4430 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4431 | |
| 4432 | // The following three tests assert that an authentication challenge was |
| 4433 | // received and that the stack is ready to respond to the challenge using |
| 4434 | // ambient credentials. |
| 4435 | EXPECT_EQ(401, response->headers->response_code()); |
| 4436 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4437 | EXPECT_FALSE(response->auth_challenge); |
| 4438 | |
| 4439 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4440 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4441 | response = trans->GetResponseInfo(); |
| 4442 | ASSERT_TRUE(response); |
| 4443 | ASSERT_TRUE(response->headers); |
| 4444 | |
| 4445 | // The following three tests assert that an authentication challenge was |
| 4446 | // received and that the stack needs explicit credentials before it is ready |
| 4447 | // to respond to the challenge. |
| 4448 | EXPECT_EQ(401, response->headers->response_code()); |
| 4449 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4450 | EXPECT_TRUE(response->auth_challenge); |
| 4451 | |
| 4452 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4453 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4454 | response = trans->GetResponseInfo(); |
| 4455 | ASSERT_TRUE(response); |
| 4456 | ASSERT_TRUE(response->headers); |
| 4457 | EXPECT_EQ(200, response->headers->response_code()); |
| 4458 | |
| 4459 | trans.reset(); |
| 4460 | session->CloseAllConnections(); |
| 4461 | } |
| 4462 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4463 | // Test the load timing for HTTPS requests with an HTTP proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4464 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingNoPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4465 | HttpRequestInfo request1; |
| 4466 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4467 | request1.url = GURL("https://www.example.org/1"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4468 | |
| 4469 | HttpRequestInfo request2; |
| 4470 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4471 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4472 | |
| 4473 | // Configure against proxy server "myproxy:70". |
brettw | c1213d9 | 2016-11-12 03:41:13 | [diff] [blame] | 4474 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4475 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4476 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4477 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4478 | |
| 4479 | // Since we have proxy, should try to establish tunnel. |
| 4480 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4481 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4482 | "Host: www.example.org:443\r\n" |
| 4483 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4484 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4485 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 4486 | "Host: www.example.org\r\n" |
| 4487 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4488 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4489 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 4490 | "Host: www.example.org\r\n" |
| 4491 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4492 | }; |
| 4493 | |
| 4494 | // The proxy responds to the connect with a 407, using a persistent |
| 4495 | // connection. |
| 4496 | MockRead data_reads1[] = { |
| 4497 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4498 | |
| 4499 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4500 | MockRead("Content-Length: 1\r\n\r\n"), |
| 4501 | MockRead(SYNCHRONOUS, "1"), |
| 4502 | |
| 4503 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4504 | MockRead("Content-Length: 2\r\n\r\n"), |
| 4505 | MockRead(SYNCHRONOUS, "22"), |
| 4506 | }; |
| 4507 | |
| 4508 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4509 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4510 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4511 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4512 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4513 | |
| 4514 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4515 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4516 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4517 | |
| 4518 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4519 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4520 | |
| 4521 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4522 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4523 | |
| 4524 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4525 | ASSERT_TRUE(response1); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4526 | EXPECT_TRUE(response1->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4527 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4528 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 4529 | |
| 4530 | LoadTimingInfo load_timing_info1; |
| 4531 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 4532 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4533 | |
| 4534 | trans1.reset(); |
| 4535 | |
| 4536 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4537 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4538 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4539 | |
| 4540 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4541 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4542 | |
| 4543 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4544 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4545 | |
| 4546 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4547 | ASSERT_TRUE(response2); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4548 | EXPECT_TRUE(response2->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4549 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4550 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 4551 | |
| 4552 | LoadTimingInfo load_timing_info2; |
| 4553 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4554 | TestLoadTimingReused(load_timing_info2); |
| 4555 | |
| 4556 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 4557 | |
| 4558 | trans2.reset(); |
| 4559 | session->CloseAllConnections(); |
| 4560 | } |
| 4561 | |
| 4562 | // 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] | 4563 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingWithPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4564 | HttpRequestInfo request1; |
| 4565 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4566 | request1.url = GURL("https://www.example.org/1"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4567 | |
| 4568 | HttpRequestInfo request2; |
| 4569 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4570 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4571 | |
| 4572 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4573 | session_deps_.proxy_service = |
| 4574 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4575 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4576 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4577 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4578 | |
| 4579 | // Since we have proxy, should try to establish tunnel. |
| 4580 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4581 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4582 | "Host: www.example.org:443\r\n" |
| 4583 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4584 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4585 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 4586 | "Host: www.example.org\r\n" |
| 4587 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4588 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4589 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 4590 | "Host: www.example.org\r\n" |
| 4591 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4592 | }; |
| 4593 | |
| 4594 | // The proxy responds to the connect with a 407, using a persistent |
| 4595 | // connection. |
| 4596 | MockRead data_reads1[] = { |
| 4597 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4598 | |
| 4599 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4600 | MockRead("Content-Length: 1\r\n\r\n"), |
| 4601 | MockRead(SYNCHRONOUS, "1"), |
| 4602 | |
| 4603 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4604 | MockRead("Content-Length: 2\r\n\r\n"), |
| 4605 | MockRead(SYNCHRONOUS, "22"), |
| 4606 | }; |
| 4607 | |
| 4608 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4609 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4610 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4611 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4612 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4613 | |
| 4614 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4615 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4616 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4617 | |
| 4618 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4619 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4620 | |
| 4621 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4622 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4623 | |
| 4624 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4625 | ASSERT_TRUE(response1); |
| 4626 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4627 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 4628 | |
| 4629 | LoadTimingInfo load_timing_info1; |
| 4630 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 4631 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 4632 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4633 | |
| 4634 | trans1.reset(); |
| 4635 | |
| 4636 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4637 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4638 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4639 | |
| 4640 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4641 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4642 | |
| 4643 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4644 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4645 | |
| 4646 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4647 | ASSERT_TRUE(response2); |
| 4648 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4649 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 4650 | |
| 4651 | LoadTimingInfo load_timing_info2; |
| 4652 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4653 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 4654 | |
| 4655 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 4656 | |
| 4657 | trans2.reset(); |
| 4658 | session->CloseAllConnections(); |
| 4659 | } |
| 4660 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4661 | // Test a simple get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4662 | TEST_F(HttpNetworkTransactionTest, HttpsProxyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4663 | HttpRequestInfo request; |
| 4664 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4665 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4666 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4667 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4668 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4669 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4670 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4671 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4672 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4673 | // Since we have proxy, should use full url |
| 4674 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4675 | MockWrite( |
| 4676 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 4677 | "Host: www.example.org\r\n" |
| 4678 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4679 | }; |
| 4680 | |
| 4681 | MockRead data_reads1[] = { |
| 4682 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4683 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4684 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4685 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4686 | }; |
| 4687 | |
| 4688 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 4689 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4690 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4691 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4692 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4693 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4694 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4695 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4696 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4697 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4698 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4699 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4700 | |
| 4701 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4702 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4703 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4704 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4705 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4706 | TestLoadTimingNotReused(load_timing_info, |
| 4707 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4708 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4709 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4710 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4711 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4712 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4713 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4714 | EXPECT_EQ(200, response->headers->response_code()); |
| 4715 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 4716 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4717 | |
| 4718 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4719 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4720 | } |
| 4721 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4722 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4723 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4724 | HttpRequestInfo request; |
| 4725 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4726 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4727 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4728 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4729 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4730 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4731 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4732 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4733 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4734 | // fetch http://www.example.org/ via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4735 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 4736 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4737 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4738 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4739 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4740 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4741 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4742 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4743 | }; |
| 4744 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4745 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4746 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4747 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4748 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4749 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4750 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4751 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4752 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4753 | TestCompletionCallback callback1; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4754 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4755 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4756 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4757 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4758 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4759 | |
| 4760 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4761 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4762 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4763 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4764 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4765 | TestLoadTimingNotReused(load_timing_info, |
| 4766 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4767 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4768 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4769 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4770 | EXPECT_TRUE(response->proxy_server.is_https()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4771 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4772 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4773 | |
| 4774 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4775 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 4776 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 4777 | } |
| 4778 | |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4779 | // Verifies that a session which races and wins against the owning transaction |
| 4780 | // (completing prior to host resolution), doesn't fail the transaction. |
| 4781 | // Regression test for crbug.com/334413. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4782 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithSessionRace) { |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4783 | HttpRequestInfo request; |
| 4784 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4785 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4786 | |
| 4787 | // Configure SPDY proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4788 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4789 | BoundTestNetLog log; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4790 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4791 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4792 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4793 | // Fetch http://www.example.org/ through the SPDY proxy. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4794 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 4795 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4796 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4797 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4798 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4799 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4800 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4801 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4802 | }; |
| 4803 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4804 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4805 | arraysize(spdy_writes)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4806 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 4807 | |
| 4808 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4809 | ssl.next_proto = kProtoHTTP2; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4810 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4811 | |
| 4812 | TestCompletionCallback callback1; |
| 4813 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4814 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4815 | |
| 4816 | // Stall the hostname resolution begun by the transaction. |
| 4817 | session_deps_.host_resolver->set_synchronous_mode(false); |
| 4818 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 4819 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4820 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4821 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4822 | |
| 4823 | // Race a session to the proxy, which completes first. |
| 4824 | session_deps_.host_resolver->set_ondemand_mode(false); |
| 4825 | SpdySessionKey key( |
| 4826 | HostPortPair("proxy", 70), ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
| 4827 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 4828 | CreateSpdySession(session.get(), key, log.bound()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4829 | |
| 4830 | // Unstall the resolution begun by the transaction. |
| 4831 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 4832 | session_deps_.host_resolver->ResolveAllPending(); |
| 4833 | |
| 4834 | EXPECT_FALSE(callback1.have_result()); |
| 4835 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4836 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4837 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4838 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4839 | ASSERT_TRUE(response); |
| 4840 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 4841 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4842 | |
| 4843 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4844 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 4845 | EXPECT_EQ(kUploadData, response_data); |
| 4846 | } |
| 4847 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4848 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4849 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4850 | HttpRequestInfo request; |
| 4851 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4852 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4853 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 4854 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4855 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4856 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4857 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4858 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4859 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4860 | // The first request will be a bare GET, the second request will be a |
| 4861 | // GET with a Proxy-Authorization header. |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 4862 | spdy_util_.set_default_url(request.url); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4863 | SpdySerializedFrame req_get( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 4864 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, false)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 4865 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4866 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4867 | "proxy-authorization", "Basic Zm9vOmJhcg==" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4868 | }; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4869 | SpdySerializedFrame req_get_authorization(spdy_util_.ConstructSpdyGet( |
| 4870 | kExtraAuthorizationHeaders, arraysize(kExtraAuthorizationHeaders) / 2, 3, |
| 4871 | LOWEST, false)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4872 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4873 | CreateMockWrite(req_get, 0), CreateMockWrite(req_get_authorization, 3), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4874 | }; |
| 4875 | |
| 4876 | // The first response is a 407 proxy authentication challenge, and the second |
| 4877 | // response will be a 200 response since the second request includes a valid |
| 4878 | // Authorization header. |
| 4879 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 4880 | "proxy-authenticate", "Basic realm=\"MyRealm1\"" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4881 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4882 | SpdySerializedFrame resp_authentication(spdy_util_.ConstructSpdyReplyError( |
bnc | c9f762a | 2016-12-06 20:38:23 | [diff] [blame] | 4883 | "407", kExtraAuthenticationHeaders, |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4884 | arraysize(kExtraAuthenticationHeaders) / 2, 1)); |
| 4885 | SpdySerializedFrame body_authentication( |
| 4886 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4887 | SpdySerializedFrame resp_data(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4888 | SpdySerializedFrame body_data(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4889 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4890 | CreateMockRead(resp_authentication, 1), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 4891 | CreateMockRead(body_authentication, 2, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4892 | CreateMockRead(resp_data, 4), |
| 4893 | CreateMockRead(body_data, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4894 | MockRead(ASYNC, 0, 6), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4895 | }; |
| 4896 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4897 | SequencedSocketData data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4898 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4899 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4900 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4901 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4902 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4903 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4904 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4905 | TestCompletionCallback callback1; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4906 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4907 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4908 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4909 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4910 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4911 | |
| 4912 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4913 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4914 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4915 | const HttpResponseInfo* const response = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4916 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4917 | ASSERT_TRUE(response); |
| 4918 | ASSERT_TRUE(response->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4919 | EXPECT_EQ(407, response->headers->response_code()); |
| 4920 | EXPECT_TRUE(response->was_fetched_via_spdy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 4921 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4922 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4923 | TestCompletionCallback callback2; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4924 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4925 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4926 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4927 | |
| 4928 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4929 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4930 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4931 | const HttpResponseInfo* const response_restart = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4932 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4933 | ASSERT_TRUE(response_restart); |
| 4934 | ASSERT_TRUE(response_restart->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4935 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 4936 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4937 | EXPECT_FALSE(response_restart->auth_challenge); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 4938 | } |
| 4939 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4940 | // Test a SPDY CONNECT through an HTTPS Proxy to an HTTPS (non-SPDY) Server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4941 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4942 | HttpRequestInfo request; |
| 4943 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4944 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4945 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4946 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 4947 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4948 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4949 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4950 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4951 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4952 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4953 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4954 | // CONNECT to www.example.org:443 via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4955 | SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4956 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 4957 | // fetch https://www.example.org/ via HTTP |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4958 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4959 | const char get[] = |
| 4960 | "GET / HTTP/1.1\r\n" |
| 4961 | "Host: www.example.org\r\n" |
| 4962 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4963 | SpdySerializedFrame wrapped_get( |
| 4964 | spdy_util_.ConstructSpdyDataFrame(1, get, strlen(get), false)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 4965 | SpdySerializedFrame conn_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4966 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 4967 | "Content-Length: 10\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4968 | SpdySerializedFrame wrapped_get_resp( |
| 4969 | spdy_util_.ConstructSpdyDataFrame(1, resp, strlen(resp), false)); |
| 4970 | SpdySerializedFrame wrapped_body( |
| 4971 | spdy_util_.ConstructSpdyDataFrame(1, "1234567890", 10, false)); |
| 4972 | SpdySerializedFrame window_update( |
| 4973 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4974 | |
| 4975 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4976 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 4977 | CreateMockWrite(window_update, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 4978 | }; |
| 4979 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4980 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 4981 | CreateMockRead(conn_resp, 1, ASYNC), |
| 4982 | CreateMockRead(wrapped_get_resp, 3, ASYNC), |
| 4983 | CreateMockRead(wrapped_body, 4, ASYNC), |
| 4984 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4985 | MockRead(ASYNC, 0, 7), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4986 | }; |
| 4987 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 4988 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 4989 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4990 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4991 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4992 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 4993 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4994 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4995 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4996 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4997 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4998 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 4999 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5000 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5001 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5002 | |
| 5003 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5004 | ASSERT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5005 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5006 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5007 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5008 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5009 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5010 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5011 | ASSERT_TRUE(response); |
| 5012 | ASSERT_TRUE(response->headers); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5013 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5014 | |
| 5015 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5016 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5017 | EXPECT_EQ("1234567890", response_data); |
| 5018 | } |
| 5019 | |
| 5020 | // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5021 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) { |
| 5022 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5023 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5024 | HttpRequestInfo request; |
| 5025 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5026 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5027 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5028 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5029 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5030 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5031 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5032 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5033 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5034 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5035 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5036 | // CONNECT to www.example.org:443 via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5037 | SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5038 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 5039 | // fetch https://www.example.org/ via SPDY |
| 5040 | const char kMyUrl[] = "https://www.example.org/"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5041 | SpdySerializedFrame get( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 5042 | spdy_util_wrapped.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5043 | SpdySerializedFrame wrapped_get(spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5044 | SpdySerializedFrame conn_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5045 | SpdySerializedFrame get_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5046 | spdy_util_wrapped.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5047 | SpdySerializedFrame wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5048 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5049 | SpdySerializedFrame body(spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 5050 | SpdySerializedFrame wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5051 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5052 | SpdySerializedFrame window_update_get_resp( |
| 5053 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
| 5054 | SpdySerializedFrame window_update_body( |
| 5055 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5056 | |
| 5057 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5058 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 5059 | CreateMockWrite(window_update_get_resp, 6), |
| 5060 | CreateMockWrite(window_update_body, 7), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5061 | }; |
| 5062 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5063 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5064 | CreateMockRead(conn_resp, 1, ASYNC), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5065 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5066 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 5067 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5068 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5069 | }; |
| 5070 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5071 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5072 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5073 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5074 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5075 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5076 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5077 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5078 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5079 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5080 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5081 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5082 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5083 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5084 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5085 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5086 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5087 | // Allow the SpdyProxyClientSocket's write callback to complete. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 5088 | base::RunLoop().RunUntilIdle(); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5089 | // Now allow the read of the response to complete. |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 5090 | spdy_data.Resume(); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5091 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5092 | EXPECT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5093 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5094 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5095 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5096 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5097 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5098 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5099 | ASSERT_TRUE(response); |
| 5100 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5101 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5102 | |
| 5103 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5104 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5105 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5106 | } |
| 5107 | |
| 5108 | // Test a SPDY CONNECT failure through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5109 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5110 | HttpRequestInfo request; |
| 5111 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5112 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5113 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5114 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5115 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5116 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5117 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5118 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5119 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5120 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5121 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5122 | // CONNECT to www.example.org:443 via SPDY |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5123 | SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5124 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5125 | SpdySerializedFrame get( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 5126 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5127 | |
| 5128 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5129 | CreateMockWrite(connect, 0), CreateMockWrite(get, 2), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5130 | }; |
| 5131 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5132 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError(1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5133 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5134 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5135 | CreateMockRead(resp, 1, ASYNC), MockRead(ASYNC, 0, 3), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5136 | }; |
| 5137 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5138 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5139 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5140 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5141 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5142 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5143 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5144 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5145 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5146 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5147 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5148 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5149 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5150 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5151 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5152 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5153 | |
| 5154 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5155 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5156 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 5157 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5158 | } |
| 5159 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5160 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 5161 | // HTTPS Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5162 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5163 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) { |
| 5164 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5165 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5166 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5167 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5168 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5169 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5170 | |
| 5171 | HttpRequestInfo request1; |
| 5172 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5173 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5174 | request1.load_flags = 0; |
| 5175 | |
| 5176 | HttpRequestInfo request2; |
| 5177 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5178 | request2.url = GURL("https://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5179 | request2.load_flags = 0; |
| 5180 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5181 | // CONNECT to www.example.org:443 via SPDY. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5182 | SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5183 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5184 | SpdySerializedFrame conn_resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5185 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5186 | // Fetch https://www.example.org/ via HTTP. |
| 5187 | const char get1[] = |
| 5188 | "GET / HTTP/1.1\r\n" |
| 5189 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5190 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5191 | SpdySerializedFrame wrapped_get1( |
| 5192 | spdy_util_.ConstructSpdyDataFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5193 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 5194 | "Content-Length: 1\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5195 | SpdySerializedFrame wrapped_get_resp1( |
| 5196 | spdy_util_.ConstructSpdyDataFrame(1, resp1, strlen(resp1), false)); |
| 5197 | SpdySerializedFrame wrapped_body1( |
| 5198 | spdy_util_.ConstructSpdyDataFrame(1, "1", 1, false)); |
| 5199 | SpdySerializedFrame window_update( |
| 5200 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5201 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5202 | // CONNECT to mail.example.org:443 via SPDY. |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 5203 | SpdyHeaderBlock connect2_block; |
| 5204 | connect2_block[spdy_util_.GetMethodKey()] = "CONNECT"; |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 5205 | connect2_block[spdy_util_.GetHostKey()] = "mail.example.org:443"; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5206 | SpdySerializedFrame connect2(spdy_util_.ConstructSpdyHeaders( |
| 5207 | 3, std::move(connect2_block), LOWEST, false)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 5208 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5209 | SpdySerializedFrame conn_resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5210 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5211 | // Fetch https://mail.example.org/ via HTTP. |
| 5212 | const char get2[] = |
| 5213 | "GET / HTTP/1.1\r\n" |
| 5214 | "Host: mail.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5215 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5216 | SpdySerializedFrame wrapped_get2( |
| 5217 | spdy_util_.ConstructSpdyDataFrame(3, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5218 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 5219 | "Content-Length: 2\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5220 | SpdySerializedFrame wrapped_get_resp2( |
| 5221 | spdy_util_.ConstructSpdyDataFrame(3, resp2, strlen(resp2), false)); |
| 5222 | SpdySerializedFrame wrapped_body2( |
| 5223 | spdy_util_.ConstructSpdyDataFrame(3, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5224 | |
| 5225 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5226 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 5227 | CreateMockWrite(connect2, 5), CreateMockWrite(wrapped_get2, 7), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5228 | }; |
| 5229 | |
| 5230 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5231 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 5232 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
| 5233 | CreateMockRead(wrapped_body1, 4, ASYNC), |
| 5234 | CreateMockRead(conn_resp2, 6, ASYNC), |
| 5235 | CreateMockRead(wrapped_get_resp2, 8, ASYNC), |
| 5236 | CreateMockRead(wrapped_body2, 9, ASYNC), |
| 5237 | MockRead(ASYNC, 0, 10), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5238 | }; |
| 5239 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5240 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5241 | arraysize(spdy_writes)); |
| 5242 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5243 | |
| 5244 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5245 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5246 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5247 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5248 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5249 | SSLSocketDataProvider ssl3(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5250 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5251 | |
| 5252 | TestCompletionCallback callback; |
| 5253 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5254 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5255 | int rv = trans.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5256 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5257 | |
| 5258 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5259 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5260 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5261 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5262 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5263 | ASSERT_TRUE(response); |
| 5264 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5265 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5266 | |
| 5267 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5268 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5269 | rv = trans.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5270 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5271 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5272 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5273 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5274 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5275 | |
| 5276 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5277 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5278 | // Even though the SPDY connection is reused, a new tunnelled connection has |
| 5279 | // to be created, so the socket's load timing looks like a fresh connection. |
| 5280 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5281 | |
| 5282 | // The requests should have different IDs, since they each are using their own |
| 5283 | // separate stream. |
| 5284 | EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5285 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5286 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5287 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5288 | } |
| 5289 | |
| 5290 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 5291 | // HTTPS Proxy to the same server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5292 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5293 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) { |
| 5294 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5295 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5296 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5297 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5298 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5299 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5300 | |
| 5301 | HttpRequestInfo request1; |
| 5302 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5303 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5304 | request1.load_flags = 0; |
| 5305 | |
| 5306 | HttpRequestInfo request2; |
| 5307 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5308 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5309 | request2.load_flags = 0; |
| 5310 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5311 | // CONNECT to www.example.org:443 via SPDY. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5312 | SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5313 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5314 | SpdySerializedFrame conn_resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5315 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5316 | // Fetch https://www.example.org/ via HTTP. |
| 5317 | const char get1[] = |
| 5318 | "GET / HTTP/1.1\r\n" |
| 5319 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5320 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5321 | SpdySerializedFrame wrapped_get1( |
| 5322 | spdy_util_.ConstructSpdyDataFrame(1, get1, strlen(get1), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5323 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 5324 | "Content-Length: 1\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5325 | SpdySerializedFrame wrapped_get_resp1( |
| 5326 | spdy_util_.ConstructSpdyDataFrame(1, resp1, strlen(resp1), false)); |
| 5327 | SpdySerializedFrame wrapped_body1( |
| 5328 | spdy_util_.ConstructSpdyDataFrame(1, "1", 1, false)); |
| 5329 | SpdySerializedFrame window_update( |
| 5330 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5331 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5332 | // Fetch https://www.example.org/2 via HTTP. |
| 5333 | const char get2[] = |
| 5334 | "GET /2 HTTP/1.1\r\n" |
| 5335 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5336 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5337 | SpdySerializedFrame wrapped_get2( |
| 5338 | spdy_util_.ConstructSpdyDataFrame(1, get2, strlen(get2), false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5339 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 5340 | "Content-Length: 2\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5341 | SpdySerializedFrame wrapped_get_resp2( |
| 5342 | spdy_util_.ConstructSpdyDataFrame(1, resp2, strlen(resp2), false)); |
| 5343 | SpdySerializedFrame wrapped_body2( |
| 5344 | spdy_util_.ConstructSpdyDataFrame(1, "22", 2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5345 | |
| 5346 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5347 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 5348 | CreateMockWrite(wrapped_get2, 5), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5349 | }; |
| 5350 | |
| 5351 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5352 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 5353 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5354 | CreateMockRead(wrapped_body1, 4, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5355 | CreateMockRead(wrapped_get_resp2, 6, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5356 | CreateMockRead(wrapped_body2, 7, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5357 | MockRead(ASYNC, 0, 8), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5358 | }; |
| 5359 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5360 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5361 | arraysize(spdy_writes)); |
| 5362 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5363 | |
| 5364 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5365 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5366 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5367 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5368 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5369 | |
| 5370 | TestCompletionCallback callback; |
| 5371 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5372 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5373 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5374 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5375 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5376 | |
| 5377 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5378 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5379 | |
| 5380 | LoadTimingInfo load_timing_info; |
| 5381 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5382 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5383 | |
| 5384 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5385 | ASSERT_TRUE(response); |
| 5386 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5387 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5388 | |
| 5389 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5390 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5391 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5392 | trans.reset(); |
| 5393 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5394 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5395 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5396 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5397 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5398 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5399 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5400 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5401 | |
| 5402 | LoadTimingInfo load_timing_info2; |
| 5403 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 5404 | TestLoadTimingReused(load_timing_info2); |
| 5405 | |
| 5406 | // The requests should have the same ID. |
| 5407 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5408 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5409 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5410 | } |
| 5411 | |
| 5412 | // Test load timing in the case of of two HTTP requests through a SPDY HTTPS |
| 5413 | // Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5414 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyLoadTimingTwoHttpRequests) { |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5415 | // Configure against https proxy server "proxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5416 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5417 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5418 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5419 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5420 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5421 | |
| 5422 | HttpRequestInfo request1; |
| 5423 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5424 | request1.url = GURL("http://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5425 | request1.load_flags = 0; |
| 5426 | |
| 5427 | HttpRequestInfo request2; |
| 5428 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5429 | request2.url = GURL("http://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5430 | request2.load_flags = 0; |
| 5431 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5432 | // http://www.example.org/ |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 5433 | SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5434 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5435 | SpdySerializedFrame get1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5436 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
| 5437 | SpdySerializedFrame get_resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5438 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, "1", 1, true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5439 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5440 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5441 | // http://mail.example.org/ |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 5442 | SpdyHeaderBlock headers2( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5443 | spdy_util_.ConstructGetHeaderBlockForProxy("http://mail.example.org/")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5444 | SpdySerializedFrame get2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5445 | spdy_util_.ConstructSpdyHeaders(3, std::move(headers2), LOWEST, true)); |
| 5446 | SpdySerializedFrame get_resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5447 | SpdySerializedFrame body2( |
| 5448 | spdy_util_.ConstructSpdyDataFrame(3, "22", 2, true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5449 | |
| 5450 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5451 | CreateMockWrite(get1, 0), CreateMockWrite(get2, 3), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5452 | }; |
| 5453 | |
| 5454 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5455 | CreateMockRead(get_resp1, 1, ASYNC), |
| 5456 | CreateMockRead(body1, 2, ASYNC), |
| 5457 | CreateMockRead(get_resp2, 4, ASYNC), |
| 5458 | CreateMockRead(body2, 5, ASYNC), |
| 5459 | MockRead(ASYNC, 0, 6), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5460 | }; |
| 5461 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5462 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 5463 | arraysize(spdy_writes)); |
| 5464 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5465 | |
| 5466 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5467 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5468 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5469 | |
| 5470 | TestCompletionCallback callback; |
| 5471 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5472 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5473 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5474 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5475 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5476 | |
| 5477 | LoadTimingInfo load_timing_info; |
| 5478 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5479 | TestLoadTimingNotReused(load_timing_info, |
| 5480 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5481 | |
| 5482 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5483 | ASSERT_TRUE(response); |
| 5484 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5485 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5486 | |
| 5487 | std::string response_data; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5488 | scoped_refptr<IOBuffer> buf(new IOBuffer(256)); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5489 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 5490 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5491 | // Delete the first request, so the second one can reuse the socket. |
| 5492 | trans.reset(); |
| 5493 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5494 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5495 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5496 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5497 | |
| 5498 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5499 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5500 | TestLoadTimingReused(load_timing_info2); |
| 5501 | |
| 5502 | // The requests should have the same ID. |
| 5503 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5504 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5505 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5506 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5507 | } |
| 5508 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5509 | // Test the challenge-response-retry sequence through an HTTPS Proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5510 | TEST_F(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5511 | HttpRequestInfo request; |
| 5512 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5513 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5514 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5515 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5516 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5517 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5518 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5519 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5520 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5521 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5522 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5523 | // Since we have proxy, should use full url |
| 5524 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5525 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 5526 | "Host: www.example.org\r\n" |
| 5527 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5528 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5529 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5530 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5531 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 5532 | "Host: www.example.org\r\n" |
| 5533 | "Proxy-Connection: keep-alive\r\n" |
| 5534 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5535 | }; |
| 5536 | |
| 5537 | // The proxy responds to the GET with a 407, using a persistent |
| 5538 | // connection. |
| 5539 | MockRead data_reads1[] = { |
| 5540 | // No credentials. |
| 5541 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 5542 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5543 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 5544 | MockRead("Content-Length: 0\r\n\r\n"), |
| 5545 | |
| 5546 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5547 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5548 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5549 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5550 | }; |
| 5551 | |
| 5552 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5553 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5554 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5555 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5556 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5557 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5558 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5559 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5560 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5561 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5562 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5563 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5564 | |
| 5565 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5566 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5567 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5568 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5569 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5570 | TestLoadTimingNotReused(load_timing_info, |
| 5571 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5572 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5573 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5574 | ASSERT_TRUE(response); |
| 5575 | ASSERT_TRUE(response->headers); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5576 | EXPECT_EQ(407, response->headers->response_code()); |
| 5577 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 5578 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5579 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5580 | TestCompletionCallback callback2; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5581 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5582 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5583 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5584 | |
| 5585 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5586 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5587 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5588 | load_timing_info = LoadTimingInfo(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5589 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5590 | // Retrying with HTTP AUTH is considered to be reusing a socket. |
| 5591 | TestLoadTimingReused(load_timing_info); |
| 5592 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5593 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5594 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5595 | |
| 5596 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 5597 | EXPECT_EQ(200, response->headers->response_code()); |
| 5598 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5599 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5600 | |
| 5601 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5602 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5603 | } |
| 5604 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5605 | void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5606 | const MockRead& status, int expected_status) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5607 | HttpRequestInfo request; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5608 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5609 | request.url = GURL("https://www.example.org/"); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5610 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5611 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5612 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5613 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5614 | |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5615 | // Since we have proxy, should try to establish tunnel. |
| 5616 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5617 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5618 | "Host: www.example.org:443\r\n" |
| 5619 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5620 | }; |
| 5621 | |
| 5622 | MockRead data_reads[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 5623 | status, MockRead("Content-Length: 10\r\n\r\n"), |
| 5624 | // No response body because the test stops reading here. |
| 5625 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5626 | }; |
| 5627 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5628 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 5629 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5630 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5631 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5632 | TestCompletionCallback callback; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5633 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5634 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5635 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5636 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5637 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5638 | |
| 5639 | rv = callback.WaitForResult(); |
| 5640 | EXPECT_EQ(expected_status, rv); |
| 5641 | } |
| 5642 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5643 | void HttpNetworkTransactionTest::ConnectStatusHelper( |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5644 | const MockRead& status) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5645 | ConnectStatusHelperWithExpectedStatus( |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5646 | status, ERR_TUNNEL_CONNECTION_FAILED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5647 | } |
| 5648 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5649 | TEST_F(HttpNetworkTransactionTest, ConnectStatus100) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5650 | ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n")); |
| 5651 | } |
| 5652 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5653 | TEST_F(HttpNetworkTransactionTest, ConnectStatus101) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5654 | ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n")); |
| 5655 | } |
| 5656 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5657 | TEST_F(HttpNetworkTransactionTest, ConnectStatus201) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5658 | ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n")); |
| 5659 | } |
| 5660 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5661 | TEST_F(HttpNetworkTransactionTest, ConnectStatus202) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5662 | ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n")); |
| 5663 | } |
| 5664 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5665 | TEST_F(HttpNetworkTransactionTest, ConnectStatus203) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5666 | ConnectStatusHelper( |
| 5667 | MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n")); |
| 5668 | } |
| 5669 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5670 | TEST_F(HttpNetworkTransactionTest, ConnectStatus204) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5671 | ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n")); |
| 5672 | } |
| 5673 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5674 | TEST_F(HttpNetworkTransactionTest, ConnectStatus205) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5675 | ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n")); |
| 5676 | } |
| 5677 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5678 | TEST_F(HttpNetworkTransactionTest, ConnectStatus206) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5679 | ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n")); |
| 5680 | } |
| 5681 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5682 | TEST_F(HttpNetworkTransactionTest, ConnectStatus300) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5683 | ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n")); |
| 5684 | } |
| 5685 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5686 | TEST_F(HttpNetworkTransactionTest, ConnectStatus301) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5687 | ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n")); |
| 5688 | } |
| 5689 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5690 | TEST_F(HttpNetworkTransactionTest, ConnectStatus302) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5691 | ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n")); |
| 5692 | } |
| 5693 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5694 | TEST_F(HttpNetworkTransactionTest, ConnectStatus303) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5695 | ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n")); |
| 5696 | } |
| 5697 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5698 | TEST_F(HttpNetworkTransactionTest, ConnectStatus304) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5699 | ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n")); |
| 5700 | } |
| 5701 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5702 | TEST_F(HttpNetworkTransactionTest, ConnectStatus305) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5703 | ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n")); |
| 5704 | } |
| 5705 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5706 | TEST_F(HttpNetworkTransactionTest, ConnectStatus306) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5707 | ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n")); |
| 5708 | } |
| 5709 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5710 | TEST_F(HttpNetworkTransactionTest, ConnectStatus307) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5711 | ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n")); |
| 5712 | } |
| 5713 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5714 | TEST_F(HttpNetworkTransactionTest, ConnectStatus308) { |
[email protected] | 0a17aab3 | 2014-04-24 03:32:37 | [diff] [blame] | 5715 | ConnectStatusHelper(MockRead("HTTP/1.1 308 Permanent Redirect\r\n")); |
| 5716 | } |
| 5717 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5718 | TEST_F(HttpNetworkTransactionTest, ConnectStatus400) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5719 | ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n")); |
| 5720 | } |
| 5721 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5722 | TEST_F(HttpNetworkTransactionTest, ConnectStatus401) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5723 | ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n")); |
| 5724 | } |
| 5725 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5726 | TEST_F(HttpNetworkTransactionTest, ConnectStatus402) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5727 | ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n")); |
| 5728 | } |
| 5729 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5730 | TEST_F(HttpNetworkTransactionTest, ConnectStatus403) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5731 | ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n")); |
| 5732 | } |
| 5733 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5734 | TEST_F(HttpNetworkTransactionTest, ConnectStatus404) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5735 | ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n")); |
| 5736 | } |
| 5737 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5738 | TEST_F(HttpNetworkTransactionTest, ConnectStatus405) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5739 | ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n")); |
| 5740 | } |
| 5741 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5742 | TEST_F(HttpNetworkTransactionTest, ConnectStatus406) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5743 | ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n")); |
| 5744 | } |
| 5745 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5746 | TEST_F(HttpNetworkTransactionTest, ConnectStatus407) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5747 | ConnectStatusHelperWithExpectedStatus( |
| 5748 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
[email protected] | a7ea883 | 2010-07-12 17:54:54 | [diff] [blame] | 5749 | ERR_PROXY_AUTH_UNSUPPORTED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5750 | } |
| 5751 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5752 | TEST_F(HttpNetworkTransactionTest, ConnectStatus408) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5753 | ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n")); |
| 5754 | } |
| 5755 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5756 | TEST_F(HttpNetworkTransactionTest, ConnectStatus409) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5757 | ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n")); |
| 5758 | } |
| 5759 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5760 | TEST_F(HttpNetworkTransactionTest, ConnectStatus410) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5761 | ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n")); |
| 5762 | } |
| 5763 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5764 | TEST_F(HttpNetworkTransactionTest, ConnectStatus411) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5765 | ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n")); |
| 5766 | } |
| 5767 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5768 | TEST_F(HttpNetworkTransactionTest, ConnectStatus412) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5769 | ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n")); |
| 5770 | } |
| 5771 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5772 | TEST_F(HttpNetworkTransactionTest, ConnectStatus413) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5773 | ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n")); |
| 5774 | } |
| 5775 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5776 | TEST_F(HttpNetworkTransactionTest, ConnectStatus414) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5777 | ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n")); |
| 5778 | } |
| 5779 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5780 | TEST_F(HttpNetworkTransactionTest, ConnectStatus415) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5781 | ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n")); |
| 5782 | } |
| 5783 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5784 | TEST_F(HttpNetworkTransactionTest, ConnectStatus416) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5785 | ConnectStatusHelper( |
| 5786 | MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n")); |
| 5787 | } |
| 5788 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5789 | TEST_F(HttpNetworkTransactionTest, ConnectStatus417) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5790 | ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n")); |
| 5791 | } |
| 5792 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5793 | TEST_F(HttpNetworkTransactionTest, ConnectStatus500) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5794 | ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n")); |
| 5795 | } |
| 5796 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5797 | TEST_F(HttpNetworkTransactionTest, ConnectStatus501) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5798 | ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n")); |
| 5799 | } |
| 5800 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5801 | TEST_F(HttpNetworkTransactionTest, ConnectStatus502) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5802 | ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n")); |
| 5803 | } |
| 5804 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5805 | TEST_F(HttpNetworkTransactionTest, ConnectStatus503) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5806 | ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n")); |
| 5807 | } |
| 5808 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5809 | TEST_F(HttpNetworkTransactionTest, ConnectStatus504) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5810 | ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n")); |
| 5811 | } |
| 5812 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5813 | TEST_F(HttpNetworkTransactionTest, ConnectStatus505) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5814 | ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); |
| 5815 | } |
| 5816 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5817 | // Test the flow when both the proxy server AND origin server require |
| 5818 | // authentication. Again, this uses basic auth for both since that is |
| 5819 | // the simplest to mock. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5820 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5821 | HttpRequestInfo request; |
| 5822 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5823 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5824 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5825 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 5826 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5827 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 5828 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5829 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5830 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5831 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5832 | MockWrite( |
| 5833 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5834 | "Host: www.example.org\r\n" |
| 5835 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 5836 | }; |
| 5837 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5838 | MockRead data_reads1[] = { |
| 5839 | MockRead("HTTP/1.0 407 Unauthorized\r\n"), |
| 5840 | // Give a couple authenticate options (only the middle one is actually |
| 5841 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 5842 | MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5843 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5844 | MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 5845 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5846 | // Large content-length -- won't matter, as connection will be reset. |
| 5847 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5848 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5849 | }; |
| 5850 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5851 | // After calling trans.RestartWithAuth() the first time, this is the |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5852 | // request we should be issuing -- the final header line contains the |
| 5853 | // proxy's credentials. |
| 5854 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5855 | MockWrite( |
| 5856 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5857 | "Host: www.example.org\r\n" |
| 5858 | "Proxy-Connection: keep-alive\r\n" |
| 5859 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5860 | }; |
| 5861 | |
| 5862 | // Now the proxy server lets the request pass through to origin server. |
| 5863 | // The origin server responds with a 401. |
| 5864 | MockRead data_reads2[] = { |
| 5865 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 5866 | // Note: We are using the same realm-name as the proxy server. This is |
| 5867 | // completely valid, as realms are unique across hosts. |
| 5868 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5869 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5870 | MockRead("Content-Length: 2000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5871 | MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5872 | }; |
| 5873 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5874 | // After calling trans.RestartWithAuth() the second time, we should send |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5875 | // the credentials for both the proxy and origin server. |
| 5876 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5877 | MockWrite( |
| 5878 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5879 | "Host: www.example.org\r\n" |
| 5880 | "Proxy-Connection: keep-alive\r\n" |
| 5881 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 5882 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5883 | }; |
| 5884 | |
| 5885 | // Lastly we get the desired content. |
| 5886 | MockRead data_reads3[] = { |
| 5887 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 5888 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5889 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5890 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5891 | }; |
| 5892 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 5893 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 5894 | data_writes1, arraysize(data_writes1)); |
| 5895 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 5896 | data_writes2, arraysize(data_writes2)); |
| 5897 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 5898 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5899 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 5900 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 5901 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5902 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5903 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5904 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5905 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5906 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5907 | |
| 5908 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5909 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5910 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5911 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5912 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5913 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5914 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5915 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5916 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5917 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5918 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5919 | |
| 5920 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5921 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5922 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5923 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5924 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5925 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5926 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5927 | TestCompletionCallback callback3; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5928 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5929 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 5930 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5931 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5932 | |
| 5933 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5934 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5935 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5936 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5937 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5938 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 5939 | } |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 5940 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 5941 | // For the NTLM implementation using SSPI, we skip the NTLM tests since we |
| 5942 | // can't hook into its internals to cause it to generate predictable NTLM |
| 5943 | // authorization headers. |
| 5944 | #if defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 5945 | // The NTLM authentication unit tests were generated by capturing the HTTP |
| 5946 | // requests and responses using Fiddler 2 and inspecting the generated random |
| 5947 | // bytes in the debugger. |
| 5948 | |
| 5949 | // Enter the correct password and authenticate successfully. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5950 | TEST_F(HttpNetworkTransactionTest, NTLMAuth1) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5951 | HttpRequestInfo request; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5952 | request.method = "GET"; |
| 5953 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 5954 | |
| 5955 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 5956 | // to other auth schemes. |
| 5957 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5958 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5959 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom1, |
| 5960 | MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5961 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5962 | |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5963 | MockWrite data_writes1[] = { |
| 5964 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5965 | "Host: 172.22.68.17\r\n" |
| 5966 | "Connection: keep-alive\r\n\r\n"), |
| 5967 | }; |
| 5968 | |
| 5969 | MockRead data_reads1[] = { |
| 5970 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 5971 | // Negotiate and NTLM are often requested together. However, we only want |
| 5972 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 5973 | // the header that requests Negotiate for this test. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5974 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 5975 | MockRead("Connection: close\r\n"), |
| 5976 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 5977 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5978 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5979 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5980 | }; |
| 5981 | |
| 5982 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5983 | // After restarting with a null identity, this is the |
| 5984 | // request we should be issuing -- the final header line contains a Type |
| 5985 | // 1 message. |
| 5986 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5987 | "Host: 172.22.68.17\r\n" |
| 5988 | "Connection: keep-alive\r\n" |
| 5989 | "Authorization: NTLM " |
| 5990 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5991 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5992 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 5993 | // (the credentials for the origin server). The second request continues |
| 5994 | // on the same connection. |
| 5995 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5996 | "Host: 172.22.68.17\r\n" |
| 5997 | "Connection: keep-alive\r\n" |
| 5998 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 5999 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 6000 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBVKW" |
| 6001 | "Yma5xzVAAAAAAAAAAAAAAAAAAAAACH+gWcm+YsP9Tqb9zCR3WAeZZX" |
| 6002 | "ahlhx5I=\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6003 | }; |
| 6004 | |
| 6005 | MockRead data_reads2[] = { |
| 6006 | // The origin server responds with a Type 2 message. |
| 6007 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 6008 | MockRead("WWW-Authenticate: NTLM " |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6009 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCjGpMpPGlYKkAAAAAAAAAALo" |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6010 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 6011 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 6012 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 6013 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 6014 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 6015 | "BtAAAAAAA=\r\n"), |
| 6016 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6017 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6018 | MockRead("You are not authorized to view this page\r\n"), |
| 6019 | |
| 6020 | // Lastly we get the desired content. |
| 6021 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6022 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 6023 | MockRead("Content-Length: 13\r\n\r\n"), |
| 6024 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6025 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6026 | }; |
| 6027 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6028 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6029 | data_writes1, arraysize(data_writes1)); |
| 6030 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6031 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6032 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6033 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6034 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6035 | TestCompletionCallback callback1; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6036 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6037 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6038 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6039 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6040 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6041 | |
| 6042 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6043 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6044 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6045 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6046 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6047 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6048 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6049 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6050 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6051 | TestCompletionCallback callback2; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6052 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6053 | rv = trans.RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
| 6054 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6055 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6056 | |
| 6057 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6058 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6059 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6060 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6061 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6062 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6063 | ASSERT_TRUE(response); |
| 6064 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6065 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6066 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6067 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6068 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6069 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6070 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6071 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6072 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6073 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6074 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6075 | ASSERT_TRUE(response); |
| 6076 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6077 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 6078 | } |
| 6079 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6080 | // Enter a wrong password, and then the correct one. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6081 | TEST_F(HttpNetworkTransactionTest, NTLMAuth2) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6082 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6083 | request.method = "GET"; |
| 6084 | request.url = GURL("http://172.22.68.17/kids/login.aspx"); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6085 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6086 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom2, |
| 6087 | MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6088 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6089 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6090 | MockWrite data_writes1[] = { |
| 6091 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6092 | "Host: 172.22.68.17\r\n" |
| 6093 | "Connection: keep-alive\r\n\r\n"), |
| 6094 | }; |
| 6095 | |
| 6096 | MockRead data_reads1[] = { |
| 6097 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 6098 | // Negotiate and NTLM are often requested together. However, we only want |
| 6099 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 6100 | // the header that requests Negotiate for this test. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6101 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 6102 | MockRead("Connection: close\r\n"), |
| 6103 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6104 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6105 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6106 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6107 | }; |
| 6108 | |
| 6109 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6110 | // After restarting with a null identity, this is the |
| 6111 | // request we should be issuing -- the final header line contains a Type |
| 6112 | // 1 message. |
| 6113 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6114 | "Host: 172.22.68.17\r\n" |
| 6115 | "Connection: keep-alive\r\n" |
| 6116 | "Authorization: NTLM " |
| 6117 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6118 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6119 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 6120 | // (the credentials for the origin server). The second request continues |
| 6121 | // on the same connection. |
| 6122 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6123 | "Host: 172.22.68.17\r\n" |
| 6124 | "Connection: keep-alive\r\n" |
| 6125 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 6126 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 6127 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwCWeY" |
| 6128 | "XnSZNwoQAAAAAAAAAAAAAAAAAAAADLa34/phTTKzNTWdub+uyFleOj" |
| 6129 | "4Ww7b7E=\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6130 | }; |
| 6131 | |
| 6132 | MockRead data_reads2[] = { |
| 6133 | // The origin server responds with a Type 2 message. |
| 6134 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 6135 | MockRead("WWW-Authenticate: NTLM " |
| 6136 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCbVWUZezVGpAAAAAAAAAAALo" |
| 6137 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 6138 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 6139 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 6140 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 6141 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 6142 | "BtAAAAAAA=\r\n"), |
| 6143 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6144 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6145 | MockRead("You are not authorized to view this page\r\n"), |
| 6146 | |
| 6147 | // Wrong password. |
| 6148 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6149 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 6150 | MockRead("Connection: close\r\n"), |
| 6151 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6152 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6153 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6154 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6155 | }; |
| 6156 | |
| 6157 | MockWrite data_writes3[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6158 | // After restarting with a null identity, this is the |
| 6159 | // request we should be issuing -- the final header line contains a Type |
| 6160 | // 1 message. |
| 6161 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6162 | "Host: 172.22.68.17\r\n" |
| 6163 | "Connection: keep-alive\r\n" |
| 6164 | "Authorization: NTLM " |
| 6165 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6166 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6167 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 6168 | // (the credentials for the origin server). The second request continues |
| 6169 | // on the same connection. |
| 6170 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6171 | "Host: 172.22.68.17\r\n" |
| 6172 | "Connection: keep-alive\r\n" |
| 6173 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 6174 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 6175 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBO54" |
| 6176 | "dFMVvTHwAAAAAAAAAAAAAAAAAAAACS7sT6Uzw7L0L//WUqlIaVWpbI" |
| 6177 | "+4MUm7c=\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6178 | }; |
| 6179 | |
| 6180 | MockRead data_reads3[] = { |
| 6181 | // The origin server responds with a Type 2 message. |
| 6182 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 6183 | MockRead("WWW-Authenticate: NTLM " |
| 6184 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCL24VN8dgOR8AAAAAAAAAALo" |
| 6185 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 6186 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 6187 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 6188 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 6189 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 6190 | "BtAAAAAAA=\r\n"), |
| 6191 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6192 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6193 | MockRead("You are not authorized to view this page\r\n"), |
| 6194 | |
| 6195 | // Lastly we get the desired content. |
| 6196 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6197 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 6198 | MockRead("Content-Length: 13\r\n\r\n"), |
| 6199 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6200 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6201 | }; |
| 6202 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6203 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6204 | data_writes1, arraysize(data_writes1)); |
| 6205 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6206 | data_writes2, arraysize(data_writes2)); |
| 6207 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6208 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6209 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6210 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6211 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6212 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6213 | TestCompletionCallback callback1; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6214 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6215 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6216 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6217 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6218 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6219 | |
| 6220 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6221 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6222 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6223 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6224 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6225 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6226 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6227 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6228 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6229 | TestCompletionCallback callback2; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6230 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6231 | // Enter the wrong password. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6232 | rv = trans.RestartWithAuth(AuthCredentials(kTestingNTLM, kWrongPassword), |
| 6233 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6234 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6235 | |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6236 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6237 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6238 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6239 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6240 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6241 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6242 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6243 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6244 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6245 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6246 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6247 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6248 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6249 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6250 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6251 | TestCompletionCallback callback4; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6252 | |
| 6253 | // Now enter the right password. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6254 | rv = trans.RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
| 6255 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6256 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6257 | |
| 6258 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6259 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6260 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6261 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6262 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6263 | TestCompletionCallback callback5; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6264 | |
| 6265 | // One more roundtrip |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6266 | rv = trans.RestartWithAuth(AuthCredentials(), callback5.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6267 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6268 | |
| 6269 | rv = callback5.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6270 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6271 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6272 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6273 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6274 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 6275 | } |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6276 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6277 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6278 | // Test reading a server response which has only headers, and no body. |
| 6279 | // After some maximum number of bytes is consumed, the transaction should |
| 6280 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6281 | TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6282 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6283 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6284 | request.url = GURL("http://www.example.org/"); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6285 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6286 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6287 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6288 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 6289 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 6290 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 6291 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6292 | |
| 6293 | MockRead data_reads[] = { |
| 6294 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6295 | MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6296 | MockRead("\r\nBODY"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6297 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6298 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6299 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6300 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6301 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6302 | TestCompletionCallback callback; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6303 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6304 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6305 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6306 | |
| 6307 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6308 | EXPECT_THAT(rv, IsError(ERR_RESPONSE_HEADERS_TOO_BIG)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6309 | } |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6310 | |
| 6311 | // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 6312 | // establish tunnel. |
| 6313 | // http://code.google.com/p/chromium/issues/detail?id=3772 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6314 | TEST_F(HttpNetworkTransactionTest, DontRecycleTransportSocketForSSLTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6315 | HttpRequestInfo request; |
| 6316 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6317 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6318 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6319 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 6320 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 6321 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6322 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6323 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6324 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6325 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6326 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6327 | // Since we have proxy, should try to establish tunnel. |
| 6328 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 6329 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6330 | "Host: www.example.org:443\r\n" |
| 6331 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6332 | }; |
| 6333 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 6334 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6335 | // connection. Usually a proxy would return 501 (not implemented), |
| 6336 | // or 200 (tunnel established). |
| 6337 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 6338 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 6339 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6340 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6341 | }; |
| 6342 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6343 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6344 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6345 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6346 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6347 | TestCompletionCallback callback1; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6348 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6349 | int rv = trans->Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6350 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6351 | |
| 6352 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6353 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6354 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6355 | // Empty the current queue. This is necessary because idle sockets are |
| 6356 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6357 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6358 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6359 | // We now check to make sure the TCPClientSocket was not added back to |
| 6360 | // the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6361 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6362 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6363 | base::RunLoop().RunUntilIdle(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6364 | // Make sure that the socket didn't get recycled after calling the destructor. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6365 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6366 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6367 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6368 | // Make sure that we recycle a socket after reading all of the response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6369 | TEST_F(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6370 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6371 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6372 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6373 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6374 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6375 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6376 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6377 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6378 | MockRead data_reads[] = { |
| 6379 | // A part of the response body is received with the response headers. |
| 6380 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 6381 | // The rest of the response body is received in two parts. |
| 6382 | MockRead("lo"), |
| 6383 | MockRead(" world"), |
| 6384 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6385 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6386 | }; |
| 6387 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6388 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6389 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6390 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6391 | TestCompletionCallback callback; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6392 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6393 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6394 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6395 | |
| 6396 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6397 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6398 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6399 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6400 | ASSERT_TRUE(response); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6401 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6402 | EXPECT_TRUE(response->headers); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6403 | std::string status_line = response->headers->GetStatusLine(); |
| 6404 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 6405 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6406 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6407 | |
| 6408 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6409 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6410 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6411 | EXPECT_EQ("hello world", response_data); |
| 6412 | |
| 6413 | // Empty the current queue. This is necessary because idle sockets are |
| 6414 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6415 | base::RunLoop().RunUntilIdle(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6416 | |
| 6417 | // 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] | 6418 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6419 | } |
| 6420 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6421 | // Make sure that we recycle a SSL socket after reading all of the response |
| 6422 | // body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6423 | TEST_F(HttpNetworkTransactionTest, RecycleSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6424 | HttpRequestInfo request; |
| 6425 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6426 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6427 | |
| 6428 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6429 | MockWrite( |
| 6430 | "GET / HTTP/1.1\r\n" |
| 6431 | "Host: www.example.org\r\n" |
| 6432 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6433 | }; |
| 6434 | |
| 6435 | MockRead data_reads[] = { |
| 6436 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6437 | MockRead("Content-Length: 11\r\n\r\n"), |
| 6438 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6439 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6440 | }; |
| 6441 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6442 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6443 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6444 | |
| 6445 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6446 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6447 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6448 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6449 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6450 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6451 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6452 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6453 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6454 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6455 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6456 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6457 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6458 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6459 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6460 | ASSERT_TRUE(response); |
| 6461 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6462 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6463 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6464 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6465 | |
| 6466 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6467 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6468 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6469 | EXPECT_EQ("hello world", response_data); |
| 6470 | |
| 6471 | // Empty the current queue. This is necessary because idle sockets are |
| 6472 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6473 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6474 | |
| 6475 | // 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] | 6476 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6477 | } |
| 6478 | |
| 6479 | // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it |
| 6480 | // from the pool and make sure that we recover okay. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6481 | TEST_F(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6482 | HttpRequestInfo request; |
| 6483 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6484 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6485 | |
| 6486 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6487 | MockWrite( |
| 6488 | "GET / HTTP/1.1\r\n" |
| 6489 | "Host: www.example.org\r\n" |
| 6490 | "Connection: keep-alive\r\n\r\n"), |
| 6491 | MockWrite( |
| 6492 | "GET / HTTP/1.1\r\n" |
| 6493 | "Host: www.example.org\r\n" |
| 6494 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6495 | }; |
| 6496 | |
| 6497 | MockRead data_reads[] = { |
mmenke | 911ee022 | 2015-12-04 03:58:42 | [diff] [blame] | 6498 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 6499 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6500 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6501 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6502 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6503 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6504 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6505 | |
| 6506 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6507 | data_writes, arraysize(data_writes)); |
| 6508 | StaticSocketDataProvider data2(data_reads, arraysize(data_reads), |
| 6509 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6510 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6511 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6512 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6513 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6514 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6515 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6516 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6517 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6518 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6519 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6520 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6521 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6522 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6523 | |
| 6524 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6525 | ASSERT_TRUE(response); |
| 6526 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6527 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6528 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6529 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6530 | |
| 6531 | std::string response_data; |
| 6532 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6533 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6534 | EXPECT_EQ("hello world", response_data); |
| 6535 | |
| 6536 | // Empty the current queue. This is necessary because idle sockets are |
| 6537 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6538 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6539 | |
| 6540 | // 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] | 6541 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6542 | |
| 6543 | // Now start the second transaction, which should reuse the previous socket. |
| 6544 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6545 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6546 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6547 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6548 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6549 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6550 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6551 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6552 | |
| 6553 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6554 | ASSERT_TRUE(response); |
| 6555 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6556 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6557 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6558 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6559 | |
| 6560 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6561 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6562 | EXPECT_EQ("hello world", response_data); |
| 6563 | |
| 6564 | // Empty the current queue. This is necessary because idle sockets are |
| 6565 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6566 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6567 | |
| 6568 | // 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] | 6569 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6570 | } |
| 6571 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6572 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 6573 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6574 | TEST_F(HttpNetworkTransactionTest, FlushSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6575 | HttpRequestInfo request; |
| 6576 | request.method = "GET"; |
| 6577 | request.url = GURL("http://www.example.org/"); |
| 6578 | request.load_flags = 0; |
| 6579 | |
| 6580 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6581 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6582 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6583 | |
| 6584 | MockRead data_reads[] = { |
| 6585 | // A part of the response body is received with the response headers. |
| 6586 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 6587 | // The rest of the response body is received in two parts. |
| 6588 | MockRead("lo"), MockRead(" world"), |
| 6589 | MockRead("junk"), // Should not be read!! |
| 6590 | MockRead(SYNCHRONOUS, OK), |
| 6591 | }; |
| 6592 | |
| 6593 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 6594 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6595 | |
| 6596 | TestCompletionCallback callback; |
| 6597 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6598 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6599 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6600 | |
| 6601 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6602 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6603 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6604 | ASSERT_TRUE(response); |
| 6605 | EXPECT_TRUE(response->headers); |
| 6606 | std::string status_line = response->headers->GetStatusLine(); |
| 6607 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 6608 | |
| 6609 | // Make memory critical notification and ensure the transaction still has been |
| 6610 | // operating right. |
| 6611 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 6612 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 6613 | base::RunLoop().RunUntilIdle(); |
| 6614 | |
| 6615 | // Socket should not be flushed as long as it is not idle. |
| 6616 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 6617 | |
| 6618 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6619 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6620 | EXPECT_THAT(rv, IsOk()); |
| 6621 | EXPECT_EQ("hello world", response_data); |
| 6622 | |
| 6623 | // Empty the current queue. This is necessary because idle sockets are |
| 6624 | // added to the connection pool asynchronously with a PostTask. |
| 6625 | base::RunLoop().RunUntilIdle(); |
| 6626 | |
| 6627 | // We now check to make sure the socket was added back to the pool. |
| 6628 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 6629 | |
| 6630 | // Idle sockets should be flushed now. |
| 6631 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 6632 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 6633 | base::RunLoop().RunUntilIdle(); |
| 6634 | |
| 6635 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 6636 | } |
| 6637 | |
| 6638 | // Grab an SSL socket, use it, and put it back into the pool. Then, make |
| 6639 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6640 | TEST_F(HttpNetworkTransactionTest, FlushSSLSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6641 | HttpRequestInfo request; |
| 6642 | request.method = "GET"; |
| 6643 | request.url = GURL("https://www.example.org/"); |
| 6644 | request.load_flags = 0; |
| 6645 | |
| 6646 | MockWrite data_writes[] = { |
| 6647 | MockWrite("GET / HTTP/1.1\r\n" |
| 6648 | "Host: www.example.org\r\n" |
| 6649 | "Connection: keep-alive\r\n\r\n"), |
| 6650 | }; |
| 6651 | |
| 6652 | MockRead data_reads[] = { |
| 6653 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 6654 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
| 6655 | |
| 6656 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6657 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6658 | |
| 6659 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 6660 | arraysize(data_writes)); |
| 6661 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6662 | |
| 6663 | TestCompletionCallback callback; |
| 6664 | |
| 6665 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6666 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6667 | |
| 6668 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6669 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6670 | |
| 6671 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6672 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6673 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6674 | ASSERT_TRUE(response); |
| 6675 | ASSERT_TRUE(response->headers); |
| 6676 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6677 | |
| 6678 | // Make memory critical notification and ensure the transaction still has been |
| 6679 | // operating right. |
| 6680 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 6681 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 6682 | base::RunLoop().RunUntilIdle(); |
| 6683 | |
| 6684 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 6685 | |
| 6686 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6687 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6688 | EXPECT_THAT(rv, IsOk()); |
| 6689 | EXPECT_EQ("hello world", response_data); |
| 6690 | |
| 6691 | // Empty the current queue. This is necessary because idle sockets are |
| 6692 | // added to the connection pool asynchronously with a PostTask. |
| 6693 | base::RunLoop().RunUntilIdle(); |
| 6694 | |
| 6695 | // We now check to make sure the socket was added back to the pool. |
| 6696 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 6697 | |
| 6698 | // Make memory notification once again and ensure idle socket is closed. |
| 6699 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 6700 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 6701 | base::RunLoop().RunUntilIdle(); |
| 6702 | |
| 6703 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 6704 | } |
| 6705 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6706 | // Make sure that we recycle a socket after a zero-length response. |
| 6707 | // http://crbug.com/9880 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6708 | TEST_F(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6709 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6710 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6711 | request.url = GURL( |
| 6712 | "http://www.example.org/csi?v=3&s=web&action=&" |
| 6713 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 6714 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 6715 | "rt=prt.2642,ol.2649,xjs.2951"); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6716 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6717 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6718 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6719 | MockRead data_reads[] = { |
| 6720 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 6721 | "Content-Length: 0\r\n" |
| 6722 | "Content-Type: text/html\r\n\r\n"), |
| 6723 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6724 | MockRead(SYNCHRONOUS, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6725 | }; |
| 6726 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6727 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6728 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6729 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 6730 | // Transaction must be created after the MockReads, so it's destroyed before |
| 6731 | // them. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6732 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 6733 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6734 | TestCompletionCallback callback; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6735 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6736 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6737 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6738 | |
| 6739 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6740 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6741 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6742 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6743 | ASSERT_TRUE(response); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6744 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6745 | EXPECT_TRUE(response->headers); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6746 | std::string status_line = response->headers->GetStatusLine(); |
| 6747 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 6748 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6749 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6750 | |
| 6751 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6752 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6753 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6754 | EXPECT_EQ("", response_data); |
| 6755 | |
| 6756 | // Empty the current queue. This is necessary because idle sockets are |
| 6757 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6758 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6759 | |
| 6760 | // 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] | 6761 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6762 | } |
| 6763 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6764 | TEST_F(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6765 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 6766 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6767 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 6768 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 6769 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6770 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6771 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 6772 | // after use. |
| 6773 | request[0].method = "GET"; |
| 6774 | request[0].url = GURL("http://www.google.com/"); |
| 6775 | request[0].load_flags = 0; |
| 6776 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 6777 | // transaction 1. The first attempts fails when writing the POST data. |
| 6778 | // This causes the transaction to retry with a new socket. The second |
| 6779 | // attempt succeeds. |
| 6780 | request[1].method = "POST"; |
| 6781 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 6782 | request[1].upload_data_stream = &upload_data_stream; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6783 | request[1].load_flags = 0; |
| 6784 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6785 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6786 | |
| 6787 | // The first socket is used for transaction 1 and the first attempt of |
| 6788 | // transaction 2. |
| 6789 | |
| 6790 | // The response of transaction 1. |
| 6791 | MockRead data_reads1[] = { |
| 6792 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 6793 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6794 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6795 | }; |
| 6796 | // The mock write results of transaction 1 and the first attempt of |
| 6797 | // transaction 2. |
| 6798 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6799 | MockWrite(SYNCHRONOUS, 64), // GET |
| 6800 | MockWrite(SYNCHRONOUS, 93), // POST |
| 6801 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6802 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6803 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6804 | data_writes1, arraysize(data_writes1)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6805 | |
| 6806 | // The second socket is used for the second attempt of transaction 2. |
| 6807 | |
| 6808 | // The response of transaction 2. |
| 6809 | MockRead data_reads2[] = { |
| 6810 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 6811 | MockRead("welcome"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6812 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6813 | }; |
| 6814 | // The mock write results of the second attempt of transaction 2. |
| 6815 | MockWrite data_writes2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6816 | MockWrite(SYNCHRONOUS, 93), // POST |
| 6817 | MockWrite(SYNCHRONOUS, 3), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6818 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6819 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6820 | data_writes2, arraysize(data_writes2)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6821 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6822 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6823 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6824 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 6825 | const char* const kExpectedResponseData[] = { |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6826 | "hello world", "welcome" |
| 6827 | }; |
| 6828 | |
| 6829 | for (int i = 0; i < 2; ++i) { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6830 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6831 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6832 | TestCompletionCallback callback; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6833 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6834 | int rv = trans.Start(&request[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6835 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6836 | |
| 6837 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6838 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6839 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6840 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6841 | ASSERT_TRUE(response); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6842 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6843 | EXPECT_TRUE(response->headers); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6844 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6845 | |
| 6846 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6847 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6848 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6849 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 6850 | } |
| 6851 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6852 | |
| 6853 | // Test the request-challenge-retry sequence for basic auth when there is |
| 6854 | // 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] | 6855 | // it fails the identity from the URL is used to answer the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6856 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6857 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6858 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6859 | request.url = GURL("http://foo:b@[email protected]/"); |
[email protected] | 7b08ba6 | 2012-02-10 20:19:41 | [diff] [blame] | 6860 | request.load_flags = LOAD_NORMAL; |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 6861 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6862 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6863 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6864 | |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 6865 | // The password contains an escaped character -- for this test to pass it |
| 6866 | // will need to be unescaped by HttpNetworkTransaction. |
| 6867 | EXPECT_EQ("b%40r", request.url.password()); |
| 6868 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6869 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6870 | MockWrite( |
| 6871 | "GET / HTTP/1.1\r\n" |
| 6872 | "Host: www.example.org\r\n" |
| 6873 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6874 | }; |
| 6875 | |
| 6876 | MockRead data_reads1[] = { |
| 6877 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6878 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6879 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6880 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6881 | }; |
| 6882 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6883 | // After the challenge above, the transaction will be restarted using the |
| 6884 | // identity from the url (foo, b@r) to answer the challenge. |
| 6885 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6886 | MockWrite( |
| 6887 | "GET / HTTP/1.1\r\n" |
| 6888 | "Host: www.example.org\r\n" |
| 6889 | "Connection: keep-alive\r\n" |
| 6890 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6891 | }; |
| 6892 | |
| 6893 | MockRead data_reads2[] = { |
| 6894 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6895 | MockRead("Content-Length: 100\r\n\r\n"), |
| 6896 | MockRead(SYNCHRONOUS, OK), |
| 6897 | }; |
| 6898 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6899 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6900 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6901 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6902 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6903 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6904 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6905 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6906 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6907 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6908 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6909 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6910 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6911 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6912 | |
| 6913 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6914 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6915 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6916 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6917 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6918 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6919 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6920 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6921 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6922 | |
| 6923 | // There is no challenge info, since the identity in URL worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6924 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6925 | |
| 6926 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6927 | |
| 6928 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6929 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6930 | } |
| 6931 | |
| 6932 | // Test the request-challenge-retry sequence for basic auth when there is an |
| 6933 | // incorrect identity in the URL. The identity from the URL should be used only |
| 6934 | // once. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6935 | TEST_F(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6936 | HttpRequestInfo request; |
| 6937 | request.method = "GET"; |
| 6938 | // Note: the URL has a username:password in it. The password "baz" is |
| 6939 | // wrong (should be "bar"). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6940 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6941 | |
| 6942 | request.load_flags = LOAD_NORMAL; |
| 6943 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6944 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6945 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6946 | |
| 6947 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6948 | MockWrite( |
| 6949 | "GET / HTTP/1.1\r\n" |
| 6950 | "Host: www.example.org\r\n" |
| 6951 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6952 | }; |
| 6953 | |
| 6954 | MockRead data_reads1[] = { |
| 6955 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6956 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6957 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6958 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 6959 | }; |
| 6960 | |
| 6961 | // After the challenge above, the transaction will be restarted using the |
| 6962 | // identity from the url (foo, baz) to answer the challenge. |
| 6963 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6964 | MockWrite( |
| 6965 | "GET / HTTP/1.1\r\n" |
| 6966 | "Host: www.example.org\r\n" |
| 6967 | "Connection: keep-alive\r\n" |
| 6968 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6969 | }; |
| 6970 | |
| 6971 | MockRead data_reads2[] = { |
| 6972 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6973 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6974 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6975 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 6976 | }; |
| 6977 | |
| 6978 | // After the challenge above, the transaction will be restarted using the |
| 6979 | // identity supplied by the user (foo, bar) to answer the challenge. |
| 6980 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6981 | MockWrite( |
| 6982 | "GET / HTTP/1.1\r\n" |
| 6983 | "Host: www.example.org\r\n" |
| 6984 | "Connection: keep-alive\r\n" |
| 6985 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 6986 | }; |
| 6987 | |
| 6988 | MockRead data_reads3[] = { |
| 6989 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6990 | MockRead("Content-Length: 100\r\n\r\n"), |
| 6991 | MockRead(SYNCHRONOUS, OK), |
| 6992 | }; |
| 6993 | |
| 6994 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6995 | data_writes1, arraysize(data_writes1)); |
| 6996 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6997 | data_writes2, arraysize(data_writes2)); |
| 6998 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6999 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7000 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7001 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7002 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7003 | |
| 7004 | TestCompletionCallback callback1; |
| 7005 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7006 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7007 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7008 | |
| 7009 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7010 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7011 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7012 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7013 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7014 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7015 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7016 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7017 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7018 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7019 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7020 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7021 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7022 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 7023 | |
| 7024 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7025 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7026 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7027 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7028 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7029 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7030 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7031 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7032 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7033 | |
| 7034 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7035 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7036 | |
| 7037 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7038 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 7039 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7040 | base::RunLoop().RunUntilIdle(); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 7041 | } |
| 7042 | |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7043 | |
| 7044 | // Test the request-challenge-retry sequence for basic auth when there is a |
| 7045 | // correct identity in the URL, but its use is being suppressed. The identity |
| 7046 | // from the URL should never be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7047 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURLSuppressed) { |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7048 | HttpRequestInfo request; |
| 7049 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7050 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7051 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
| 7052 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7053 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7054 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7055 | |
| 7056 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7057 | MockWrite( |
| 7058 | "GET / HTTP/1.1\r\n" |
| 7059 | "Host: www.example.org\r\n" |
| 7060 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7061 | }; |
| 7062 | |
| 7063 | MockRead data_reads1[] = { |
| 7064 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7065 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7066 | MockRead("Content-Length: 10\r\n\r\n"), |
| 7067 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 7068 | }; |
| 7069 | |
| 7070 | // After the challenge above, the transaction will be restarted using the |
| 7071 | // identity supplied by the user, not the one in the URL, to answer the |
| 7072 | // challenge. |
| 7073 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7074 | MockWrite( |
| 7075 | "GET / HTTP/1.1\r\n" |
| 7076 | "Host: www.example.org\r\n" |
| 7077 | "Connection: keep-alive\r\n" |
| 7078 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7079 | }; |
| 7080 | |
| 7081 | MockRead data_reads3[] = { |
| 7082 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7083 | MockRead("Content-Length: 100\r\n\r\n"), |
| 7084 | MockRead(SYNCHRONOUS, OK), |
| 7085 | }; |
| 7086 | |
| 7087 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7088 | data_writes1, arraysize(data_writes1)); |
| 7089 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 7090 | data_writes3, arraysize(data_writes3)); |
| 7091 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7092 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 7093 | |
| 7094 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7095 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7096 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7097 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7098 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7099 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7100 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7101 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7102 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7103 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 7104 | |
| 7105 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7106 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7107 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7108 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7109 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7110 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7111 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7112 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7113 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7114 | |
| 7115 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7116 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7117 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7118 | |
| 7119 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7120 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7121 | } |
| 7122 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7123 | // Test that previously tried username/passwords for a realm get re-used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7124 | TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7125 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7126 | |
| 7127 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 7128 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7129 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7130 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7131 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7132 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7133 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7134 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7135 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7136 | MockWrite( |
| 7137 | "GET /x/y/z HTTP/1.1\r\n" |
| 7138 | "Host: www.example.org\r\n" |
| 7139 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7140 | }; |
| 7141 | |
| 7142 | MockRead data_reads1[] = { |
| 7143 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7144 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7145 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7146 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7147 | }; |
| 7148 | |
| 7149 | // Resend with authorization (username=foo, password=bar) |
| 7150 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7151 | MockWrite( |
| 7152 | "GET /x/y/z HTTP/1.1\r\n" |
| 7153 | "Host: www.example.org\r\n" |
| 7154 | "Connection: keep-alive\r\n" |
| 7155 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7156 | }; |
| 7157 | |
| 7158 | // Sever accepts the authorization. |
| 7159 | MockRead data_reads2[] = { |
| 7160 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7161 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7162 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7163 | }; |
| 7164 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7165 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7166 | data_writes1, arraysize(data_writes1)); |
| 7167 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7168 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7169 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7170 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7171 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7172 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7173 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7174 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7175 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7176 | |
| 7177 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7178 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7179 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7180 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7181 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7182 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[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(kFoo, kBar), |
| 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 2: authenticate (foo2, bar2) on MyRealm2 |
| 7202 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7203 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7204 | request.method = "GET"; |
| 7205 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 7206 | // protection space as MyRealm1. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7207 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7208 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7209 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7210 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7211 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7212 | MockWrite( |
| 7213 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 7214 | "Host: www.example.org\r\n" |
| 7215 | "Connection: keep-alive\r\n" |
| 7216 | // Send preemptive authorization for MyRealm1 |
| 7217 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7218 | }; |
| 7219 | |
| 7220 | // The server didn't like the preemptive authorization, and |
| 7221 | // challenges us for a different realm (MyRealm2). |
| 7222 | MockRead data_reads1[] = { |
| 7223 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7224 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 7225 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7226 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7227 | }; |
| 7228 | |
| 7229 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 7230 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7231 | MockWrite( |
| 7232 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 7233 | "Host: www.example.org\r\n" |
| 7234 | "Connection: keep-alive\r\n" |
| 7235 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7236 | }; |
| 7237 | |
| 7238 | // Sever accepts the authorization. |
| 7239 | MockRead data_reads2[] = { |
| 7240 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7241 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7242 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7243 | }; |
| 7244 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7245 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7246 | data_writes1, arraysize(data_writes1)); |
| 7247 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7248 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7249 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7250 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7251 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7252 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7253 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7254 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7255 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7256 | |
| 7257 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7258 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7259 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7260 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7261 | ASSERT_TRUE(response); |
| 7262 | ASSERT_TRUE(response->auth_challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7263 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 7264 | EXPECT_EQ("http://www.example.org", |
| 7265 | response->auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7266 | EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 7267 | EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7268 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7269 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7270 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7271 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 7272 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7273 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7274 | |
| 7275 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7276 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7277 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7278 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7279 | ASSERT_TRUE(response); |
| 7280 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7281 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7282 | } |
| 7283 | |
| 7284 | // ------------------------------------------------------------------------ |
| 7285 | |
| 7286 | // Transaction 3: Resend a request in MyRealm's protection space -- |
| 7287 | // succeed with preemptive authorization. |
| 7288 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7289 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7290 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7291 | request.url = GURL("http://www.example.org/x/y/z2"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7292 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7293 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7294 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7295 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7296 | MockWrite( |
| 7297 | "GET /x/y/z2 HTTP/1.1\r\n" |
| 7298 | "Host: www.example.org\r\n" |
| 7299 | "Connection: keep-alive\r\n" |
| 7300 | // The authorization for MyRealm1 gets sent preemptively |
| 7301 | // (since the url is in the same protection space) |
| 7302 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7303 | }; |
| 7304 | |
| 7305 | // Sever accepts the preemptive authorization |
| 7306 | MockRead data_reads1[] = { |
| 7307 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7308 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7309 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7310 | }; |
| 7311 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7312 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7313 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7314 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7315 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7316 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7317 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7318 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7319 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7320 | |
| 7321 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7322 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7323 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7324 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7325 | ASSERT_TRUE(response); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7326 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7327 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7328 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7329 | } |
| 7330 | |
| 7331 | // ------------------------------------------------------------------------ |
| 7332 | |
| 7333 | // Transaction 4: request another URL in MyRealm (however the |
| 7334 | // url is not known to belong to the protection space, so no pre-auth). |
| 7335 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7336 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7337 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7338 | request.url = GURL("http://www.example.org/x/1"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7339 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7340 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7341 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7342 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7343 | MockWrite( |
| 7344 | "GET /x/1 HTTP/1.1\r\n" |
| 7345 | "Host: www.example.org\r\n" |
| 7346 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7347 | }; |
| 7348 | |
| 7349 | MockRead data_reads1[] = { |
| 7350 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7351 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7352 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7353 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7354 | }; |
| 7355 | |
| 7356 | // Resend with authorization from MyRealm's cache. |
| 7357 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7358 | MockWrite( |
| 7359 | "GET /x/1 HTTP/1.1\r\n" |
| 7360 | "Host: www.example.org\r\n" |
| 7361 | "Connection: keep-alive\r\n" |
| 7362 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7363 | }; |
| 7364 | |
| 7365 | // Sever accepts the authorization. |
| 7366 | MockRead data_reads2[] = { |
| 7367 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7368 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7369 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7370 | }; |
| 7371 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7372 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7373 | data_writes1, arraysize(data_writes1)); |
| 7374 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7375 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7376 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7377 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7378 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7379 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7380 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7381 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7382 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7383 | |
| 7384 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7385 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7386 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7387 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7388 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7389 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7390 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7391 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7392 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7393 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7394 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7395 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7396 | ASSERT_TRUE(response); |
| 7397 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7398 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7399 | } |
| 7400 | |
| 7401 | // ------------------------------------------------------------------------ |
| 7402 | |
| 7403 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 7404 | // cached identity. Should invalidate and re-prompt. |
| 7405 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7406 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7407 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7408 | request.url = GURL("http://www.example.org/p/q/t"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7409 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7410 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7411 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7412 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7413 | MockWrite( |
| 7414 | "GET /p/q/t HTTP/1.1\r\n" |
| 7415 | "Host: www.example.org\r\n" |
| 7416 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7417 | }; |
| 7418 | |
| 7419 | MockRead data_reads1[] = { |
| 7420 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7421 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7422 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7423 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7424 | }; |
| 7425 | |
| 7426 | // Resend with authorization from cache for MyRealm. |
| 7427 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7428 | MockWrite( |
| 7429 | "GET /p/q/t HTTP/1.1\r\n" |
| 7430 | "Host: www.example.org\r\n" |
| 7431 | "Connection: keep-alive\r\n" |
| 7432 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7433 | }; |
| 7434 | |
| 7435 | // Sever rejects the authorization. |
| 7436 | MockRead data_reads2[] = { |
| 7437 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7438 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7439 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7440 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7441 | }; |
| 7442 | |
| 7443 | // At this point we should prompt for new credentials for MyRealm. |
| 7444 | // Restart with username=foo3, password=foo4. |
| 7445 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7446 | MockWrite( |
| 7447 | "GET /p/q/t HTTP/1.1\r\n" |
| 7448 | "Host: www.example.org\r\n" |
| 7449 | "Connection: keep-alive\r\n" |
| 7450 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7451 | }; |
| 7452 | |
| 7453 | // Sever accepts the authorization. |
| 7454 | MockRead data_reads3[] = { |
| 7455 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7456 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7457 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7458 | }; |
| 7459 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7460 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7461 | data_writes1, arraysize(data_writes1)); |
| 7462 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7463 | data_writes2, arraysize(data_writes2)); |
| 7464 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 7465 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7466 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7467 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7468 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7469 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7470 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7471 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7472 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7473 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7474 | |
| 7475 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7476 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7477 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7478 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7479 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7480 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7481 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7482 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7483 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7484 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7485 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7486 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7487 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7488 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7489 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7490 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7491 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7492 | rv = trans.RestartWithAuth(AuthCredentials(kFoo3, kBar3), |
| 7493 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7494 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7495 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7496 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7497 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7498 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7499 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7500 | ASSERT_TRUE(response); |
| 7501 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7502 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7503 | } |
| 7504 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7505 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7506 | // Tests that nonce count increments when multiple auth attempts |
| 7507 | // are started with the same nonce. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7508 | TEST_F(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { |
[email protected] | 54fea256 | 2010-11-17 14:40:44 | [diff] [blame] | 7509 | HttpAuthHandlerDigest::Factory* digest_factory = |
| 7510 | new HttpAuthHandlerDigest::Factory(); |
| 7511 | HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = |
| 7512 | new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); |
| 7513 | digest_factory->set_nonce_generator(nonce_generator); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7514 | session_deps_.http_auth_handler_factory.reset(digest_factory); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7515 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7516 | |
| 7517 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 7518 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7519 | HttpRequestInfo request; |
| 7520 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7521 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7522 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7523 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7524 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7525 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7526 | MockWrite( |
| 7527 | "GET /x/y/z HTTP/1.1\r\n" |
| 7528 | "Host: www.example.org\r\n" |
| 7529 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7530 | }; |
| 7531 | |
| 7532 | MockRead data_reads1[] = { |
| 7533 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7534 | MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " |
| 7535 | "algorithm=MD5, qop=\"auth\"\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7536 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7537 | }; |
| 7538 | |
| 7539 | // Resend with authorization (username=foo, password=bar) |
| 7540 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7541 | MockWrite( |
| 7542 | "GET /x/y/z HTTP/1.1\r\n" |
| 7543 | "Host: www.example.org\r\n" |
| 7544 | "Connection: keep-alive\r\n" |
| 7545 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 7546 | "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " |
| 7547 | "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " |
| 7548 | "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7549 | }; |
| 7550 | |
| 7551 | // Sever accepts the authorization. |
| 7552 | MockRead data_reads2[] = { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 7553 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7554 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7555 | }; |
| 7556 | |
| 7557 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7558 | data_writes1, arraysize(data_writes1)); |
| 7559 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7560 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7561 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7562 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7563 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7564 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7565 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7566 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7567 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7568 | |
| 7569 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7570 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7571 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7572 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7573 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7574 | EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge.get())); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7575 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7576 | TestCompletionCallback callback2; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7577 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7578 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 7579 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7580 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7581 | |
| 7582 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7583 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7584 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7585 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7586 | ASSERT_TRUE(response); |
| 7587 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7588 | } |
| 7589 | |
| 7590 | // ------------------------------------------------------------------------ |
| 7591 | |
| 7592 | // Transaction 2: Request another resource in digestive's protection space. |
| 7593 | // This will preemptively add an Authorization header which should have an |
| 7594 | // "nc" value of 2 (as compared to 1 in the first use. |
| 7595 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7596 | HttpRequestInfo request; |
| 7597 | request.method = "GET"; |
| 7598 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 7599 | // protection space as digest. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7600 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7601 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7602 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7603 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7604 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7605 | MockWrite( |
| 7606 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 7607 | "Host: www.example.org\r\n" |
| 7608 | "Connection: keep-alive\r\n" |
| 7609 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 7610 | "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " |
| 7611 | "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " |
| 7612 | "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7613 | }; |
| 7614 | |
| 7615 | // Sever accepts the authorization. |
| 7616 | MockRead data_reads1[] = { |
| 7617 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7618 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7619 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7620 | }; |
| 7621 | |
| 7622 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7623 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7624 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7625 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7626 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7627 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7628 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7629 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7630 | |
| 7631 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7632 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7633 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7634 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7635 | ASSERT_TRUE(response); |
| 7636 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7637 | } |
| 7638 | } |
| 7639 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7640 | // Test the ResetStateForRestart() private method. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7641 | TEST_F(HttpNetworkTransactionTest, ResetStateForRestart) { |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7642 | // Create a transaction (the dependencies aren't important). |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7643 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7644 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7645 | |
| 7646 | // Setup some state (which we expect ResetStateForRestart() will clear). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7647 | trans.read_buf_ = new IOBuffer(15); |
| 7648 | trans.read_buf_len_ = 15; |
| 7649 | trans.request_headers_.SetHeader("Authorization", "NTLM"); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7650 | |
| 7651 | // Setup state in response_ |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7652 | HttpResponseInfo* response = &trans.response_; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7653 | response->auth_challenge = new AuthChallengeInfo(); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 7654 | response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7655 | response->response_time = base::Time::Now(); |
| 7656 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7657 | |
| 7658 | { // Setup state for response_.vary_data |
| 7659 | HttpRequestInfo request; |
| 7660 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 7661 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 7662 | scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 7663 | request.extra_headers.SetHeader("Foo", "1"); |
| 7664 | request.extra_headers.SetHeader("bar", "23"); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7665 | EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7666 | } |
| 7667 | |
| 7668 | // Cause the above state to be reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7669 | trans.ResetStateForRestart(); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7670 | |
| 7671 | // Verify that the state that needed to be reset, has been reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7672 | EXPECT_FALSE(trans.read_buf_); |
| 7673 | EXPECT_EQ(0, trans.read_buf_len_); |
| 7674 | EXPECT_TRUE(trans.request_headers_.IsEmpty()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7675 | EXPECT_FALSE(response->auth_challenge); |
| 7676 | EXPECT_FALSE(response->headers); |
[email protected] | 34f4094 | 2010-10-04 00:34:04 | [diff] [blame] | 7677 | EXPECT_FALSE(response->was_cached); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 7678 | EXPECT_EQ(0U, response->ssl_info.cert_status); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7679 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7680 | } |
| 7681 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7682 | // Test HTTPS connections to a site with a bad certificate |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7683 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7684 | HttpRequestInfo request; |
| 7685 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7686 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7687 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7688 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7689 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7690 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7691 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7692 | MockWrite( |
| 7693 | "GET / HTTP/1.1\r\n" |
| 7694 | "Host: www.example.org\r\n" |
| 7695 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7696 | }; |
| 7697 | |
| 7698 | MockRead data_reads[] = { |
| 7699 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7700 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7701 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7702 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7703 | }; |
| 7704 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 7705 | StaticSocketDataProvider ssl_bad_certificate; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7706 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7707 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7708 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 7709 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7710 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7711 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 7712 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7713 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 7714 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7715 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7716 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7717 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7718 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7719 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7720 | |
| 7721 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7722 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7723 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7724 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7725 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7726 | |
| 7727 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7728 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7729 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7730 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7731 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7732 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7733 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7734 | } |
| 7735 | |
| 7736 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 7737 | // proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7738 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7739 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7740 | |
| 7741 | HttpRequestInfo request; |
| 7742 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7743 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7744 | |
| 7745 | MockWrite proxy_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7746 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7747 | "Host: www.example.org:443\r\n" |
| 7748 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7749 | }; |
| 7750 | |
| 7751 | MockRead proxy_reads[] = { |
| 7752 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7753 | MockRead(SYNCHRONOUS, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7754 | }; |
| 7755 | |
| 7756 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7757 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7758 | "Host: www.example.org:443\r\n" |
| 7759 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7760 | MockWrite("GET / HTTP/1.1\r\n" |
| 7761 | "Host: www.example.org\r\n" |
| 7762 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7763 | }; |
| 7764 | |
| 7765 | MockRead data_reads[] = { |
| 7766 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 7767 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7768 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7769 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7770 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7771 | }; |
| 7772 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7773 | StaticSocketDataProvider ssl_bad_certificate( |
| 7774 | proxy_reads, arraysize(proxy_reads), |
| 7775 | proxy_writes, arraysize(proxy_writes)); |
| 7776 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7777 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7778 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 7779 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7780 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7781 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 7782 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7783 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 7784 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7785 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7786 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7787 | |
| 7788 | for (int i = 0; i < 2; i++) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7789 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7790 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7791 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7792 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7793 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7794 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7795 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7796 | |
| 7797 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7798 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7799 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7800 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7801 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7802 | |
| 7803 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7804 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7805 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7806 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7807 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7808 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7809 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7810 | } |
| 7811 | } |
| 7812 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7813 | |
| 7814 | // Test HTTPS connections to a site, going through an HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7815 | TEST_F(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7816 | session_deps_.proxy_service = |
| 7817 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7818 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7819 | session_deps_.net_log = &net_log; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7820 | |
| 7821 | HttpRequestInfo request; |
| 7822 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7823 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7824 | |
| 7825 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7826 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7827 | "Host: www.example.org:443\r\n" |
| 7828 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7829 | MockWrite("GET / HTTP/1.1\r\n" |
| 7830 | "Host: www.example.org\r\n" |
| 7831 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7832 | }; |
| 7833 | |
| 7834 | MockRead data_reads[] = { |
| 7835 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 7836 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7837 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7838 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7839 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7840 | }; |
| 7841 | |
| 7842 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7843 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7844 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 7845 | SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7846 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7847 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7848 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 7849 | session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7850 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7851 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7852 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7853 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7854 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7855 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7856 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7857 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7858 | |
| 7859 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7860 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7861 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7862 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7863 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7864 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 7865 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7866 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 7867 | EXPECT_EQ(200, response->headers->response_code()); |
| 7868 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7869 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7870 | |
| 7871 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7872 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7873 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 7874 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7875 | } |
| 7876 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7877 | // Test an HTTPS Proxy's ability to redirect a CONNECT request |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7878 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7879 | session_deps_.proxy_service = |
| 7880 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7881 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7882 | session_deps_.net_log = &net_log; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7883 | |
| 7884 | HttpRequestInfo request; |
| 7885 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7886 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7887 | |
| 7888 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7889 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7890 | "Host: www.example.org:443\r\n" |
| 7891 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7892 | }; |
| 7893 | |
| 7894 | MockRead data_reads[] = { |
| 7895 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 7896 | MockRead("Location: http://login.example.com/\r\n"), |
| 7897 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7898 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7899 | }; |
| 7900 | |
| 7901 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7902 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7903 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7904 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7905 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7906 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7907 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7908 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7909 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7910 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7911 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7912 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7913 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7914 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7915 | |
| 7916 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7917 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7918 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7919 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7920 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7921 | |
| 7922 | EXPECT_EQ(302, response->headers->response_code()); |
| 7923 | std::string url; |
| 7924 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 7925 | EXPECT_EQ("http://login.example.com/", url); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7926 | |
| 7927 | // In the case of redirects from proxies, HttpNetworkTransaction returns |
| 7928 | // timing for the proxy connection instead of the connection to the host, |
| 7929 | // and no send / receive times. |
| 7930 | // See HttpNetworkTransaction::OnHttpsProxyTunnelResponse. |
| 7931 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7932 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7933 | |
| 7934 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 7935 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 7936 | |
| 7937 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 7938 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 7939 | load_timing_info.proxy_resolve_end); |
| 7940 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 7941 | load_timing_info.connect_timing.connect_start); |
| 7942 | ExpectConnectTimingHasTimes( |
| 7943 | load_timing_info.connect_timing, |
| 7944 | CONNECT_TIMING_HAS_DNS_TIMES | CONNECT_TIMING_HAS_SSL_TIMES); |
| 7945 | |
| 7946 | EXPECT_TRUE(load_timing_info.send_start.is_null()); |
| 7947 | EXPECT_TRUE(load_timing_info.send_end.is_null()); |
| 7948 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7949 | } |
| 7950 | |
| 7951 | // Test an HTTPS (SPDY) Proxy's ability to redirect a CONNECT request |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7952 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7953 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7954 | |
| 7955 | HttpRequestInfo request; |
| 7956 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7957 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7958 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7959 | SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7960 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7961 | SpdySerializedFrame goaway( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 7962 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7963 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7964 | CreateMockWrite(conn, 0, SYNCHRONOUS), |
| 7965 | CreateMockWrite(goaway, 2, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7966 | }; |
| 7967 | |
| 7968 | static const char* const kExtraHeaders[] = { |
| 7969 | "location", |
| 7970 | "http://login.example.com/", |
| 7971 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 7972 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
bnc | c9f762a | 2016-12-06 20:38:23 | [diff] [blame] | 7973 | "302", kExtraHeaders, arraysize(kExtraHeaders) / 2, 1)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7974 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 7975 | CreateMockRead(resp, 1), MockRead(ASYNC, 0, 3), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7976 | }; |
| 7977 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 7978 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 7979 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7980 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 7981 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7982 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7983 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7984 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7985 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7986 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7987 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7988 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7989 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7990 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7991 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7992 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7993 | |
| 7994 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7995 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7996 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7997 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7998 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 7999 | |
| 8000 | EXPECT_EQ(302, response->headers->response_code()); |
| 8001 | std::string url; |
| 8002 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 8003 | EXPECT_EQ("http://login.example.com/", url); |
| 8004 | } |
| 8005 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 8006 | // Test that an HTTPS proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8007 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8008 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8009 | |
| 8010 | HttpRequestInfo request; |
| 8011 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8012 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8013 | |
| 8014 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8015 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8016 | "Host: www.example.org:443\r\n" |
| 8017 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8018 | }; |
| 8019 | |
| 8020 | MockRead data_reads[] = { |
| 8021 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 8022 | MockRead("Content-Length: 23\r\n\r\n"), |
| 8023 | MockRead("The host does not exist"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8024 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8025 | }; |
| 8026 | |
| 8027 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8028 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8029 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8030 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8031 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8032 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8033 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8034 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8035 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8036 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8037 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8038 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8039 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8040 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8041 | |
| 8042 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8043 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8044 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 8045 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8046 | } |
| 8047 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 8048 | // Test that a SPDY proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8049 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaSpdyProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8050 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8051 | |
| 8052 | HttpRequestInfo request; |
| 8053 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8054 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8055 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8056 | SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8057 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8058 | SpdySerializedFrame rst( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 8059 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8060 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8061 | CreateMockWrite(conn, 0), CreateMockWrite(rst, 3), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8062 | }; |
| 8063 | |
| 8064 | static const char* const kExtraHeaders[] = { |
| 8065 | "location", |
| 8066 | "http://login.example.com/", |
| 8067 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8068 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
bnc | c9f762a | 2016-12-06 20:38:23 | [diff] [blame] | 8069 | "404", kExtraHeaders, arraysize(kExtraHeaders) / 2, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8070 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 8071 | 1, "The host does not exist", 23, true)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8072 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8073 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8074 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8075 | }; |
| 8076 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8077 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 8078 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8079 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8080 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8081 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8082 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8083 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8084 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8085 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8086 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8087 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8088 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8089 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8090 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8091 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8092 | |
| 8093 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8094 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8095 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 8096 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8097 | } |
| 8098 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8099 | // Test the request-challenge-retry sequence for basic auth, through |
| 8100 | // a SPDY proxy over a single SPDY session. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8101 | TEST_F(HttpNetworkTransactionTest, BasicAuthSpdyProxy) { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8102 | HttpRequestInfo request; |
| 8103 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8104 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8105 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 8106 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8107 | |
| 8108 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8109 | session_deps_.proxy_service = |
| 8110 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8111 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8112 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8113 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8114 | |
| 8115 | // Since we have proxy, should try to establish tunnel. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8116 | SpdySerializedFrame req(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8117 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8118 | SpdySerializedFrame rst( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 8119 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 8120 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8121 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8122 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8123 | // be issuing -- the final header line contains the credentials. |
| 8124 | const char* const kAuthCredentials[] = { |
| 8125 | "proxy-authorization", "Basic Zm9vOmJhcg==", |
| 8126 | }; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8127 | SpdySerializedFrame connect2(spdy_util_.ConstructSpdyConnect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 8128 | kAuthCredentials, arraysize(kAuthCredentials) / 2, 3, LOWEST, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8129 | HostPortPair("www.example.org", 443))); |
| 8130 | // fetch https://www.example.org/ via HTTP |
| 8131 | const char get[] = |
| 8132 | "GET / HTTP/1.1\r\n" |
| 8133 | "Host: www.example.org\r\n" |
| 8134 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8135 | SpdySerializedFrame wrapped_get( |
| 8136 | spdy_util_.ConstructSpdyDataFrame(3, get, strlen(get), false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8137 | |
| 8138 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8139 | CreateMockWrite(req, 0, ASYNC), CreateMockWrite(rst, 2, ASYNC), |
| 8140 | CreateMockWrite(connect2, 3), CreateMockWrite(wrapped_get, 5), |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8141 | }; |
| 8142 | |
| 8143 | // The proxy responds to the connect with a 407, using a persistent |
| 8144 | // connection. |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 8145 | const char kAuthStatus[] = "407"; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8146 | const char* const kAuthChallenge[] = { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8147 | "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 8148 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8149 | SpdySerializedFrame conn_auth_resp(spdy_util_.ConstructSpdyReplyError( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8150 | kAuthStatus, kAuthChallenge, arraysize(kAuthChallenge) / 2, 1)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8151 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8152 | SpdySerializedFrame conn_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8153 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 8154 | "Content-Length: 5\r\n\r\n"; |
| 8155 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8156 | SpdySerializedFrame wrapped_get_resp( |
| 8157 | spdy_util_.ConstructSpdyDataFrame(3, resp, strlen(resp), false)); |
| 8158 | SpdySerializedFrame wrapped_body( |
| 8159 | spdy_util_.ConstructSpdyDataFrame(3, "hello", 5, false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8160 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8161 | CreateMockRead(conn_auth_resp, 1, ASYNC), |
| 8162 | CreateMockRead(conn_resp, 4, ASYNC), |
| 8163 | CreateMockRead(wrapped_get_resp, 6, ASYNC), |
| 8164 | CreateMockRead(wrapped_body, 7, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8165 | MockRead(ASYNC, OK, 8), // EOF. May or may not be read. |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8166 | }; |
| 8167 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8168 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8169 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8170 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8171 | // Negotiate SPDY to the proxy |
| 8172 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8173 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8174 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8175 | // Vanilla SSL to the server |
| 8176 | SSLSocketDataProvider server(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8177 | session_deps_.socket_factory->AddSSLSocketDataProvider(&server); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8178 | |
| 8179 | TestCompletionCallback callback1; |
| 8180 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8181 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8182 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8183 | |
| 8184 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8185 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8186 | |
| 8187 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8188 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 8189 | TestNetLogEntry::List entries; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8190 | log.GetEntries(&entries); |
| 8191 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 8192 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 8193 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8194 | ExpectLogContainsSomewhere( |
| 8195 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 8196 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 8197 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8198 | |
| 8199 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8200 | ASSERT_TRUE(response); |
| 8201 | ASSERT_TRUE(response->headers); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8202 | EXPECT_EQ(407, response->headers->response_code()); |
| 8203 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8204 | EXPECT_TRUE(response->auth_challenge); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 8205 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8206 | |
| 8207 | TestCompletionCallback callback2; |
| 8208 | |
| 8209 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 8210 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8211 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8212 | |
| 8213 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8214 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8215 | |
| 8216 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8217 | ASSERT_TRUE(response); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8218 | |
| 8219 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8220 | EXPECT_EQ(200, response->headers->response_code()); |
| 8221 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 8222 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8223 | |
| 8224 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8225 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8226 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8227 | LoadTimingInfo load_timing_info; |
| 8228 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8229 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8230 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 8231 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8232 | trans.reset(); |
| 8233 | session->CloseAllConnections(); |
| 8234 | } |
| 8235 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8236 | // Test that an explicitly trusted SPDY proxy can push a resource from an |
| 8237 | // origin that is different from that of its associated resource. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8238 | TEST_F(HttpNetworkTransactionTest, CrossOriginSPDYProxyPush) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8239 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8240 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8241 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 8242 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8243 | HttpRequestInfo request; |
| 8244 | HttpRequestInfo push_request; |
| 8245 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8246 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8247 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8248 | push_request.method = "GET"; |
| 8249 | push_request.url = GURL("http://www.another-origin.com/foo.dat"); |
| 8250 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8251 | // Configure against https proxy server "myproxy:443". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8252 | session_deps_.proxy_service = |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8253 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:443"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8254 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8255 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8256 | |
inlinechan | 894515af | 2016-12-09 02:40:10 | [diff] [blame] | 8257 | session_deps_.proxy_delegate = std::move(proxy_delegate); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8258 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8259 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8260 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8261 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 8262 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8263 | SpdySerializedFrame stream2_priority( |
| 8264 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8265 | |
| 8266 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8267 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8268 | CreateMockWrite(stream2_priority, 3, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8269 | }; |
| 8270 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8271 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8272 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8273 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8274 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8275 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8276 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 8277 | NULL, 0, 2, 1, "http://www.another-origin.com/foo.dat")); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8278 | const char kPushedData[] = "pushed"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8279 | SpdySerializedFrame stream2_body(spdy_util_.ConstructSpdyDataFrame( |
| 8280 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8281 | |
| 8282 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8283 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 8284 | CreateMockRead(stream2_syn, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8285 | CreateMockRead(stream1_body, 4, ASYNC), |
| 8286 | CreateMockRead(stream2_body, 5, ASYNC), |
| 8287 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8288 | }; |
| 8289 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8290 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8291 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8292 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8293 | // Negotiate SPDY to the proxy |
| 8294 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8295 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8296 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8297 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8298 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8299 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8300 | TestCompletionCallback callback; |
| 8301 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8302 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8303 | |
| 8304 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8305 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8306 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8307 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8308 | auto push_trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8309 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8310 | rv = push_trans->Start(&push_request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8311 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8312 | |
| 8313 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8314 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8315 | const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); |
| 8316 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8317 | ASSERT_TRUE(response); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8318 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8319 | |
| 8320 | EXPECT_EQ(200, response->headers->response_code()); |
| 8321 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8322 | |
| 8323 | std::string response_data; |
| 8324 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8325 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8326 | EXPECT_EQ("hello!", response_data); |
| 8327 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8328 | LoadTimingInfo load_timing_info; |
| 8329 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8330 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8331 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 8332 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8333 | // Verify the pushed stream. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8334 | EXPECT_TRUE(push_response->headers); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8335 | EXPECT_EQ(200, push_response->headers->response_code()); |
| 8336 | |
| 8337 | rv = ReadTransaction(push_trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8338 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8339 | EXPECT_EQ("pushed", response_data); |
| 8340 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8341 | LoadTimingInfo push_load_timing_info; |
| 8342 | EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); |
| 8343 | TestLoadTimingReusedWithPac(push_load_timing_info); |
| 8344 | // The transactions should share a socket ID, despite being for different |
| 8345 | // origins. |
| 8346 | EXPECT_EQ(load_timing_info.socket_log_id, |
| 8347 | push_load_timing_info.socket_log_id); |
| 8348 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8349 | trans.reset(); |
| 8350 | push_trans.reset(); |
| 8351 | session->CloseAllConnections(); |
| 8352 | } |
| 8353 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8354 | // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8355 | TEST_F(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8356 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8357 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8358 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 8359 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8360 | HttpRequestInfo request; |
| 8361 | |
| 8362 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8363 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8364 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8365 | session_deps_.proxy_service = |
| 8366 | ProxyService::CreateFixed("https://myproxy:443"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8367 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8368 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8369 | |
| 8370 | // Enable cross-origin push. |
inlinechan | 894515af | 2016-12-09 02:40:10 | [diff] [blame] | 8371 | session_deps_.proxy_delegate = std::move(proxy_delegate); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8372 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8373 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8374 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8375 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 8376 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8377 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8378 | SpdySerializedFrame push_rst( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 8379 | spdy_util_.ConstructSpdyRstStream(2, ERROR_CODE_REFUSED_STREAM)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8380 | |
| 8381 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8382 | CreateMockWrite(stream1_syn, 0, ASYNC), CreateMockWrite(push_rst, 3), |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8383 | }; |
| 8384 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8385 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8386 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8387 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8388 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8389 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8390 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 8391 | NULL, 0, 2, 1, "https://www.another-origin.com/foo.dat")); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8392 | |
| 8393 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8394 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 8395 | CreateMockRead(stream2_syn, 2, ASYNC), |
| 8396 | CreateMockRead(stream1_body, 4, ASYNC), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 8397 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a hang |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8398 | }; |
| 8399 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8400 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8401 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8402 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8403 | // Negotiate SPDY to the proxy |
| 8404 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8405 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8406 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8407 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8408 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8409 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8410 | TestCompletionCallback callback; |
| 8411 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8412 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8413 | |
| 8414 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8415 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8416 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8417 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8418 | ASSERT_TRUE(response); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8419 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8420 | |
| 8421 | EXPECT_EQ(200, response->headers->response_code()); |
| 8422 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8423 | |
| 8424 | std::string response_data; |
| 8425 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8426 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8427 | EXPECT_EQ("hello!", response_data); |
| 8428 | |
| 8429 | trans.reset(); |
| 8430 | session->CloseAllConnections(); |
| 8431 | } |
| 8432 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8433 | // Test that an explicitly trusted SPDY proxy can push same-origin HTTPS |
| 8434 | // resources. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8435 | TEST_F(HttpNetworkTransactionTest, SameOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8436 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8437 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8438 | proxy_delegate->set_trusted_spdy_proxy( |
| 8439 | net::ProxyServer::FromURI("myproxy:70", net::ProxyServer::SCHEME_HTTP)); |
| 8440 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8441 | HttpRequestInfo request; |
| 8442 | |
| 8443 | request.method = "GET"; |
| 8444 | request.url = GURL("http://www.example.org/"); |
| 8445 | |
| 8446 | // Configure against https proxy server "myproxy:70". |
| 8447 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
| 8448 | BoundTestNetLog log; |
| 8449 | session_deps_.net_log = log.bound().net_log(); |
| 8450 | |
| 8451 | // Enable cross-origin push. |
inlinechan | 894515af | 2016-12-09 02:40:10 | [diff] [blame] | 8452 | session_deps_.proxy_delegate = std::move(proxy_delegate); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8453 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8454 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8455 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8456 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 8457 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8458 | SpdySerializedFrame stream2_priority( |
| 8459 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8460 | |
| 8461 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8462 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8463 | CreateMockWrite(stream2_priority, 3, ASYNC), |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8464 | }; |
| 8465 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8466 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8467 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8468 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8469 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
Bence Béky | 096cf05 | 2017-08-08 23:55:33 | [diff] [blame] | 8470 | nullptr, 0, 2, 1, "http://www.example.org/foo.dat")); |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 8471 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8472 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8473 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8474 | SpdySerializedFrame stream2_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8475 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8476 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8477 | SpdySerializedFrame stream2_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8478 | |
| 8479 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8480 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 8481 | CreateMockRead(stream2_syn, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8482 | CreateMockRead(stream1_body, 4, ASYNC), |
| 8483 | CreateMockRead(stream2_body, 5, ASYNC), |
| 8484 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8485 | }; |
| 8486 | |
| 8487 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8488 | arraysize(spdy_writes)); |
| 8489 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 8490 | // Negotiate SPDY to the proxy |
| 8491 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8492 | proxy.next_proto = kProtoHTTP2; |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8493 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
| 8494 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8495 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8496 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8497 | TestCompletionCallback callback; |
| 8498 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8499 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8500 | |
| 8501 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8502 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8503 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8504 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8505 | ASSERT_TRUE(response); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8506 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8507 | |
| 8508 | EXPECT_EQ(200, response->headers->response_code()); |
| 8509 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8510 | |
| 8511 | std::string response_data; |
| 8512 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8513 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8514 | EXPECT_EQ("hello!", response_data); |
| 8515 | |
| 8516 | trans.reset(); |
| 8517 | session->CloseAllConnections(); |
| 8518 | } |
| 8519 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8520 | // Test HTTPS connections to a site with a bad certificate, going through an |
| 8521 | // HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8522 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8523 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8524 | |
| 8525 | HttpRequestInfo request; |
| 8526 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8527 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8528 | |
| 8529 | // Attempt to fetch the URL from a server with a bad cert |
| 8530 | MockWrite bad_cert_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8531 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8532 | "Host: www.example.org:443\r\n" |
| 8533 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8534 | }; |
| 8535 | |
| 8536 | MockRead bad_cert_reads[] = { |
| 8537 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8538 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8539 | }; |
| 8540 | |
| 8541 | // Attempt to fetch the URL with a good cert |
| 8542 | MockWrite good_data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8543 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8544 | "Host: www.example.org:443\r\n" |
| 8545 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 8546 | MockWrite("GET / HTTP/1.1\r\n" |
| 8547 | "Host: www.example.org\r\n" |
| 8548 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8549 | }; |
| 8550 | |
| 8551 | MockRead good_cert_reads[] = { |
| 8552 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 8553 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8554 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8555 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8556 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8557 | }; |
| 8558 | |
| 8559 | StaticSocketDataProvider ssl_bad_certificate( |
| 8560 | bad_cert_reads, arraysize(bad_cert_reads), |
| 8561 | bad_cert_writes, arraysize(bad_cert_writes)); |
| 8562 | StaticSocketDataProvider data(good_cert_reads, arraysize(good_cert_reads), |
| 8563 | good_data_writes, arraysize(good_data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8564 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 8565 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8566 | |
| 8567 | // SSL to the proxy, then CONNECT request, then SSL with bad certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8568 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 8569 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 8570 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8571 | |
| 8572 | // SSL to the proxy, then CONNECT request, then valid SSL certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8573 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 8574 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8575 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8576 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8577 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8578 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8579 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8580 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8581 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8582 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8583 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8584 | |
| 8585 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8586 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8587 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8588 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8589 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8590 | |
| 8591 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8592 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8593 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8594 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8595 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8596 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8597 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8598 | } |
| 8599 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8600 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8601 | HttpRequestInfo request; |
| 8602 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8603 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8604 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 8605 | "Chromium Ultra Awesome X Edition"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8606 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8607 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8608 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8609 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8610 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8611 | MockWrite( |
| 8612 | "GET / HTTP/1.1\r\n" |
| 8613 | "Host: www.example.org\r\n" |
| 8614 | "Connection: keep-alive\r\n" |
| 8615 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8616 | }; |
| 8617 | |
| 8618 | // Lastly, the server responds with the actual content. |
| 8619 | MockRead data_reads[] = { |
| 8620 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8621 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8622 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8623 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8624 | }; |
| 8625 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8626 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8627 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8628 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8629 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8630 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8631 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8632 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8633 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8634 | |
| 8635 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8636 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8637 | } |
| 8638 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8639 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8640 | HttpRequestInfo request; |
| 8641 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8642 | request.url = GURL("https://www.example.org/"); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8643 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 8644 | "Chromium Ultra Awesome X Edition"); |
| 8645 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8646 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8647 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8648 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8649 | |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8650 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8651 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8652 | "Host: www.example.org:443\r\n" |
| 8653 | "Proxy-Connection: keep-alive\r\n" |
| 8654 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8655 | }; |
| 8656 | MockRead data_reads[] = { |
| 8657 | // Return an error, so the transaction stops here (this test isn't |
| 8658 | // interested in the rest). |
| 8659 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 8660 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8661 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 8662 | }; |
| 8663 | |
| 8664 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8665 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8666 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8667 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8668 | TestCompletionCallback callback; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8669 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8670 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8671 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8672 | |
| 8673 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8674 | EXPECT_THAT(rv, IsOk()); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8675 | } |
| 8676 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8677 | TEST_F(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8678 | HttpRequestInfo request; |
| 8679 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8680 | request.url = GURL("http://www.example.org/"); |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 8681 | request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 8682 | "http://the.previous.site.com/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8683 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8684 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8685 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8686 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8687 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8688 | MockWrite( |
| 8689 | "GET / HTTP/1.1\r\n" |
| 8690 | "Host: www.example.org\r\n" |
| 8691 | "Connection: keep-alive\r\n" |
| 8692 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8693 | }; |
| 8694 | |
| 8695 | // Lastly, the server responds with the actual content. |
| 8696 | MockRead data_reads[] = { |
| 8697 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8698 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8699 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8700 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8701 | }; |
| 8702 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8703 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8704 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8705 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8706 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8707 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8708 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8709 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8710 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8711 | |
| 8712 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8713 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8714 | } |
| 8715 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8716 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8717 | HttpRequestInfo request; |
| 8718 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8719 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8720 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8721 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8722 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8723 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8724 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8725 | MockWrite( |
| 8726 | "POST / HTTP/1.1\r\n" |
| 8727 | "Host: www.example.org\r\n" |
| 8728 | "Connection: keep-alive\r\n" |
| 8729 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8730 | }; |
| 8731 | |
| 8732 | // Lastly, the server responds with the actual content. |
| 8733 | MockRead data_reads[] = { |
| 8734 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8735 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8736 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8737 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8738 | }; |
| 8739 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8740 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8741 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8742 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8743 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8744 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8745 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8746 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8747 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8748 | |
| 8749 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8750 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8751 | } |
| 8752 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8753 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8754 | HttpRequestInfo request; |
| 8755 | request.method = "PUT"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8756 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8757 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8758 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8759 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8760 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8761 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8762 | MockWrite( |
| 8763 | "PUT / HTTP/1.1\r\n" |
| 8764 | "Host: www.example.org\r\n" |
| 8765 | "Connection: keep-alive\r\n" |
| 8766 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8767 | }; |
| 8768 | |
| 8769 | // Lastly, the server responds with the actual content. |
| 8770 | MockRead data_reads[] = { |
| 8771 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8772 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8773 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8774 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8775 | }; |
| 8776 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8777 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8778 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8779 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8780 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8781 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8782 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8783 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8784 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8785 | |
| 8786 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8787 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8788 | } |
| 8789 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8790 | TEST_F(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8791 | HttpRequestInfo request; |
| 8792 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8793 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8794 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8795 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8796 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8797 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8798 | MockWrite data_writes[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 8799 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 8800 | "Host: www.example.org\r\n" |
| 8801 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8802 | }; |
| 8803 | |
| 8804 | // Lastly, the server responds with the actual content. |
| 8805 | MockRead data_reads[] = { |
| 8806 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8807 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8808 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8809 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8810 | }; |
| 8811 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8812 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8813 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8814 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8815 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8816 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8817 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8818 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8819 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8820 | |
| 8821 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8822 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8823 | } |
| 8824 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8825 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8826 | HttpRequestInfo request; |
| 8827 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8828 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8829 | request.load_flags = LOAD_BYPASS_CACHE; |
| 8830 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8831 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8832 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8833 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8834 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8835 | MockWrite( |
| 8836 | "GET / HTTP/1.1\r\n" |
| 8837 | "Host: www.example.org\r\n" |
| 8838 | "Connection: keep-alive\r\n" |
| 8839 | "Pragma: no-cache\r\n" |
| 8840 | "Cache-Control: no-cache\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8841 | }; |
| 8842 | |
| 8843 | // Lastly, the server responds with the actual content. |
| 8844 | MockRead data_reads[] = { |
| 8845 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8846 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8847 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8848 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8849 | }; |
| 8850 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8851 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8852 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8853 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8854 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8855 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8856 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8857 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8858 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8859 | |
| 8860 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8861 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8862 | } |
| 8863 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8864 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlValidateCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8865 | HttpRequestInfo request; |
| 8866 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8867 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8868 | request.load_flags = LOAD_VALIDATE_CACHE; |
| 8869 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8870 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8871 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8872 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8873 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8874 | MockWrite( |
| 8875 | "GET / HTTP/1.1\r\n" |
| 8876 | "Host: www.example.org\r\n" |
| 8877 | "Connection: keep-alive\r\n" |
| 8878 | "Cache-Control: max-age=0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8879 | }; |
| 8880 | |
| 8881 | // Lastly, the server responds with the actual content. |
| 8882 | MockRead data_reads[] = { |
| 8883 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8884 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8885 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8886 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8887 | }; |
| 8888 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8889 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8890 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8891 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8892 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8893 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8894 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8895 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8896 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8897 | |
| 8898 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8899 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8900 | } |
| 8901 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8902 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8903 | HttpRequestInfo request; |
| 8904 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8905 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8906 | request.extra_headers.SetHeader("FooHeader", "Bar"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8907 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8908 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8909 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8910 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8911 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8912 | MockWrite( |
| 8913 | "GET / HTTP/1.1\r\n" |
| 8914 | "Host: www.example.org\r\n" |
| 8915 | "Connection: keep-alive\r\n" |
| 8916 | "FooHeader: Bar\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8917 | }; |
| 8918 | |
| 8919 | // Lastly, the server responds with the actual content. |
| 8920 | MockRead data_reads[] = { |
| 8921 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8922 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8923 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8924 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8925 | }; |
| 8926 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8927 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8928 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8929 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8930 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8931 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8932 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8933 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8934 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8935 | |
| 8936 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8937 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8938 | } |
| 8939 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8940 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8941 | HttpRequestInfo request; |
| 8942 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8943 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8944 | request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 8945 | request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 8946 | request.extra_headers.SetHeader("FoO", "bar"); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8947 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8948 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8949 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8950 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8951 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8952 | MockWrite( |
| 8953 | "GET / HTTP/1.1\r\n" |
| 8954 | "Host: www.example.org\r\n" |
| 8955 | "Connection: keep-alive\r\n" |
| 8956 | "referer: www.foo.com\r\n" |
| 8957 | "hEllo: Kitty\r\n" |
| 8958 | "FoO: bar\r\n\r\n"), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8959 | }; |
| 8960 | |
| 8961 | // Lastly, the server responds with the actual content. |
| 8962 | MockRead data_reads[] = { |
| 8963 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8964 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8965 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8966 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8967 | }; |
| 8968 | |
| 8969 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8970 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8971 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8972 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8973 | TestCompletionCallback callback; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8974 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8975 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8976 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8977 | |
| 8978 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8979 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 8980 | } |
| 8981 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8982 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8983 | HttpRequestInfo request; |
| 8984 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8985 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8986 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8987 | session_deps_.proxy_service = |
| 8988 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8989 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8990 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8991 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8992 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8993 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8994 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 8995 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 8996 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 8997 | |
| 8998 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8999 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 9000 | MockWrite( |
| 9001 | "GET / HTTP/1.1\r\n" |
| 9002 | "Host: www.example.org\r\n" |
| 9003 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9004 | |
| 9005 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9006 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9007 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9008 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9009 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9010 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9011 | }; |
| 9012 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9013 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9014 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9015 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9016 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9017 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9018 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9019 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9020 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9021 | |
| 9022 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9023 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9024 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9025 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9026 | ASSERT_TRUE(response); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9027 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9028 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9029 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9030 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9031 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9032 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 9033 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9034 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9035 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9036 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9037 | EXPECT_EQ("Payload", response_text); |
| 9038 | } |
| 9039 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9040 | TEST_F(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9041 | HttpRequestInfo request; |
| 9042 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9043 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9044 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9045 | session_deps_.proxy_service = |
| 9046 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9047 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9048 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9049 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9050 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9051 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9052 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9053 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 9054 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 9055 | |
| 9056 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9057 | MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), |
| 9058 | arraysize(write_buffer)), |
| 9059 | MockWrite( |
| 9060 | "GET / HTTP/1.1\r\n" |
| 9061 | "Host: www.example.org\r\n" |
| 9062 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9063 | |
| 9064 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 9065 | MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), |
| 9066 | arraysize(read_buffer)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9067 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9068 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9069 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9070 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9071 | }; |
| 9072 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9073 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9074 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9075 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9076 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9077 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9078 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9079 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9080 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9081 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9082 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9083 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9084 | |
| 9085 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9086 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9087 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9088 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9089 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9090 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9091 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 9092 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9093 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9094 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9095 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9096 | |
| 9097 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9098 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9099 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9100 | EXPECT_EQ("Payload", response_text); |
| 9101 | } |
| 9102 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9103 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9104 | HttpRequestInfo request; |
| 9105 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9106 | request.url = GURL("http://www.example.org/"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9107 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9108 | session_deps_.proxy_service = |
| 9109 | ProxyService::CreateFixed("socks4://myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9110 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9111 | session_deps_.net_log = &net_log; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9112 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9113 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9114 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9115 | |
| 9116 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 9117 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 9118 | |
| 9119 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9120 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 9121 | MockWrite( |
| 9122 | "GET / HTTP/1.1\r\n" |
| 9123 | "Host: www.example.org\r\n" |
| 9124 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9125 | |
| 9126 | MockRead data_reads[] = { |
| 9127 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
| 9128 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9129 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9130 | MockRead("Payload"), |
| 9131 | MockRead(SYNCHRONOUS, OK) |
| 9132 | }; |
| 9133 | |
| 9134 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9135 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9136 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9137 | |
| 9138 | TestCompletionCallback callback; |
| 9139 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9140 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9141 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9142 | |
| 9143 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9144 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9145 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9146 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9147 | ASSERT_TRUE(response); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9148 | |
| 9149 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9150 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9151 | TestLoadTimingNotReused(load_timing_info, |
| 9152 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 9153 | |
| 9154 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9155 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9156 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9157 | EXPECT_EQ("Payload", response_text); |
| 9158 | } |
| 9159 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9160 | TEST_F(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9161 | HttpRequestInfo request; |
| 9162 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9163 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9164 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9165 | session_deps_.proxy_service = |
| 9166 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9167 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9168 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9169 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9170 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9171 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9172 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9173 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 9174 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9175 | const char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9176 | 0x05, // Version |
| 9177 | 0x01, // Command (CONNECT) |
| 9178 | 0x00, // Reserved. |
| 9179 | 0x03, // Address type (DOMAINNAME). |
| 9180 | 0x0F, // Length of domain (15) |
| 9181 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 9182 | '.', 'o', 'r', 'g', 0x00, 0x50, // 16-bit port (80) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9183 | }; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9184 | const char kSOCKS5OkResponse[] = |
| 9185 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 9186 | |
| 9187 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9188 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 9189 | MockWrite(ASYNC, kSOCKS5OkRequest, arraysize(kSOCKS5OkRequest)), |
| 9190 | MockWrite( |
| 9191 | "GET / HTTP/1.1\r\n" |
| 9192 | "Host: www.example.org\r\n" |
| 9193 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9194 | |
| 9195 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 9196 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 9197 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9198 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9199 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9200 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9201 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9202 | }; |
| 9203 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9204 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9205 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9206 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9207 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9208 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9209 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9210 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9211 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9212 | |
| 9213 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9214 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9215 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9216 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9217 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9218 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9219 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9220 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9221 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9222 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9223 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 9224 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9225 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9226 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9227 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9228 | EXPECT_EQ("Payload", response_text); |
| 9229 | } |
| 9230 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9231 | TEST_F(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9232 | HttpRequestInfo request; |
| 9233 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9234 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9235 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9236 | session_deps_.proxy_service = |
| 9237 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9238 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9239 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9240 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9241 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9242 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9243 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9244 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 9245 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9246 | const unsigned char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9247 | 0x05, // Version |
| 9248 | 0x01, // Command (CONNECT) |
| 9249 | 0x00, // Reserved. |
| 9250 | 0x03, // Address type (DOMAINNAME). |
| 9251 | 0x0F, // Length of domain (15) |
| 9252 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 9253 | '.', 'o', 'r', 'g', 0x01, 0xBB, // 16-bit port (443) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9254 | }; |
| 9255 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9256 | const char kSOCKS5OkResponse[] = |
| 9257 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 9258 | |
| 9259 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9260 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 9261 | MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
| 9262 | arraysize(kSOCKS5OkRequest)), |
| 9263 | MockWrite( |
| 9264 | "GET / HTTP/1.1\r\n" |
| 9265 | "Host: www.example.org\r\n" |
| 9266 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9267 | |
| 9268 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 9269 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 9270 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9271 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9272 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9273 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9274 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9275 | }; |
| 9276 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9277 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9278 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9279 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9280 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9281 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9282 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9283 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9284 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9285 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9286 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9287 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9288 | |
| 9289 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9290 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9291 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9292 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9293 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9294 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9295 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9296 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9297 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9298 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9299 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 9300 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9301 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9302 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9303 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9304 | EXPECT_EQ("Payload", response_text); |
| 9305 | } |
| 9306 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9307 | namespace { |
| 9308 | |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9309 | // Tests that for connection endpoints the group names are correctly set. |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9310 | |
| 9311 | struct GroupNameTest { |
| 9312 | std::string proxy_server; |
| 9313 | std::string url; |
| 9314 | std::string expected_group_name; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9315 | bool ssl; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9316 | }; |
| 9317 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9318 | std::unique_ptr<HttpNetworkSession> SetupSessionForGroupNameTests( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9319 | SpdySessionDependencies* session_deps_) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9320 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9321 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 9322 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9323 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 9324 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9325 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 9326 | http_server_properties->SetHttp2AlternativeService( |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9327 | url::SchemeHostPort("https", "host.with.alternate", 443), |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 9328 | alternative_service, expiration); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9329 | |
| 9330 | return session; |
| 9331 | } |
| 9332 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9333 | int GroupNameTransactionHelper(const std::string& url, |
| 9334 | HttpNetworkSession* session) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9335 | HttpRequestInfo request; |
| 9336 | request.method = "GET"; |
| 9337 | request.url = GURL(url); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9338 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9339 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9340 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9341 | TestCompletionCallback callback; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9342 | |
| 9343 | // We do not complete this request, the dtor will clean the transaction up. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9344 | return trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9345 | } |
| 9346 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9347 | } // namespace |
| 9348 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9349 | TEST_F(HttpNetworkTransactionTest, GroupNameForDirectConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9350 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9351 | { |
| 9352 | "", // unused |
| 9353 | "http://www.example.org/direct", |
| 9354 | "www.example.org:80", |
| 9355 | false, |
| 9356 | }, |
| 9357 | { |
| 9358 | "", // unused |
| 9359 | "http://[2001:1418:13:1::25]/direct", |
| 9360 | "[2001:1418:13:1::25]:80", |
| 9361 | false, |
| 9362 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9363 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9364 | // SSL Tests |
| 9365 | { |
| 9366 | "", // unused |
| 9367 | "https://www.example.org/direct_ssl", |
| 9368 | "ssl/www.example.org:443", |
| 9369 | true, |
| 9370 | }, |
| 9371 | { |
| 9372 | "", // unused |
| 9373 | "https://[2001:1418:13:1::25]/direct", |
| 9374 | "ssl/[2001:1418:13:1::25]:443", |
| 9375 | true, |
| 9376 | }, |
| 9377 | { |
| 9378 | "", // unused |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9379 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9380 | "ssl/host.with.alternate:443", |
| 9381 | true, |
| 9382 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9383 | }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9384 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 9385 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9386 | session_deps_.proxy_service = |
| 9387 | ProxyService::CreateFixed(tests[i].proxy_server); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9388 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 9389 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9390 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9391 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9392 | CaptureGroupNameTransportSocketPool* transport_conn_pool = |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9393 | new CaptureGroupNameTransportSocketPool(nullptr, nullptr); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9394 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9395 | new CaptureGroupNameSSLSocketPool(nullptr, nullptr); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9396 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 9397 | mock_pool_manager->SetTransportSocketPool(transport_conn_pool); |
| 9398 | mock_pool_manager->SetSSLSocketPool(ssl_conn_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 9399 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9400 | |
| 9401 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9402 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9403 | if (tests[i].ssl) |
| 9404 | EXPECT_EQ(tests[i].expected_group_name, |
| 9405 | ssl_conn_pool->last_group_name_received()); |
| 9406 | else |
| 9407 | EXPECT_EQ(tests[i].expected_group_name, |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9408 | transport_conn_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9409 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9410 | } |
| 9411 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9412 | TEST_F(HttpNetworkTransactionTest, GroupNameForHTTPProxyConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9413 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9414 | { |
| 9415 | "http_proxy", |
| 9416 | "http://www.example.org/http_proxy_normal", |
| 9417 | "www.example.org:80", |
| 9418 | false, |
| 9419 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9420 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9421 | // SSL Tests |
| 9422 | { |
| 9423 | "http_proxy", |
| 9424 | "https://www.example.org/http_connect_ssl", |
| 9425 | "ssl/www.example.org:443", |
| 9426 | true, |
| 9427 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 9428 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9429 | { |
| 9430 | "http_proxy", |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9431 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9432 | "ssl/host.with.alternate:443", |
| 9433 | true, |
| 9434 | }, |
[email protected] | 4549925 | 2013-01-23 17:12:56 | [diff] [blame] | 9435 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9436 | { |
| 9437 | "http_proxy", |
| 9438 | "ftp://ftp.google.com/http_proxy_normal", |
| 9439 | "ftp/ftp.google.com:21", |
| 9440 | false, |
| 9441 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9442 | }; |
| 9443 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 9444 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9445 | session_deps_.proxy_service = |
| 9446 | ProxyService::CreateFixed(tests[i].proxy_server); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9447 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 9448 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9449 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9450 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9451 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9452 | HostPortPair proxy_host("http_proxy", 80); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9453 | CaptureGroupNameHttpProxySocketPool* http_proxy_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9454 | new CaptureGroupNameHttpProxySocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9455 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9456 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9457 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
avi | adef344 | 2016-10-03 18:50:39 | [diff] [blame] | 9458 | mock_pool_manager->SetSocketPoolForHTTPProxy( |
| 9459 | proxy_host, base::WrapUnique(http_proxy_pool)); |
| 9460 | mock_pool_manager->SetSocketPoolForSSLWithProxy( |
| 9461 | proxy_host, base::WrapUnique(ssl_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 9462 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9463 | |
| 9464 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9465 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9466 | if (tests[i].ssl) |
| 9467 | EXPECT_EQ(tests[i].expected_group_name, |
| 9468 | ssl_conn_pool->last_group_name_received()); |
| 9469 | else |
| 9470 | EXPECT_EQ(tests[i].expected_group_name, |
| 9471 | http_proxy_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9472 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9473 | } |
| 9474 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9475 | TEST_F(HttpNetworkTransactionTest, GroupNameForSOCKSConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9476 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9477 | { |
| 9478 | "socks4://socks_proxy:1080", |
| 9479 | "http://www.example.org/socks4_direct", |
| 9480 | "socks4/www.example.org:80", |
| 9481 | false, |
| 9482 | }, |
| 9483 | { |
| 9484 | "socks5://socks_proxy:1080", |
| 9485 | "http://www.example.org/socks5_direct", |
| 9486 | "socks5/www.example.org:80", |
| 9487 | false, |
| 9488 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9489 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9490 | // SSL Tests |
| 9491 | { |
| 9492 | "socks4://socks_proxy:1080", |
| 9493 | "https://www.example.org/socks4_ssl", |
| 9494 | "socks4/ssl/www.example.org:443", |
| 9495 | true, |
| 9496 | }, |
| 9497 | { |
| 9498 | "socks5://socks_proxy:1080", |
| 9499 | "https://www.example.org/socks5_ssl", |
| 9500 | "socks5/ssl/www.example.org:443", |
| 9501 | true, |
| 9502 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 9503 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9504 | { |
| 9505 | "socks4://socks_proxy:1080", |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9506 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9507 | "socks4/ssl/host.with.alternate:443", |
| 9508 | true, |
| 9509 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9510 | }; |
| 9511 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 9512 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9513 | session_deps_.proxy_service = |
| 9514 | ProxyService::CreateFixed(tests[i].proxy_server); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9515 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 9516 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 9517 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9518 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9519 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9520 | HostPortPair proxy_host("socks_proxy", 1080); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9521 | CaptureGroupNameSOCKSSocketPool* socks_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9522 | new CaptureGroupNameSOCKSSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9523 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9524 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9525 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
avi | adef344 | 2016-10-03 18:50:39 | [diff] [blame] | 9526 | mock_pool_manager->SetSocketPoolForSOCKSProxy( |
| 9527 | proxy_host, base::WrapUnique(socks_conn_pool)); |
| 9528 | mock_pool_manager->SetSocketPoolForSSLWithProxy( |
| 9529 | proxy_host, base::WrapUnique(ssl_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 9530 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9531 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9532 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9533 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9534 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9535 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9536 | if (tests[i].ssl) |
| 9537 | EXPECT_EQ(tests[i].expected_group_name, |
| 9538 | ssl_conn_pool->last_group_name_received()); |
| 9539 | else |
| 9540 | EXPECT_EQ(tests[i].expected_group_name, |
| 9541 | socks_conn_pool->last_group_name_received()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9542 | } |
| 9543 | } |
| 9544 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9545 | TEST_F(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9546 | HttpRequestInfo request; |
| 9547 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9548 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9549 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9550 | session_deps_.proxy_service = |
| 9551 | ProxyService::CreateFixed("myproxy:70;foobar:80"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 9552 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 9553 | // This simulates failure resolving all hostnames; that means we will fail |
| 9554 | // connecting to both proxies (myproxy:70 and foobar:80). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9555 | session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 9556 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9557 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9558 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9559 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9560 | TestCompletionCallback callback; |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9561 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9562 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9563 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9564 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9565 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9566 | EXPECT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9567 | } |
| 9568 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9569 | // Base test to make sure that when the load flags for a request specify to |
| 9570 | // bypass the cache, the DNS cache is not used. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9571 | void HttpNetworkTransactionTest::BypassHostCacheOnRefreshHelper( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9572 | int load_flags) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9573 | // Issue a request, asking to bypass the cache(s). |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9574 | HttpRequestInfo request_info; |
| 9575 | request_info.method = "GET"; |
| 9576 | request_info.load_flags = load_flags; |
| 9577 | request_info.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9578 | |
[email protected] | a2c2fb9 | 2009-07-18 07:31:04 | [diff] [blame] | 9579 | // Select a host resolver that does caching. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9580 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 9581 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9582 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9583 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9584 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9585 | // 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] | 9586 | AddressList addrlist; |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 9587 | TestCompletionCallback callback; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9588 | std::unique_ptr<HostResolver::Request> request1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9589 | int rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9590 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9591 | DEFAULT_PRIORITY, &addrlist, callback.callback(), &request1, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9592 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9593 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 9594 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9595 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9596 | |
| 9597 | // Verify that it was added to host cache, by doing a subsequent async lookup |
| 9598 | // and confirming it completes synchronously. |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9599 | std::unique_ptr<HostResolver::Request> request2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9600 | rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9601 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9602 | DEFAULT_PRIORITY, &addrlist, callback.callback(), &request2, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9603 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9604 | ASSERT_THAT(rv, IsOk()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9605 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9606 | // 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] | 9607 | // we can tell if the next lookup hit the cache, or the "network". |
| 9608 | // (cache --> success, "network" --> failure). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9609 | session_deps_.host_resolver->rules()->AddSimulatedFailure("www.example.org"); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9610 | |
| 9611 | // Connect up a mock socket which will fail with ERR_UNEXPECTED during the |
| 9612 | // 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] | 9613 | MockRead data_reads[] = { MockRead(SYNCHRONOUS, ERR_UNEXPECTED) }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9614 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9615 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9616 | |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9617 | // Run the request. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9618 | rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9619 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9620 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9621 | |
| 9622 | // If we bypassed the cache, we would have gotten a failure while resolving |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9623 | // "www.example.org". |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9624 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9625 | } |
| 9626 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9627 | // There are multiple load flags that should trigger the host cache bypass. |
| 9628 | // Test each in isolation: |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9629 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh1) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9630 | BypassHostCacheOnRefreshHelper(LOAD_BYPASS_CACHE); |
| 9631 | } |
| 9632 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9633 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh2) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9634 | BypassHostCacheOnRefreshHelper(LOAD_VALIDATE_CACHE); |
| 9635 | } |
| 9636 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9637 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh3) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9638 | BypassHostCacheOnRefreshHelper(LOAD_DISABLE_CACHE); |
| 9639 | } |
| 9640 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9641 | // Make sure we can handle an error when writing the request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9642 | TEST_F(HttpNetworkTransactionTest, RequestWriteError) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9643 | HttpRequestInfo request; |
| 9644 | request.method = "GET"; |
| 9645 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9646 | |
| 9647 | MockWrite write_failure[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9648 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9649 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9650 | StaticSocketDataProvider data(NULL, 0, |
| 9651 | write_failure, arraysize(write_failure)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9652 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9653 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9654 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9655 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9656 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9657 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9658 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9659 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9660 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9661 | |
| 9662 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9663 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9664 | |
| 9665 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9666 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9667 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9668 | } |
| 9669 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9670 | // Check that a connection closed after the start of the headers finishes ok. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9671 | TEST_F(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9672 | HttpRequestInfo request; |
| 9673 | request.method = "GET"; |
| 9674 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9675 | |
| 9676 | MockRead data_reads[] = { |
| 9677 | MockRead("HTTP/1."), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9678 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9679 | }; |
| 9680 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9681 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9682 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9683 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9684 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9685 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9686 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9687 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9688 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9689 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9690 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9691 | |
| 9692 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9693 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9694 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9695 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9696 | ASSERT_TRUE(response); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9697 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9698 | EXPECT_TRUE(response->headers); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9699 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 9700 | |
| 9701 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9702 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9703 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9704 | EXPECT_EQ("", response_data); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9705 | |
| 9706 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9707 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9708 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9709 | } |
| 9710 | |
| 9711 | // Make sure that a dropped connection while draining the body for auth |
| 9712 | // restart does the right thing. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9713 | TEST_F(HttpNetworkTransactionTest, DrainResetOK) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9714 | HttpRequestInfo request; |
| 9715 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9716 | request.url = GURL("http://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9717 | |
| 9718 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9719 | MockWrite( |
| 9720 | "GET / HTTP/1.1\r\n" |
| 9721 | "Host: www.example.org\r\n" |
| 9722 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9723 | }; |
| 9724 | |
| 9725 | MockRead data_reads1[] = { |
| 9726 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 9727 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9728 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9729 | MockRead("Content-Length: 14\r\n\r\n"), |
| 9730 | MockRead("Unauth"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9731 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9732 | }; |
| 9733 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9734 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 9735 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9736 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9737 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9738 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9739 | // be issuing -- the final header line contains the credentials. |
| 9740 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9741 | MockWrite( |
| 9742 | "GET / HTTP/1.1\r\n" |
| 9743 | "Host: www.example.org\r\n" |
| 9744 | "Connection: keep-alive\r\n" |
| 9745 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9746 | }; |
| 9747 | |
| 9748 | // Lastly, the server responds with the actual content. |
| 9749 | MockRead data_reads2[] = { |
| 9750 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9751 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9752 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9753 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9754 | }; |
| 9755 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9756 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 9757 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9758 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9759 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9760 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9761 | TestCompletionCallback callback1; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9762 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9763 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9764 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9765 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9766 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9767 | |
| 9768 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9769 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9770 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9771 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9772 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9773 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9774 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9775 | TestCompletionCallback callback2; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9776 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9777 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9778 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9779 | |
| 9780 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9781 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9782 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9783 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9784 | ASSERT_TRUE(response); |
| 9785 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9786 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9787 | } |
| 9788 | |
| 9789 | // Test HTTPS connections going through a proxy that sends extra data. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9790 | TEST_F(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9791 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9792 | |
| 9793 | HttpRequestInfo request; |
| 9794 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9795 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9796 | |
| 9797 | MockRead proxy_reads[] = { |
| 9798 | MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9799 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9800 | }; |
| 9801 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9802 | StaticSocketDataProvider data(proxy_reads, arraysize(proxy_reads), NULL, 0); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9803 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9804 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9805 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9806 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9807 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9808 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9809 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9810 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9811 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9812 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9813 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9814 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9815 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9816 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9817 | |
| 9818 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9819 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9820 | } |
| 9821 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9822 | TEST_F(HttpNetworkTransactionTest, LargeContentLengthThenClose) { |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9823 | HttpRequestInfo request; |
| 9824 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9825 | request.url = GURL("http://www.example.org/"); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9826 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9827 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9828 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9829 | |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 9830 | MockRead data_reads[] = { |
| 9831 | 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] | 9832 | MockRead(SYNCHRONOUS, OK), |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 9833 | }; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9834 | |
| 9835 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9836 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9837 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9838 | TestCompletionCallback callback; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9839 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9840 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9841 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9842 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9843 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9844 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9845 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9846 | ASSERT_TRUE(response); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9847 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9848 | EXPECT_TRUE(response->headers); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9849 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 9850 | |
| 9851 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9852 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9853 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 9854 | } |
| 9855 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9856 | TEST_F(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 9857 | base::FilePath temp_file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 9858 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path)); |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 9859 | const uint64_t kFakeSize = 100000; // file is actually blank |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 9860 | UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 9861 | overriding_content_length(kFakeSize); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9862 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9863 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9864 | element_readers.push_back(std::make_unique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 9865 | base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 9866 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9867 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9868 | |
| 9869 | HttpRequestInfo request; |
| 9870 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9871 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9872 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9873 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9874 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9875 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9876 | |
| 9877 | MockRead data_reads[] = { |
| 9878 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 9879 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9880 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9881 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9882 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9883 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9884 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9885 | TestCompletionCallback callback; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9886 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9887 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9888 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9889 | |
| 9890 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9891 | EXPECT_THAT(rv, IsError(ERR_UPLOAD_FILE_CHANGED)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9892 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9893 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9894 | ASSERT_TRUE(response); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9895 | |
maksim.sisov | e869bf5 | 2016-06-23 17:11:52 | [diff] [blame] | 9896 | EXPECT_FALSE(response->headers); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9897 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 9898 | base::DeleteFile(temp_file_path, false); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 9899 | } |
| 9900 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9901 | TEST_F(HttpNetworkTransactionTest, UploadUnreadableFile) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 9902 | base::FilePath temp_file; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 9903 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9904 | std::string temp_file_content("Unreadable file."); |
lazyboy | 8df84fc | 2017-04-12 02:12:48 | [diff] [blame] | 9905 | ASSERT_EQ(static_cast<int>(temp_file_content.length()), |
| 9906 | base::WriteFile(temp_file, temp_file_content.c_str(), |
| 9907 | temp_file_content.length())); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 9908 | ASSERT_TRUE(base::MakeFileUnreadable(temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9909 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9910 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9911 | element_readers.push_back(std::make_unique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 9912 | base::ThreadTaskRunnerHandle::Get().get(), temp_file, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 9913 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9914 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9915 | |
| 9916 | HttpRequestInfo request; |
| 9917 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9918 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9919 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 9920 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 9921 | // If we try to upload an unreadable file, the transaction should fail. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9922 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9923 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9924 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 9925 | StaticSocketDataProvider data(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9926 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9927 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9928 | TestCompletionCallback callback; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9929 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9930 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9931 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9932 | |
| 9933 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9934 | EXPECT_THAT(rv, IsError(ERR_ACCESS_DENIED)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9935 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 9936 | base::DeleteFile(temp_file, false); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 9937 | } |
| 9938 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9939 | TEST_F(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9940 | class FakeUploadElementReader : public UploadElementReader { |
| 9941 | public: |
| 9942 | FakeUploadElementReader() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9943 | ~FakeUploadElementReader() override {} |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9944 | |
| 9945 | const CompletionCallback& callback() const { return callback_; } |
| 9946 | |
| 9947 | // UploadElementReader overrides: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9948 | int Init(const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9949 | callback_ = callback; |
| 9950 | return ERR_IO_PENDING; |
| 9951 | } |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 9952 | uint64_t GetContentLength() const override { return 0; } |
| 9953 | uint64_t BytesRemaining() const override { return 0; } |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 9954 | int Read(IOBuffer* buf, |
| 9955 | int buf_length, |
| 9956 | const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9957 | return ERR_FAILED; |
| 9958 | } |
| 9959 | |
| 9960 | private: |
| 9961 | CompletionCallback callback_; |
| 9962 | }; |
| 9963 | |
| 9964 | FakeUploadElementReader* fake_reader = new FakeUploadElementReader; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9965 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
| 9966 | element_readers.push_back(base::WrapUnique(fake_reader)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 9967 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9968 | |
| 9969 | HttpRequestInfo request; |
| 9970 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9971 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9972 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9973 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9974 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9975 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9976 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9977 | |
| 9978 | StaticSocketDataProvider data; |
| 9979 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9980 | |
| 9981 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9982 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9983 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 9984 | base::RunLoop().RunUntilIdle(); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 9985 | |
| 9986 | // Transaction is pending on request body initialization. |
| 9987 | ASSERT_FALSE(fake_reader->callback().is_null()); |
| 9988 | |
| 9989 | // Return Init()'s result after the transaction gets destroyed. |
| 9990 | trans.reset(); |
| 9991 | fake_reader->callback().Run(OK); // Should not crash. |
| 9992 | } |
| 9993 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9994 | // Tests that changes to Auth realms are treated like auth rejections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9995 | TEST_F(HttpNetworkTransactionTest, ChangeAuthRealms) { |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9996 | HttpRequestInfo request; |
| 9997 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9998 | request.url = GURL("http://www.example.org/"); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 9999 | |
| 10000 | // First transaction will request a resource and receive a Basic challenge |
| 10001 | // with realm="first_realm". |
| 10002 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10003 | MockWrite( |
| 10004 | "GET / HTTP/1.1\r\n" |
| 10005 | "Host: www.example.org\r\n" |
| 10006 | "Connection: keep-alive\r\n" |
| 10007 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10008 | }; |
| 10009 | MockRead data_reads1[] = { |
| 10010 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 10011 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 10012 | "\r\n"), |
| 10013 | }; |
| 10014 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10015 | // After calling trans.RestartWithAuth(), provide an Authentication header |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10016 | // for first_realm. The server will reject and provide a challenge with |
| 10017 | // second_realm. |
| 10018 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10019 | MockWrite( |
| 10020 | "GET / HTTP/1.1\r\n" |
| 10021 | "Host: www.example.org\r\n" |
| 10022 | "Connection: keep-alive\r\n" |
| 10023 | "Authorization: Basic Zmlyc3Q6YmF6\r\n" |
| 10024 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10025 | }; |
| 10026 | MockRead data_reads2[] = { |
| 10027 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 10028 | "WWW-Authenticate: Basic realm=\"second_realm\"\r\n" |
| 10029 | "\r\n"), |
| 10030 | }; |
| 10031 | |
| 10032 | // This again fails, and goes back to first_realm. Make sure that the |
| 10033 | // entry is removed from cache. |
| 10034 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10035 | MockWrite( |
| 10036 | "GET / HTTP/1.1\r\n" |
| 10037 | "Host: www.example.org\r\n" |
| 10038 | "Connection: keep-alive\r\n" |
| 10039 | "Authorization: Basic c2Vjb25kOmZvdQ==\r\n" |
| 10040 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10041 | }; |
| 10042 | MockRead data_reads3[] = { |
| 10043 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 10044 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 10045 | "\r\n"), |
| 10046 | }; |
| 10047 | |
| 10048 | // Try one last time (with the correct password) and get the resource. |
| 10049 | MockWrite data_writes4[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10050 | MockWrite( |
| 10051 | "GET / HTTP/1.1\r\n" |
| 10052 | "Host: www.example.org\r\n" |
| 10053 | "Connection: keep-alive\r\n" |
| 10054 | "Authorization: Basic Zmlyc3Q6YmFy\r\n" |
| 10055 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10056 | }; |
| 10057 | MockRead data_reads4[] = { |
| 10058 | MockRead("HTTP/1.1 200 OK\r\n" |
| 10059 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10060 | "Content-Length: 5\r\n" |
| 10061 | "\r\n" |
| 10062 | "hello"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10063 | }; |
| 10064 | |
| 10065 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 10066 | data_writes1, arraysize(data_writes1)); |
| 10067 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 10068 | data_writes2, arraysize(data_writes2)); |
| 10069 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 10070 | data_writes3, arraysize(data_writes3)); |
| 10071 | StaticSocketDataProvider data4(data_reads4, arraysize(data_reads4), |
| 10072 | data_writes4, arraysize(data_writes4)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10073 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 10074 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 10075 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 10076 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10077 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10078 | TestCompletionCallback callback1; |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10079 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10080 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10081 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10082 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10083 | // Issue the first request with Authorize headers. There should be a |
| 10084 | // password prompt for first_realm waiting to be filled in after the |
| 10085 | // transaction completes. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10086 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10087 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10088 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10089 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10090 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10091 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10092 | const AuthChallengeInfo* challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10093 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10094 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10095 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10096 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 10097 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10098 | |
| 10099 | // Issue the second request with an incorrect password. There should be a |
| 10100 | // password prompt for second_realm waiting to be filled in after the |
| 10101 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10102 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10103 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBaz), |
| 10104 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10105 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10106 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10107 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10108 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10109 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10110 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10111 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10112 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10113 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10114 | EXPECT_EQ("second_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 10115 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10116 | |
| 10117 | // Issue the third request with another incorrect password. There should be |
| 10118 | // a password prompt for first_realm waiting to be filled in. If the password |
| 10119 | // prompt is not present, it indicates that the HttpAuthCacheEntry for |
| 10120 | // first_realm was not correctly removed. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10121 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10122 | rv = trans.RestartWithAuth(AuthCredentials(kSecond, kFou), |
| 10123 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10124 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10125 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10126 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10127 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10128 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10129 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10130 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10131 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10132 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10133 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 10134 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10135 | |
| 10136 | // Issue the fourth request with the correct password and username. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10137 | TestCompletionCallback callback4; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10138 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBar), |
| 10139 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10140 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10141 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10142 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10143 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10144 | ASSERT_TRUE(response); |
| 10145 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10146 | } |
| 10147 | |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 10148 | // Regression test for https://crbug.com/754395. |
| 10149 | TEST_F(HttpNetworkTransactionTest, IgnoreAltSvcWithInvalidCert) { |
| 10150 | MockRead data_reads[] = { |
| 10151 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10152 | MockRead(kAlternativeServiceHttpHeader), |
| 10153 | MockRead("\r\n"), |
| 10154 | MockRead("hello world"), |
| 10155 | MockRead(SYNCHRONOUS, OK), |
| 10156 | }; |
| 10157 | |
| 10158 | HttpRequestInfo request; |
| 10159 | request.method = "GET"; |
| 10160 | request.url = GURL("https://www.example.org/"); |
| 10161 | |
| 10162 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 10163 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10164 | |
| 10165 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10166 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 10167 | ASSERT_TRUE(ssl.cert); |
| 10168 | ssl.cert_status = CERT_STATUS_COMMON_NAME_INVALID; |
| 10169 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10170 | |
| 10171 | TestCompletionCallback callback; |
| 10172 | |
| 10173 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10174 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 10175 | |
| 10176 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 10177 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10178 | |
| 10179 | url::SchemeHostPort test_server(request.url); |
| 10180 | HttpServerProperties* http_server_properties = |
| 10181 | session->http_server_properties(); |
| 10182 | EXPECT_TRUE( |
| 10183 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
| 10184 | |
| 10185 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 10186 | |
| 10187 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 10188 | ASSERT_TRUE(response); |
| 10189 | ASSERT_TRUE(response->headers); |
| 10190 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10191 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 10192 | EXPECT_FALSE(response->was_alpn_negotiated); |
| 10193 | |
| 10194 | std::string response_data; |
| 10195 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 10196 | EXPECT_EQ("hello world", response_data); |
| 10197 | |
| 10198 | EXPECT_TRUE( |
| 10199 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
| 10200 | } |
| 10201 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10202 | TEST_F(HttpNetworkTransactionTest, HonorAlternativeServiceHeader) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10203 | MockRead data_reads[] = { |
| 10204 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10205 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10206 | MockRead("\r\n"), |
| 10207 | MockRead("hello world"), |
| 10208 | MockRead(SYNCHRONOUS, OK), |
| 10209 | }; |
| 10210 | |
| 10211 | HttpRequestInfo request; |
| 10212 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10213 | request.url = GURL("https://www.example.org/"); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10214 | |
| 10215 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10216 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10217 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10218 | SSLSocketDataProvider ssl(ASYNC, OK); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 10219 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 10220 | ASSERT_TRUE(ssl.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10221 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10222 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10223 | TestCompletionCallback callback; |
| 10224 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10225 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10226 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10227 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10228 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10229 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10230 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10231 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10232 | HttpServerProperties* http_server_properties = |
| 10233 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10234 | EXPECT_TRUE( |
| 10235 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10236 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10237 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10238 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10239 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10240 | ASSERT_TRUE(response); |
| 10241 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10242 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10243 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10244 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10245 | |
| 10246 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10247 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10248 | EXPECT_EQ("hello world", response_data); |
| 10249 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10250 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 10251 | http_server_properties->GetAlternativeServiceInfos(test_server); |
| 10252 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 10253 | AlternativeService alternative_service(kProtoHTTP2, "mail.example.org", 443); |
| 10254 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 10255 | alternative_service_info_vector[0].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10256 | } |
| 10257 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10258 | // Regression test for https://crbug.com/615497. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10259 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10260 | DoNotParseAlternativeServiceHeaderOnInsecureRequest) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10261 | MockRead data_reads[] = { |
| 10262 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10263 | MockRead(kAlternativeServiceHttpHeader), |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10264 | MockRead("\r\n"), |
| 10265 | MockRead("hello world"), |
| 10266 | MockRead(SYNCHRONOUS, OK), |
| 10267 | }; |
| 10268 | |
| 10269 | HttpRequestInfo request; |
| 10270 | request.method = "GET"; |
| 10271 | request.url = GURL("http://www.example.org/"); |
| 10272 | request.load_flags = 0; |
| 10273 | |
| 10274 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 10275 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10276 | |
| 10277 | TestCompletionCallback callback; |
| 10278 | |
| 10279 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10280 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10281 | |
| 10282 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10283 | HttpServerProperties* http_server_properties = |
| 10284 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10285 | EXPECT_TRUE( |
| 10286 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10287 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10288 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10289 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10290 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10291 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10292 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10293 | ASSERT_TRUE(response); |
| 10294 | ASSERT_TRUE(response->headers); |
| 10295 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10296 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10297 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10298 | |
| 10299 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10300 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10301 | EXPECT_EQ("hello world", response_data); |
| 10302 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10303 | EXPECT_TRUE( |
| 10304 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10305 | } |
| 10306 | |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 10307 | // HTTP/2 Alternative Services should be disabled by default. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10308 | // TODO(bnc): Remove when https://crbug.com/615413 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10309 | TEST_F(HttpNetworkTransactionTest, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10310 | DisableHTTP2AlternativeServicesWithDifferentHost) { |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 10311 | session_deps_.enable_http2_alternative_service = false; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10312 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 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 | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10316 | request.load_flags = 0; |
| 10317 | |
| 10318 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10319 | StaticSocketDataProvider first_data; |
| 10320 | first_data.set_connect_data(mock_connect); |
| 10321 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10322 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10323 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10324 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10325 | |
| 10326 | MockRead data_reads[] = { |
| 10327 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 10328 | MockRead(ASYNC, OK), |
| 10329 | }; |
| 10330 | StaticSocketDataProvider second_data(data_reads, arraysize(data_reads), NULL, |
| 10331 | 0); |
| 10332 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 10333 | |
| 10334 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10335 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10336 | HttpServerProperties* http_server_properties = |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10337 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10338 | AlternativeService alternative_service(kProtoHTTP2, "different.example.org", |
| 10339 | 444); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10340 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10341 | http_server_properties->SetHttp2AlternativeService( |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10342 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 10343 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10344 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10345 | TestCompletionCallback callback; |
| 10346 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10347 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10348 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10349 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10350 | } |
| 10351 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10352 | // Regression test for https://crbug.com/615497: |
| 10353 | // Alternative Services should be disabled for http origin. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10354 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10355 | DisableAlternativeServicesForInsecureOrigin) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10356 | HttpRequestInfo request; |
| 10357 | request.method = "GET"; |
| 10358 | request.url = GURL("http://www.example.org/"); |
| 10359 | request.load_flags = 0; |
| 10360 | |
| 10361 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10362 | StaticSocketDataProvider first_data; |
| 10363 | first_data.set_connect_data(mock_connect); |
| 10364 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
| 10365 | |
| 10366 | MockRead data_reads[] = { |
| 10367 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 10368 | MockRead(ASYNC, OK), |
| 10369 | }; |
| 10370 | StaticSocketDataProvider second_data(data_reads, arraysize(data_reads), NULL, |
| 10371 | 0); |
| 10372 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 10373 | |
| 10374 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10375 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10376 | HttpServerProperties* http_server_properties = |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10377 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10378 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10379 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10380 | http_server_properties->SetHttp2AlternativeService( |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10381 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 10382 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10383 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10384 | TestCompletionCallback callback; |
| 10385 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10386 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10387 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10388 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10389 | } |
| 10390 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10391 | TEST_F(HttpNetworkTransactionTest, ClearAlternativeServices) { |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10392 | // Set an alternative service for origin. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10393 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10394 | HttpServerProperties* http_server_properties = |
| 10395 | session->http_server_properties(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10396 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10397 | AlternativeService alternative_service(kProtoQUIC, "", 80); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10398 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10399 | http_server_properties->SetQuicAlternativeService( |
| 10400 | test_server, alternative_service, expiration, |
| 10401 | session->params().quic_supported_versions); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10402 | EXPECT_EQ( |
| 10403 | 1u, |
| 10404 | http_server_properties->GetAlternativeServiceInfos(test_server).size()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10405 | |
| 10406 | // Send a clear header. |
| 10407 | MockRead data_reads[] = { |
| 10408 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10409 | MockRead("Alt-Svc: clear\r\n"), |
| 10410 | MockRead("\r\n"), |
| 10411 | MockRead("hello world"), |
| 10412 | MockRead(SYNCHRONOUS, OK), |
| 10413 | }; |
| 10414 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 10415 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10416 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10417 | SSLSocketDataProvider ssl(ASYNC, OK); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 10418 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 10419 | ASSERT_TRUE(ssl.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10420 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10421 | |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10422 | HttpRequestInfo request; |
| 10423 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10424 | request.url = GURL("https://www.example.org/"); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10425 | |
| 10426 | TestCompletionCallback callback; |
| 10427 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10428 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10429 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10430 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10431 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10432 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10433 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10434 | ASSERT_TRUE(response); |
| 10435 | ASSERT_TRUE(response->headers); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10436 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10437 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10438 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10439 | |
| 10440 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10441 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10442 | EXPECT_EQ("hello world", response_data); |
| 10443 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10444 | EXPECT_TRUE( |
| 10445 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10446 | } |
| 10447 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10448 | TEST_F(HttpNetworkTransactionTest, HonorMultipleAlternativeServiceHeaders) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10449 | MockRead data_reads[] = { |
| 10450 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10451 | MockRead("Alt-Svc: h2=\"www.example.com:443\","), |
| 10452 | MockRead("h2=\":1234\"\r\n\r\n"), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10453 | MockRead("hello world"), |
| 10454 | MockRead(SYNCHRONOUS, OK), |
| 10455 | }; |
| 10456 | |
| 10457 | HttpRequestInfo request; |
| 10458 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10459 | request.url = GURL("https://www.example.org/"); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10460 | |
| 10461 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10462 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10463 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10464 | SSLSocketDataProvider ssl(ASYNC, OK); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 10465 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 10466 | ASSERT_TRUE(ssl.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10467 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10468 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10469 | TestCompletionCallback callback; |
| 10470 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10471 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10472 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10473 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10474 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10475 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10476 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10477 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10478 | HttpServerProperties* http_server_properties = |
| 10479 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10480 | EXPECT_TRUE( |
| 10481 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10482 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10483 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10484 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10485 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10486 | ASSERT_TRUE(response); |
| 10487 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10488 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10489 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10490 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10491 | |
| 10492 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10493 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10494 | EXPECT_EQ("hello world", response_data); |
| 10495 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10496 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 10497 | http_server_properties->GetAlternativeServiceInfos(test_server); |
| 10498 | ASSERT_EQ(2u, alternative_service_info_vector.size()); |
| 10499 | |
| 10500 | AlternativeService alternative_service(kProtoHTTP2, "www.example.com", 443); |
| 10501 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 10502 | alternative_service_info_vector[0].alternative_service()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10503 | AlternativeService alternative_service_2(kProtoHTTP2, "www.example.org", |
| 10504 | 1234); |
| 10505 | EXPECT_EQ(alternative_service_2, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 10506 | alternative_service_info_vector[1].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10507 | } |
| 10508 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10509 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10510 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10511 | HostPortPair alternative("alternative.example.org", 443); |
| 10512 | std::string origin_url = "https://origin.example.org:443"; |
| 10513 | std::string alternative_url = "https://alternative.example.org:443"; |
| 10514 | |
| 10515 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 10516 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10517 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10518 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10519 | |
| 10520 | // HTTP/1.1 data for request. |
| 10521 | MockWrite http_writes[] = { |
| 10522 | MockWrite("GET / HTTP/1.1\r\n" |
| 10523 | "Host: alternative.example.org\r\n" |
| 10524 | "Connection: keep-alive\r\n\r\n"), |
| 10525 | }; |
| 10526 | |
| 10527 | MockRead http_reads[] = { |
| 10528 | MockRead("HTTP/1.1 200 OK\r\n" |
| 10529 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10530 | "Content-Length: 40\r\n\r\n" |
| 10531 | "first HTTP/1.1 response from alternative"), |
| 10532 | }; |
| 10533 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 10534 | http_writes, arraysize(http_writes)); |
| 10535 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 10536 | |
| 10537 | StaticSocketDataProvider data_refused; |
| 10538 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 10539 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 10540 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10541 | // Set up a QUIC alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10542 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10543 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10544 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10545 | AlternativeService alternative_service(kProtoQUIC, alternative); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10546 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10547 | http_server_properties->SetQuicAlternativeService( |
| 10548 | server, alternative_service, expiration, |
| 10549 | HttpNetworkSession::Params().quic_supported_versions); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10550 | // Mark the QUIC alternative service as broken. |
| 10551 | http_server_properties->MarkAlternativeServiceBroken(alternative_service); |
| 10552 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10553 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 10554 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10555 | request.method = "GET"; |
| 10556 | request.url = GURL(origin_url); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10557 | TestCompletionCallback callback; |
| 10558 | NetErrorDetails details; |
| 10559 | EXPECT_FALSE(details.quic_broken); |
| 10560 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10561 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10562 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10563 | EXPECT_TRUE(details.quic_broken); |
| 10564 | } |
| 10565 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10566 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicNotBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10567 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10568 | HostPortPair alternative1("alternative1.example.org", 443); |
| 10569 | HostPortPair alternative2("alternative2.example.org", 443); |
| 10570 | std::string origin_url = "https://origin.example.org:443"; |
| 10571 | std::string alternative_url1 = "https://alternative1.example.org:443"; |
| 10572 | std::string alternative_url2 = "https://alternative2.example.org:443"; |
| 10573 | |
| 10574 | // Negotiate HTTP/1.1 with alternative1.example.org. |
| 10575 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10576 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10577 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10578 | |
| 10579 | // HTTP/1.1 data for request. |
| 10580 | MockWrite http_writes[] = { |
| 10581 | MockWrite("GET / HTTP/1.1\r\n" |
| 10582 | "Host: alternative1.example.org\r\n" |
| 10583 | "Connection: keep-alive\r\n\r\n"), |
| 10584 | }; |
| 10585 | |
| 10586 | MockRead http_reads[] = { |
| 10587 | MockRead("HTTP/1.1 200 OK\r\n" |
| 10588 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10589 | "Content-Length: 40\r\n\r\n" |
| 10590 | "first HTTP/1.1 response from alternative1"), |
| 10591 | }; |
| 10592 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 10593 | http_writes, arraysize(http_writes)); |
| 10594 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 10595 | |
| 10596 | StaticSocketDataProvider data_refused; |
| 10597 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 10598 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 10599 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10600 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10601 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10602 | session->http_server_properties(); |
| 10603 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10604 | // Set up two QUIC alternative services for server. |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10605 | AlternativeServiceInfoVector alternative_service_info_vector; |
| 10606 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 10607 | |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10608 | AlternativeService alternative_service1(kProtoQUIC, alternative1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10609 | alternative_service_info_vector.push_back( |
| 10610 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 10611 | alternative_service1, expiration, |
| 10612 | session->params().quic_supported_versions)); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10613 | AlternativeService alternative_service2(kProtoQUIC, alternative2); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10614 | alternative_service_info_vector.push_back( |
| 10615 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 10616 | alternative_service2, expiration, |
| 10617 | session->params().quic_supported_versions)); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10618 | |
| 10619 | http_server_properties->SetAlternativeServices( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10620 | server, alternative_service_info_vector); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10621 | |
| 10622 | // Mark one of the QUIC alternative service as broken. |
| 10623 | http_server_properties->MarkAlternativeServiceBroken(alternative_service1); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10624 | EXPECT_EQ(2u, |
| 10625 | http_server_properties->GetAlternativeServiceInfos(server).size()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10626 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10627 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 10628 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10629 | request.method = "GET"; |
| 10630 | request.url = GURL(origin_url); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10631 | TestCompletionCallback callback; |
| 10632 | NetErrorDetails details; |
| 10633 | EXPECT_FALSE(details.quic_broken); |
| 10634 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10635 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10636 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10637 | EXPECT_FALSE(details.quic_broken); |
| 10638 | } |
| 10639 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10640 | TEST_F(HttpNetworkTransactionTest, MarkBrokenAlternateProtocolAndFallback) { |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10641 | HttpRequestInfo request; |
| 10642 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10643 | request.url = GURL("https://www.example.org/"); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10644 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10645 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10646 | StaticSocketDataProvider first_data; |
| 10647 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10648 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10649 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10650 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10651 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10652 | |
| 10653 | MockRead data_reads[] = { |
| 10654 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10655 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10656 | MockRead(ASYNC, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10657 | }; |
| 10658 | StaticSocketDataProvider second_data( |
| 10659 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10660 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10661 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10662 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10663 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10664 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10665 | session->http_server_properties(); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10666 | const url::SchemeHostPort server(request.url); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10667 | // Port must be < 1024, or the header will be ignored (since initial port was |
| 10668 | // port 80 (another restricted port). |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10669 | // Port is ignored by MockConnect anyway. |
| 10670 | const AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 10671 | 666); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10672 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10673 | http_server_properties->SetHttp2AlternativeService( |
| 10674 | server, alternative_service, expiration); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10675 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10676 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10677 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10678 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10679 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10680 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10681 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10682 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10683 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10684 | ASSERT_TRUE(response); |
| 10685 | ASSERT_TRUE(response->headers); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10686 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10687 | |
| 10688 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10689 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10690 | EXPECT_EQ("hello world", response_data); |
| 10691 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10692 | const AlternativeServiceInfoVector alternative_service_info_vector = |
| 10693 | http_server_properties->GetAlternativeServiceInfos(server); |
| 10694 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 10695 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 10696 | alternative_service_info_vector[0].alternative_service()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10697 | EXPECT_TRUE( |
| 10698 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10699 | } |
| 10700 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10701 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10702 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10703 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10704 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10705 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedBlocked) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10706 | HttpRequestInfo restricted_port_request; |
| 10707 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10708 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10709 | restricted_port_request.load_flags = 0; |
| 10710 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10711 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10712 | StaticSocketDataProvider first_data; |
| 10713 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10714 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10715 | |
| 10716 | MockRead data_reads[] = { |
| 10717 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10718 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10719 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10720 | }; |
| 10721 | StaticSocketDataProvider second_data( |
| 10722 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10723 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10724 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10725 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10726 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10727 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10728 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10729 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10730 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10731 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10732 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10733 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 10734 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10735 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10736 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10737 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10738 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10739 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10740 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10741 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10742 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10743 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 10744 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10745 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10746 | // Invalid change to unrestricted port should fail. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10747 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_REFUSED)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10748 | } |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10749 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10750 | // Ensure that we are allowed to redirect traffic via an alternate protocol to |
| 10751 | // an unrestricted (port >= 1024) when the original traffic was on a restricted |
| 10752 | // port (port < 1024) if we set |enable_user_alternate_protocol_ports|. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10753 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedPermitted) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10754 | session_deps_.enable_user_alternate_protocol_ports = true; |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10755 | |
| 10756 | HttpRequestInfo restricted_port_request; |
| 10757 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10758 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10759 | restricted_port_request.load_flags = 0; |
| 10760 | |
| 10761 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10762 | StaticSocketDataProvider first_data; |
| 10763 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10764 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10765 | |
| 10766 | MockRead data_reads[] = { |
| 10767 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10768 | MockRead("hello world"), |
| 10769 | MockRead(ASYNC, OK), |
| 10770 | }; |
| 10771 | StaticSocketDataProvider second_data( |
| 10772 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10773 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10774 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10775 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10776 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10777 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10778 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10779 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10780 | HttpServerProperties* http_server_properties = |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10781 | session->http_server_properties(); |
| 10782 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10783 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 10784 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10785 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10786 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10787 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10788 | expiration); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10789 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10790 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10791 | TestCompletionCallback callback; |
| 10792 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10793 | EXPECT_EQ(ERR_IO_PENDING, |
| 10794 | trans.Start(&restricted_port_request, callback.callback(), |
| 10795 | NetLogWithSource())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10796 | // Change to unrestricted port should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10797 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10798 | } |
| 10799 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10800 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10801 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10802 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10803 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10804 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedAllowed) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10805 | HttpRequestInfo restricted_port_request; |
| 10806 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10807 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10808 | restricted_port_request.load_flags = 0; |
| 10809 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10810 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10811 | StaticSocketDataProvider first_data; |
| 10812 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10813 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10814 | |
| 10815 | MockRead data_reads[] = { |
| 10816 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10817 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10818 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10819 | }; |
| 10820 | StaticSocketDataProvider second_data( |
| 10821 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10822 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10823 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10824 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10825 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10826 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10827 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10828 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10829 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10830 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10831 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10832 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 10833 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10834 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10835 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10836 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10837 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10838 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10839 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10840 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10841 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10842 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 10843 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10844 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10845 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10846 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10847 | } |
| 10848 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10849 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10850 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10851 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10852 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10853 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed1) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10854 | HttpRequestInfo unrestricted_port_request; |
| 10855 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10856 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10857 | unrestricted_port_request.load_flags = 0; |
| 10858 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10859 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10860 | StaticSocketDataProvider first_data; |
| 10861 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10862 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10863 | |
| 10864 | MockRead data_reads[] = { |
| 10865 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10866 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10867 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10868 | }; |
| 10869 | StaticSocketDataProvider second_data( |
| 10870 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10871 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10872 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10873 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10874 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10875 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10876 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10877 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10878 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10879 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10880 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10881 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 10882 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10883 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10884 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10885 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10886 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10887 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10888 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10889 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10890 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10891 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10892 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10893 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10894 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10895 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10896 | } |
| 10897 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10898 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10899 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10900 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10901 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10902 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed2) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10903 | HttpRequestInfo unrestricted_port_request; |
| 10904 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10905 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10906 | unrestricted_port_request.load_flags = 0; |
| 10907 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10908 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10909 | StaticSocketDataProvider first_data; |
| 10910 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10911 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10912 | |
| 10913 | MockRead data_reads[] = { |
| 10914 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10915 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10916 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10917 | }; |
| 10918 | StaticSocketDataProvider second_data( |
| 10919 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10920 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10921 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10922 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10923 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10924 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10925 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10926 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10927 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10928 | session->http_server_properties(); |
bnc | 0bbb0262 | 2015-07-23 10:06:22 | [diff] [blame] | 10929 | const int kUnrestrictedAlternatePort = 1025; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10930 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 10931 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10932 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10933 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10934 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10935 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10936 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10937 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10938 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10939 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10940 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10941 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10942 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10943 | // Valid change to an unrestricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10944 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10945 | } |
| 10946 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10947 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10948 | // to an unsafe port, and that we resume the second HttpStreamFactoryImpl::Job |
| 10949 | // once the alternate protocol request fails. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10950 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) { |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10951 | HttpRequestInfo request; |
| 10952 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10953 | request.url = GURL("http://www.example.org/"); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10954 | |
| 10955 | // The alternate protocol request will error out before we attempt to connect, |
| 10956 | // so only the standard HTTP request will try to connect. |
| 10957 | MockRead data_reads[] = { |
| 10958 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10959 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10960 | MockRead(ASYNC, OK), |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10961 | }; |
| 10962 | StaticSocketDataProvider data( |
| 10963 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10964 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10965 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10966 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10967 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10968 | HttpServerProperties* http_server_properties = |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10969 | session->http_server_properties(); |
| 10970 | const int kUnsafePort = 7; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10971 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 10972 | kUnsafePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10973 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10974 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10975 | url::SchemeHostPort(request.url), alternative_service, expiration); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10976 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10977 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10978 | TestCompletionCallback callback; |
| 10979 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10980 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10981 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10982 | // The HTTP request should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10983 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10984 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10985 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10986 | ASSERT_TRUE(response); |
| 10987 | ASSERT_TRUE(response->headers); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10988 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10989 | |
| 10990 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10991 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 10992 | EXPECT_EQ("hello world", response_data); |
| 10993 | } |
| 10994 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10995 | TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10996 | HttpRequestInfo request; |
| 10997 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10998 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10999 | |
| 11000 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11001 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11002 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11003 | MockRead("\r\n"), |
| 11004 | MockRead("hello world"), |
| 11005 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11006 | MockRead(ASYNC, OK)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11007 | |
| 11008 | StaticSocketDataProvider first_transaction( |
| 11009 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11010 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11011 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11012 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11013 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11014 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11015 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11016 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11017 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11018 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11019 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11020 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 11021 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11022 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11023 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11024 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11025 | }; |
| 11026 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11027 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11028 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11029 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11030 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11031 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11032 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 11033 | NULL, 0, NULL, 0); |
| 11034 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 11035 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11036 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11037 | &hanging_non_alternate_protocol_socket); |
| 11038 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11039 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11040 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11041 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11042 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11043 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11044 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11045 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11046 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11047 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11048 | |
| 11049 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11050 | ASSERT_TRUE(response); |
| 11051 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11052 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11053 | |
| 11054 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11055 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11056 | EXPECT_EQ("hello world", response_data); |
| 11057 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11058 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11059 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11060 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11061 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11062 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11063 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11064 | |
| 11065 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11066 | ASSERT_TRUE(response); |
| 11067 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11068 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11069 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11070 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11071 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11072 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11073 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11074 | } |
| 11075 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11076 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11077 | HttpRequestInfo request; |
| 11078 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11079 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11080 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11081 | // First transaction receives Alt-Svc header over HTTP/1.1. |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11082 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11083 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11084 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11085 | MockRead("\r\n"), |
| 11086 | MockRead("hello world"), |
| 11087 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11088 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11089 | }; |
| 11090 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11091 | StaticSocketDataProvider http11_data(data_reads, arraysize(data_reads), NULL, |
| 11092 | 0); |
| 11093 | session_deps_.socket_factory->AddSocketDataProvider(&http11_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11094 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11095 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 11096 | ssl_http11.cert = ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11097 | ASSERT_TRUE(ssl_http11.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11098 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
| 11099 | |
| 11100 | // Second transaction starts an alternative and a non-alternative Job. |
| 11101 | // Both sockets hang. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11102 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 11103 | StaticSocketDataProvider hanging_socket1(NULL, 0, NULL, 0); |
| 11104 | hanging_socket1.set_connect_data(never_finishing_connect); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 11105 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket1); |
| 11106 | |
| 11107 | StaticSocketDataProvider hanging_socket2(NULL, 0, NULL, 0); |
| 11108 | hanging_socket2.set_connect_data(never_finishing_connect); |
| 11109 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket2); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11110 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11111 | // Third transaction starts an alternative and a non-alternative job. |
| 11112 | // The non-alternative job hangs, but the alternative one succeeds. |
| 11113 | // The second transaction, still pending, binds to this socket. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11114 | SpdySerializedFrame req1( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11115 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11116 | SpdySerializedFrame req2( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11117 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 3, LOWEST)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11118 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11119 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 1), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11120 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 11121 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11122 | SpdySerializedFrame data1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 11123 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11124 | SpdySerializedFrame data2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11125 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11126 | CreateMockRead(resp1, 2), CreateMockRead(data1, 3), |
| 11127 | CreateMockRead(resp2, 4), CreateMockRead(data2, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11128 | MockRead(ASYNC, 0, 6), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11129 | }; |
| 11130 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11131 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11132 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11133 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11134 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11135 | AddSSLSocketData(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11136 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 11137 | StaticSocketDataProvider hanging_socket3(NULL, 0, NULL, 0); |
| 11138 | hanging_socket3.set_connect_data(never_finishing_connect); |
| 11139 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket3); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11140 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11141 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11142 | TestCompletionCallback callback1; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11143 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11144 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11145 | int rv = trans1.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11146 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11147 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11148 | |
| 11149 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11150 | ASSERT_TRUE(response); |
| 11151 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11152 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11153 | |
| 11154 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11155 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11156 | EXPECT_EQ("hello world", response_data); |
| 11157 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11158 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11159 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11160 | rv = trans2.Start(&request, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11161 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11162 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11163 | TestCompletionCallback callback3; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11164 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11165 | rv = trans3.Start(&request, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11166 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11167 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11168 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
| 11169 | EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11170 | |
| 11171 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11172 | ASSERT_TRUE(response); |
| 11173 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11174 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11175 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11176 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11177 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11178 | EXPECT_EQ("hello!", response_data); |
| 11179 | |
| 11180 | response = trans3.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11181 | ASSERT_TRUE(response); |
| 11182 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11183 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11184 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11185 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11186 | ASSERT_THAT(ReadTransaction(&trans3, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11187 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11188 | } |
| 11189 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11190 | TEST_F(HttpNetworkTransactionTest, StallAlternativeServiceForNpnSpdy) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11191 | HttpRequestInfo request; |
| 11192 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11193 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11194 | |
| 11195 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11196 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11197 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11198 | MockRead("\r\n"), |
| 11199 | MockRead("hello world"), |
| 11200 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11201 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11202 | }; |
| 11203 | |
| 11204 | StaticSocketDataProvider first_transaction( |
| 11205 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11206 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11207 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11208 | SSLSocketDataProvider ssl(ASYNC, OK); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 11209 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11210 | ASSERT_TRUE(ssl.cert); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11211 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11212 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11213 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11214 | StaticSocketDataProvider hanging_alternate_protocol_socket( |
| 11215 | NULL, 0, NULL, 0); |
| 11216 | hanging_alternate_protocol_socket.set_connect_data( |
| 11217 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11218 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11219 | &hanging_alternate_protocol_socket); |
| 11220 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11221 | // 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] | 11222 | StaticSocketDataProvider second_transaction(data_reads, arraysize(data_reads), |
| 11223 | NULL, 0); |
| 11224 | session_deps_.socket_factory->AddSocketDataProvider(&second_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11225 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11226 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11227 | TestCompletionCallback callback; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11228 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11229 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11230 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11231 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11232 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11233 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11234 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11235 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11236 | |
| 11237 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11238 | ASSERT_TRUE(response); |
| 11239 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11240 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11241 | |
| 11242 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11243 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11244 | EXPECT_EQ("hello world", response_data); |
| 11245 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11246 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11247 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11248 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11249 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11250 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11251 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11252 | |
| 11253 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11254 | ASSERT_TRUE(response); |
| 11255 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11256 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11257 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11258 | EXPECT_FALSE(response->was_alpn_negotiated); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11259 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11260 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11261 | EXPECT_EQ("hello world", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11262 | } |
| 11263 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11264 | class CapturingProxyResolver : public ProxyResolver { |
| 11265 | public: |
sammc | e90c921 | 2015-05-27 23:43:35 | [diff] [blame] | 11266 | CapturingProxyResolver() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11267 | ~CapturingProxyResolver() override {} |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11268 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11269 | int GetProxyForURL(const GURL& url, |
| 11270 | ProxyInfo* results, |
| 11271 | const CompletionCallback& callback, |
maksim.sisov | 7e15726 | 2016-10-20 11:19:55 | [diff] [blame] | 11272 | std::unique_ptr<Request>* request, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11273 | const NetLogWithSource& net_log) override { |
[email protected] | fae7669f | 2010-08-02 21:49:40 | [diff] [blame] | 11274 | ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, |
| 11275 | HostPortPair("myproxy", 80)); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11276 | results->UseProxyServer(proxy_server); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11277 | resolved_.push_back(url); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11278 | return OK; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11279 | } |
| 11280 | |
[email protected] | 2447640 | 2010-07-20 20:55:17 | [diff] [blame] | 11281 | const std::vector<GURL>& resolved() const { return resolved_; } |
| 11282 | |
| 11283 | private: |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11284 | std::vector<GURL> resolved_; |
| 11285 | |
| 11286 | DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); |
| 11287 | }; |
| 11288 | |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 11289 | class CapturingProxyResolverFactory : public ProxyResolverFactory { |
| 11290 | public: |
| 11291 | explicit CapturingProxyResolverFactory(CapturingProxyResolver* resolver) |
| 11292 | : ProxyResolverFactory(false), resolver_(resolver) {} |
| 11293 | |
| 11294 | int CreateProxyResolver( |
| 11295 | const scoped_refptr<ProxyResolverScriptData>& pac_script, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11296 | std::unique_ptr<ProxyResolver>* resolver, |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 11297 | const net::CompletionCallback& callback, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11298 | std::unique_ptr<Request>* request) override { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11299 | *resolver = std::make_unique<ForwardingProxyResolver>(resolver_); |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 11300 | return OK; |
| 11301 | } |
| 11302 | |
| 11303 | private: |
| 11304 | ProxyResolver* resolver_; |
| 11305 | }; |
| 11306 | |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11307 | // Test that proxy is resolved using the origin url, |
| 11308 | // regardless of the alternative server. |
| 11309 | TEST_F(HttpNetworkTransactionTest, UseOriginNotAlternativeForProxy) { |
| 11310 | // Configure proxy to bypass www.example.org, which is the origin URL. |
| 11311 | ProxyConfig proxy_config; |
| 11312 | proxy_config.proxy_rules().ParseFromString("myproxy:70"); |
| 11313 | proxy_config.proxy_rules().bypass_rules.AddRuleFromString("www.example.org"); |
| 11314 | auto proxy_config_service = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11315 | std::make_unique<ProxyConfigServiceFixed>(proxy_config); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11316 | |
| 11317 | CapturingProxyResolver capturing_proxy_resolver; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11318 | auto proxy_resolver_factory = std::make_unique<CapturingProxyResolverFactory>( |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11319 | &capturing_proxy_resolver); |
| 11320 | |
| 11321 | TestNetLog net_log; |
| 11322 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11323 | session_deps_.proxy_service = std::make_unique<ProxyService>( |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11324 | std::move(proxy_config_service), std::move(proxy_resolver_factory), |
| 11325 | &net_log); |
| 11326 | |
| 11327 | session_deps_.net_log = &net_log; |
| 11328 | |
| 11329 | // Configure alternative service with a hostname that is not bypassed by the |
| 11330 | // proxy. |
| 11331 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11332 | HttpServerProperties* http_server_properties = |
| 11333 | session->http_server_properties(); |
| 11334 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 11335 | HostPortPair alternative("www.example.com", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11336 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11337 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11338 | http_server_properties->SetHttp2AlternativeService( |
| 11339 | server, alternative_service, expiration); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11340 | |
| 11341 | // Non-alternative job should hang. |
| 11342 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
| 11343 | StaticSocketDataProvider hanging_alternate_protocol_socket(nullptr, 0, |
| 11344 | nullptr, 0); |
| 11345 | hanging_alternate_protocol_socket.set_connect_data(never_finishing_connect); |
| 11346 | session_deps_.socket_factory->AddSocketDataProvider( |
| 11347 | &hanging_alternate_protocol_socket); |
| 11348 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11349 | AddSSLSocketData(); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11350 | |
| 11351 | HttpRequestInfo request; |
| 11352 | request.method = "GET"; |
| 11353 | request.url = GURL("https://www.example.org/"); |
| 11354 | request.load_flags = 0; |
| 11355 | |
| 11356 | SpdySerializedFrame req( |
| 11357 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
| 11358 | |
| 11359 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
| 11360 | |
| 11361 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 11362 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 11363 | MockRead spdy_reads[] = { |
| 11364 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
| 11365 | }; |
| 11366 | |
| 11367 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11368 | arraysize(spdy_writes)); |
| 11369 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 11370 | |
| 11371 | TestCompletionCallback callback; |
| 11372 | |
| 11373 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 11374 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11375 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11376 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 11377 | |
| 11378 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 11379 | ASSERT_TRUE(response); |
| 11380 | ASSERT_TRUE(response->headers); |
| 11381 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 11382 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11383 | EXPECT_TRUE(response->was_alpn_negotiated); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11384 | |
| 11385 | std::string response_data; |
| 11386 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 11387 | EXPECT_EQ("hello!", response_data); |
| 11388 | |
| 11389 | // Origin host bypasses proxy, no resolution should have happened. |
| 11390 | ASSERT_TRUE(capturing_proxy_resolver.resolved().empty()); |
| 11391 | } |
| 11392 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11393 | TEST_F(HttpNetworkTransactionTest, UseAlternativeServiceForTunneledNpnSpdy) { |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11394 | ProxyConfig proxy_config; |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11395 | proxy_config.set_auto_detect(true); |
| 11396 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 11397 | |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11398 | CapturingProxyResolver capturing_proxy_resolver; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11399 | session_deps_.proxy_service = std::make_unique<ProxyService>( |
| 11400 | std::make_unique<ProxyConfigServiceFixed>(proxy_config), |
| 11401 | std::make_unique<CapturingProxyResolverFactory>( |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11402 | &capturing_proxy_resolver), |
| 11403 | nullptr); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11404 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11405 | session_deps_.net_log = &net_log; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11406 | |
| 11407 | HttpRequestInfo request; |
| 11408 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11409 | request.url = GURL("https://www.example.org/"); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11410 | |
| 11411 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11412 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11413 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11414 | MockRead("\r\n"), |
| 11415 | MockRead("hello world"), |
| 11416 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11417 | MockRead(ASYNC, OK), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11418 | }; |
| 11419 | |
| 11420 | StaticSocketDataProvider first_transaction( |
| 11421 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11422 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11423 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11424 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11425 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11426 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11427 | AddSSLSocketData(); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11428 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11429 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11430 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11431 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11432 | MockWrite(ASYNC, 0, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11433 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 11434 | "Host: www.example.org:443\r\n" |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11435 | "Proxy-Connection: keep-alive\r\n\r\n"), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11436 | CreateMockWrite(req, 2), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11437 | }; |
| 11438 | |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11439 | const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 11440 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 11441 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11442 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11443 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11444 | MockRead(ASYNC, 1, kCONNECTResponse), CreateMockRead(resp, 3), |
| 11445 | CreateMockRead(data, 4), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11446 | }; |
| 11447 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11448 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11449 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11450 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11451 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11452 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11453 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 11454 | NULL, 0, NULL, 0); |
| 11455 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 11456 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11457 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11458 | &hanging_non_alternate_protocol_socket); |
| 11459 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11460 | TestCompletionCallback callback; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11461 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11462 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11463 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11464 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11465 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11466 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 11467 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11468 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 11469 | |
| 11470 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 11471 | ASSERT_TRUE(response); |
| 11472 | ASSERT_TRUE(response->headers); |
| 11473 | EXPECT_EQ("HTTP/0.9 200 OK", response->headers->GetStatusLine()); |
| 11474 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11475 | EXPECT_TRUE(response->was_alpn_negotiated); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 11476 | |
| 11477 | std::string response_data; |
| 11478 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 11479 | EXPECT_EQ("hello world", response_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11480 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11481 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11482 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11483 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11484 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11485 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11486 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11487 | |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 11488 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11489 | ASSERT_TRUE(response); |
| 11490 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11491 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11492 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11493 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11494 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11495 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11496 | EXPECT_EQ("hello!", response_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11497 | ASSERT_EQ(2u, capturing_proxy_resolver.resolved().size()); |
| 11498 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11499 | capturing_proxy_resolver.resolved()[0].spec()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11500 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11501 | capturing_proxy_resolver.resolved()[1].spec()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11502 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11503 | LoadTimingInfo load_timing_info; |
| 11504 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 11505 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11506 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11507 | } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11508 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11509 | TEST_F(HttpNetworkTransactionTest, |
bnc | 1c196c6e | 2016-05-28 13:51:48 | [diff] [blame] | 11510 | UseAlternativeServiceForNpnSpdyWithExistingSpdySession) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11511 | HttpRequestInfo request; |
| 11512 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11513 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11514 | |
| 11515 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11516 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11517 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11518 | MockRead("\r\n"), |
| 11519 | MockRead("hello world"), |
| 11520 | MockRead(ASYNC, OK), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11521 | }; |
| 11522 | |
| 11523 | StaticSocketDataProvider first_transaction( |
| 11524 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11525 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11526 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11527 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11528 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11529 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11530 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11531 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11532 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11533 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11534 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11535 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 11536 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11537 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11538 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11539 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11540 | }; |
| 11541 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11542 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11543 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11544 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11545 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 11546 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11547 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11548 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11549 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11550 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11551 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11552 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11553 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11554 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11555 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11556 | |
| 11557 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11558 | ASSERT_TRUE(response); |
| 11559 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11560 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11561 | |
| 11562 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11563 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11564 | EXPECT_EQ("hello world", response_data); |
| 11565 | |
| 11566 | // Set up an initial SpdySession in the pool to reuse. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11567 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 11568 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 11569 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 11570 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 11571 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 11572 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11573 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11574 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11575 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11576 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11577 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11578 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11579 | |
| 11580 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11581 | ASSERT_TRUE(response); |
| 11582 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11583 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11584 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11585 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11586 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11587 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11588 | EXPECT_EQ("hello!", response_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11589 | } |
| 11590 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11591 | // GenerateAuthToken is a mighty big test. |
| 11592 | // It tests all permutation of GenerateAuthToken behavior: |
| 11593 | // - Synchronous and Asynchronous completion. |
| 11594 | // - OK or error on completion. |
| 11595 | // - Direct connection, non-authenticating proxy, and authenticating proxy. |
| 11596 | // - HTTP or HTTPS backend (to include proxy tunneling). |
| 11597 | // - Non-authenticating and authenticating backend. |
| 11598 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 11599 | // In all, there are 44 reasonable permuations (for example, if there are |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11600 | // problems generating an auth token for an authenticating proxy, we don't |
| 11601 | // need to test all permutations of the backend server). |
| 11602 | // |
| 11603 | // The test proceeds by going over each of the configuration cases, and |
| 11604 | // potentially running up to three rounds in each of the tests. The TestConfig |
| 11605 | // specifies both the configuration for the test as well as the expectations |
| 11606 | // for the results. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11607 | TEST_F(HttpNetworkTransactionTest, GenerateAuthToken) { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11608 | static const char kServer[] = "http://www.example.com"; |
| 11609 | static const char kSecureServer[] = "https://www.example.com"; |
| 11610 | static const char kProxy[] = "myproxy:70"; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11611 | |
| 11612 | enum AuthTiming { |
| 11613 | AUTH_NONE, |
| 11614 | AUTH_SYNC, |
| 11615 | AUTH_ASYNC, |
| 11616 | }; |
| 11617 | |
| 11618 | const MockWrite kGet( |
| 11619 | "GET / HTTP/1.1\r\n" |
| 11620 | "Host: www.example.com\r\n" |
| 11621 | "Connection: keep-alive\r\n\r\n"); |
| 11622 | const MockWrite kGetProxy( |
| 11623 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11624 | "Host: www.example.com\r\n" |
| 11625 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 11626 | const MockWrite kGetAuth( |
| 11627 | "GET / HTTP/1.1\r\n" |
| 11628 | "Host: www.example.com\r\n" |
| 11629 | "Connection: keep-alive\r\n" |
| 11630 | "Authorization: auth_token\r\n\r\n"); |
| 11631 | const MockWrite kGetProxyAuth( |
| 11632 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11633 | "Host: www.example.com\r\n" |
| 11634 | "Proxy-Connection: keep-alive\r\n" |
| 11635 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 11636 | const MockWrite kGetAuthThroughProxy( |
| 11637 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11638 | "Host: www.example.com\r\n" |
| 11639 | "Proxy-Connection: keep-alive\r\n" |
| 11640 | "Authorization: auth_token\r\n\r\n"); |
| 11641 | const MockWrite kGetAuthWithProxyAuth( |
| 11642 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11643 | "Host: www.example.com\r\n" |
| 11644 | "Proxy-Connection: keep-alive\r\n" |
| 11645 | "Proxy-Authorization: auth_token\r\n" |
| 11646 | "Authorization: auth_token\r\n\r\n"); |
| 11647 | const MockWrite kConnect( |
| 11648 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 11649 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11650 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 11651 | const MockWrite kConnectProxyAuth( |
| 11652 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 11653 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11654 | "Proxy-Connection: keep-alive\r\n" |
| 11655 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 11656 | |
| 11657 | const MockRead kSuccess( |
| 11658 | "HTTP/1.1 200 OK\r\n" |
| 11659 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11660 | "Content-Length: 3\r\n\r\n" |
| 11661 | "Yes"); |
| 11662 | const MockRead kFailure( |
| 11663 | "Should not be called."); |
| 11664 | const MockRead kServerChallenge( |
| 11665 | "HTTP/1.1 401 Unauthorized\r\n" |
| 11666 | "WWW-Authenticate: Mock realm=server\r\n" |
| 11667 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11668 | "Content-Length: 14\r\n\r\n" |
| 11669 | "Unauthorized\r\n"); |
| 11670 | const MockRead kProxyChallenge( |
| 11671 | "HTTP/1.1 407 Unauthorized\r\n" |
| 11672 | "Proxy-Authenticate: Mock realm=proxy\r\n" |
| 11673 | "Proxy-Connection: close\r\n" |
| 11674 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11675 | "Content-Length: 14\r\n\r\n" |
| 11676 | "Unauthorized\r\n"); |
| 11677 | const MockRead kProxyConnected( |
| 11678 | "HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 11679 | |
| 11680 | // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with |
| 11681 | // no constructors, but the C++ compiler on Windows warns about |
| 11682 | // unspecified data in compound literals. So, moved to using constructors, |
| 11683 | // and TestRound's created with the default constructor should not be used. |
| 11684 | struct TestRound { |
| 11685 | TestRound() |
| 11686 | : expected_rv(ERR_UNEXPECTED), |
| 11687 | extra_write(NULL), |
| 11688 | extra_read(NULL) { |
| 11689 | } |
| 11690 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 11691 | int expected_rv_arg) |
| 11692 | : write(write_arg), |
| 11693 | read(read_arg), |
| 11694 | expected_rv(expected_rv_arg), |
| 11695 | extra_write(NULL), |
| 11696 | extra_read(NULL) { |
| 11697 | } |
| 11698 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 11699 | int expected_rv_arg, const MockWrite* extra_write_arg, |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 11700 | const MockRead* extra_read_arg) |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11701 | : write(write_arg), |
| 11702 | read(read_arg), |
| 11703 | expected_rv(expected_rv_arg), |
| 11704 | extra_write(extra_write_arg), |
| 11705 | extra_read(extra_read_arg) { |
| 11706 | } |
| 11707 | MockWrite write; |
| 11708 | MockRead read; |
| 11709 | int expected_rv; |
| 11710 | const MockWrite* extra_write; |
| 11711 | const MockRead* extra_read; |
| 11712 | }; |
| 11713 | |
| 11714 | static const int kNoSSL = 500; |
| 11715 | |
| 11716 | struct TestConfig { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11717 | int line_number; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 11718 | const char* const proxy_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11719 | AuthTiming proxy_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11720 | int first_generate_proxy_token_rv; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 11721 | const char* const server_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11722 | AuthTiming server_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11723 | int first_generate_server_token_rv; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11724 | int num_auth_rounds; |
| 11725 | int first_ssl_round; |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11726 | TestRound rounds[4]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11727 | } test_configs[] = { |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11728 | // Non-authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11729 | {__LINE__, |
| 11730 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11731 | AUTH_NONE, |
| 11732 | OK, |
| 11733 | kServer, |
| 11734 | AUTH_NONE, |
| 11735 | OK, |
| 11736 | 1, |
| 11737 | kNoSSL, |
| 11738 | {TestRound(kGet, kSuccess, OK)}}, |
| 11739 | // Authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11740 | {__LINE__, |
| 11741 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11742 | AUTH_NONE, |
| 11743 | OK, |
| 11744 | kServer, |
| 11745 | AUTH_SYNC, |
| 11746 | OK, |
| 11747 | 2, |
| 11748 | kNoSSL, |
| 11749 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11750 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11751 | {__LINE__, |
| 11752 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11753 | AUTH_NONE, |
| 11754 | OK, |
| 11755 | kServer, |
| 11756 | AUTH_SYNC, |
| 11757 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11758 | 3, |
| 11759 | kNoSSL, |
| 11760 | {TestRound(kGet, kServerChallenge, OK), |
| 11761 | TestRound(kGet, kServerChallenge, OK), |
| 11762 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11763 | {__LINE__, |
| 11764 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11765 | AUTH_NONE, |
| 11766 | OK, |
| 11767 | kServer, |
| 11768 | AUTH_SYNC, |
| 11769 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 11770 | 2, |
| 11771 | kNoSSL, |
| 11772 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11773 | {__LINE__, |
| 11774 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11775 | AUTH_NONE, |
| 11776 | OK, |
| 11777 | kServer, |
| 11778 | AUTH_SYNC, |
| 11779 | ERR_UNDOCUMENTED_SECURITY_LIBRARY_STATUS, |
| 11780 | 2, |
| 11781 | kNoSSL, |
| 11782 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11783 | {__LINE__, |
| 11784 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11785 | AUTH_SYNC, |
| 11786 | ERR_FAILED, |
| 11787 | kServer, |
| 11788 | AUTH_NONE, |
| 11789 | OK, |
| 11790 | 2, |
| 11791 | kNoSSL, |
| 11792 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 11793 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11794 | {__LINE__, |
| 11795 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11796 | AUTH_ASYNC, |
| 11797 | ERR_FAILED, |
| 11798 | kServer, |
| 11799 | AUTH_NONE, |
| 11800 | OK, |
| 11801 | 2, |
| 11802 | kNoSSL, |
| 11803 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 11804 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11805 | {__LINE__, |
| 11806 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11807 | AUTH_NONE, |
| 11808 | OK, |
| 11809 | kServer, |
| 11810 | AUTH_SYNC, |
| 11811 | ERR_FAILED, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11812 | 2, |
| 11813 | kNoSSL, |
| 11814 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11815 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11816 | {__LINE__, |
| 11817 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11818 | AUTH_NONE, |
| 11819 | OK, |
| 11820 | kServer, |
| 11821 | AUTH_ASYNC, |
| 11822 | ERR_FAILED, |
| 11823 | 2, |
| 11824 | kNoSSL, |
| 11825 | {TestRound(kGet, kServerChallenge, OK), |
| 11826 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11827 | {__LINE__, |
| 11828 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11829 | AUTH_NONE, |
| 11830 | OK, |
| 11831 | kServer, |
| 11832 | AUTH_ASYNC, |
| 11833 | OK, |
| 11834 | 2, |
| 11835 | kNoSSL, |
| 11836 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11837 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11838 | {__LINE__, |
| 11839 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11840 | AUTH_NONE, |
| 11841 | OK, |
| 11842 | kServer, |
| 11843 | AUTH_ASYNC, |
| 11844 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11845 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11846 | kNoSSL, |
| 11847 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11848 | // The second round uses a HttpAuthHandlerMock that always succeeds. |
| 11849 | TestRound(kGet, kServerChallenge, OK), |
| 11850 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11851 | // Non-authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11852 | {__LINE__, |
| 11853 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11854 | AUTH_NONE, |
| 11855 | OK, |
| 11856 | kServer, |
| 11857 | AUTH_NONE, |
| 11858 | OK, |
| 11859 | 1, |
| 11860 | kNoSSL, |
| 11861 | {TestRound(kGetProxy, kSuccess, OK)}}, |
| 11862 | // Authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11863 | {__LINE__, |
| 11864 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11865 | AUTH_NONE, |
| 11866 | OK, |
| 11867 | kServer, |
| 11868 | AUTH_SYNC, |
| 11869 | OK, |
| 11870 | 2, |
| 11871 | kNoSSL, |
| 11872 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11873 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11874 | {__LINE__, |
| 11875 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11876 | AUTH_NONE, |
| 11877 | OK, |
| 11878 | kServer, |
| 11879 | AUTH_SYNC, |
| 11880 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11881 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11882 | kNoSSL, |
| 11883 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11884 | TestRound(kGetProxy, kServerChallenge, OK), |
| 11885 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11886 | {__LINE__, |
| 11887 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11888 | AUTH_NONE, |
| 11889 | OK, |
| 11890 | kServer, |
| 11891 | AUTH_ASYNC, |
| 11892 | OK, |
| 11893 | 2, |
| 11894 | kNoSSL, |
| 11895 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11896 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11897 | {__LINE__, |
| 11898 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11899 | AUTH_NONE, |
| 11900 | OK, |
| 11901 | kServer, |
| 11902 | AUTH_ASYNC, |
| 11903 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11904 | 2, |
| 11905 | kNoSSL, |
| 11906 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11907 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11908 | // Non-authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11909 | {__LINE__, |
| 11910 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11911 | AUTH_SYNC, |
| 11912 | OK, |
| 11913 | kServer, |
| 11914 | AUTH_NONE, |
| 11915 | OK, |
| 11916 | 2, |
| 11917 | kNoSSL, |
| 11918 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11919 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11920 | {__LINE__, |
| 11921 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11922 | AUTH_SYNC, |
| 11923 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11924 | kServer, |
| 11925 | AUTH_NONE, |
| 11926 | OK, |
| 11927 | 2, |
| 11928 | kNoSSL, |
| 11929 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11930 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11931 | {__LINE__, |
| 11932 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11933 | AUTH_ASYNC, |
| 11934 | OK, |
| 11935 | kServer, |
| 11936 | AUTH_NONE, |
| 11937 | OK, |
| 11938 | 2, |
| 11939 | kNoSSL, |
| 11940 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11941 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11942 | {__LINE__, |
| 11943 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11944 | AUTH_ASYNC, |
| 11945 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11946 | kServer, |
| 11947 | AUTH_NONE, |
| 11948 | OK, |
| 11949 | 2, |
| 11950 | kNoSSL, |
| 11951 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11952 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11953 | {__LINE__, |
| 11954 | kProxy, |
| 11955 | AUTH_ASYNC, |
| 11956 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11957 | kServer, |
| 11958 | AUTH_NONE, |
| 11959 | OK, |
| 11960 | 3, |
| 11961 | kNoSSL, |
| 11962 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 11963 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 11964 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11965 | // Authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11966 | {__LINE__, |
| 11967 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11968 | AUTH_SYNC, |
| 11969 | OK, |
| 11970 | kServer, |
| 11971 | AUTH_SYNC, |
| 11972 | OK, |
| 11973 | 3, |
| 11974 | kNoSSL, |
| 11975 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11976 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 11977 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11978 | {__LINE__, |
| 11979 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11980 | AUTH_SYNC, |
| 11981 | OK, |
| 11982 | kServer, |
| 11983 | AUTH_SYNC, |
| 11984 | ERR_INVALID_AUTH_CREDENTIALS, |
| 11985 | 3, |
| 11986 | kNoSSL, |
| 11987 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11988 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11989 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
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_ASYNC, |
| 11993 | OK, |
| 11994 | kServer, |
| 11995 | AUTH_SYNC, |
| 11996 | OK, |
| 11997 | 3, |
| 11998 | kNoSSL, |
| 11999 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12000 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12001 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12002 | {__LINE__, |
| 12003 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12004 | AUTH_ASYNC, |
| 12005 | OK, |
| 12006 | kServer, |
| 12007 | AUTH_SYNC, |
| 12008 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12009 | 3, |
| 12010 | kNoSSL, |
| 12011 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12012 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12013 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12014 | {__LINE__, |
| 12015 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12016 | AUTH_SYNC, |
| 12017 | OK, |
| 12018 | kServer, |
| 12019 | AUTH_ASYNC, |
| 12020 | OK, |
| 12021 | 3, |
| 12022 | kNoSSL, |
| 12023 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12024 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12025 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12026 | {__LINE__, |
| 12027 | kProxy, |
| 12028 | AUTH_SYNC, |
| 12029 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12030 | kServer, |
| 12031 | AUTH_ASYNC, |
| 12032 | OK, |
| 12033 | 4, |
| 12034 | kNoSSL, |
| 12035 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12036 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 12037 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12038 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 12039 | {__LINE__, |
| 12040 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12041 | AUTH_SYNC, |
| 12042 | OK, |
| 12043 | kServer, |
| 12044 | AUTH_ASYNC, |
| 12045 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12046 | 3, |
| 12047 | kNoSSL, |
| 12048 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12049 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12050 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12051 | {__LINE__, |
| 12052 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12053 | AUTH_ASYNC, |
| 12054 | OK, |
| 12055 | kServer, |
| 12056 | AUTH_ASYNC, |
| 12057 | OK, |
| 12058 | 3, |
| 12059 | kNoSSL, |
| 12060 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12061 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12062 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12063 | {__LINE__, |
| 12064 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12065 | AUTH_ASYNC, |
| 12066 | OK, |
| 12067 | kServer, |
| 12068 | AUTH_ASYNC, |
| 12069 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12070 | 3, |
| 12071 | kNoSSL, |
| 12072 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12073 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12074 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12075 | {__LINE__, |
| 12076 | kProxy, |
| 12077 | AUTH_ASYNC, |
| 12078 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12079 | kServer, |
| 12080 | AUTH_ASYNC, |
| 12081 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12082 | 4, |
| 12083 | kNoSSL, |
| 12084 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12085 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 12086 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12087 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12088 | // Non-authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12089 | {__LINE__, |
| 12090 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12091 | AUTH_NONE, |
| 12092 | OK, |
| 12093 | kSecureServer, |
| 12094 | AUTH_NONE, |
| 12095 | OK, |
| 12096 | 1, |
| 12097 | 0, |
| 12098 | {TestRound(kGet, kSuccess, OK)}}, |
| 12099 | // Authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12100 | {__LINE__, |
| 12101 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12102 | AUTH_NONE, |
| 12103 | OK, |
| 12104 | kSecureServer, |
| 12105 | AUTH_SYNC, |
| 12106 | OK, |
| 12107 | 2, |
| 12108 | 0, |
| 12109 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12110 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12111 | {__LINE__, |
| 12112 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12113 | AUTH_NONE, |
| 12114 | OK, |
| 12115 | kSecureServer, |
| 12116 | AUTH_SYNC, |
| 12117 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12118 | 2, |
| 12119 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12120 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12121 | {__LINE__, |
| 12122 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12123 | AUTH_NONE, |
| 12124 | OK, |
| 12125 | kSecureServer, |
| 12126 | AUTH_ASYNC, |
| 12127 | OK, |
| 12128 | 2, |
| 12129 | 0, |
| 12130 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12131 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12132 | {__LINE__, |
| 12133 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12134 | AUTH_NONE, |
| 12135 | OK, |
| 12136 | kSecureServer, |
| 12137 | AUTH_ASYNC, |
| 12138 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12139 | 2, |
| 12140 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12141 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12142 | // Non-authenticating HTTPS server with a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12143 | {__LINE__, |
| 12144 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12145 | AUTH_NONE, |
| 12146 | OK, |
| 12147 | kSecureServer, |
| 12148 | AUTH_NONE, |
| 12149 | OK, |
| 12150 | 1, |
| 12151 | 0, |
| 12152 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 12153 | // Authenticating HTTPS server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12154 | {__LINE__, |
| 12155 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12156 | AUTH_NONE, |
| 12157 | OK, |
| 12158 | kSecureServer, |
| 12159 | AUTH_SYNC, |
| 12160 | OK, |
| 12161 | 2, |
| 12162 | 0, |
| 12163 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12164 | TestRound(kGetAuth, 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_NONE, |
| 12168 | OK, |
| 12169 | kSecureServer, |
| 12170 | AUTH_SYNC, |
| 12171 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12172 | 2, |
| 12173 | 0, |
| 12174 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12175 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12176 | {__LINE__, |
| 12177 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12178 | AUTH_NONE, |
| 12179 | OK, |
| 12180 | kSecureServer, |
| 12181 | AUTH_ASYNC, |
| 12182 | OK, |
| 12183 | 2, |
| 12184 | 0, |
| 12185 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12186 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12187 | {__LINE__, |
| 12188 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12189 | AUTH_NONE, |
| 12190 | OK, |
| 12191 | kSecureServer, |
| 12192 | AUTH_ASYNC, |
| 12193 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12194 | 2, |
| 12195 | 0, |
| 12196 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12197 | TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12198 | // Non-Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12199 | {__LINE__, |
| 12200 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12201 | AUTH_SYNC, |
| 12202 | OK, |
| 12203 | kSecureServer, |
| 12204 | AUTH_NONE, |
| 12205 | OK, |
| 12206 | 2, |
| 12207 | 1, |
| 12208 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12209 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12210 | {__LINE__, |
| 12211 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12212 | AUTH_SYNC, |
| 12213 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12214 | kSecureServer, |
| 12215 | AUTH_NONE, |
| 12216 | OK, |
| 12217 | 2, |
| 12218 | kNoSSL, |
| 12219 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12220 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12221 | {__LINE__, |
| 12222 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12223 | AUTH_SYNC, |
| 12224 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 12225 | kSecureServer, |
| 12226 | AUTH_NONE, |
| 12227 | OK, |
| 12228 | 2, |
| 12229 | kNoSSL, |
| 12230 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12231 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12232 | {__LINE__, |
| 12233 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12234 | AUTH_SYNC, |
| 12235 | ERR_UNEXPECTED, |
| 12236 | kSecureServer, |
| 12237 | AUTH_NONE, |
| 12238 | OK, |
| 12239 | 2, |
| 12240 | kNoSSL, |
| 12241 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12242 | TestRound(kConnect, kProxyConnected, ERR_UNEXPECTED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12243 | {__LINE__, |
| 12244 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12245 | AUTH_ASYNC, |
| 12246 | OK, |
| 12247 | kSecureServer, |
| 12248 | AUTH_NONE, |
| 12249 | OK, |
| 12250 | 2, |
| 12251 | 1, |
| 12252 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12253 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12254 | {__LINE__, |
| 12255 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12256 | AUTH_ASYNC, |
| 12257 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12258 | kSecureServer, |
| 12259 | AUTH_NONE, |
| 12260 | OK, |
| 12261 | 2, |
| 12262 | kNoSSL, |
| 12263 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12264 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12265 | // Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12266 | {__LINE__, |
| 12267 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12268 | AUTH_SYNC, |
| 12269 | OK, |
| 12270 | kSecureServer, |
| 12271 | AUTH_SYNC, |
| 12272 | OK, |
| 12273 | 3, |
| 12274 | 1, |
| 12275 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12276 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12277 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12278 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12279 | {__LINE__, |
| 12280 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12281 | AUTH_SYNC, |
| 12282 | OK, |
| 12283 | kSecureServer, |
| 12284 | AUTH_SYNC, |
| 12285 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12286 | 3, |
| 12287 | 1, |
| 12288 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12289 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12290 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12291 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12292 | {__LINE__, |
| 12293 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12294 | AUTH_ASYNC, |
| 12295 | OK, |
| 12296 | kSecureServer, |
| 12297 | AUTH_SYNC, |
| 12298 | OK, |
| 12299 | 3, |
| 12300 | 1, |
| 12301 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12302 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12303 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12304 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12305 | {__LINE__, |
| 12306 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12307 | AUTH_ASYNC, |
| 12308 | OK, |
| 12309 | kSecureServer, |
| 12310 | AUTH_SYNC, |
| 12311 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12312 | 3, |
| 12313 | 1, |
| 12314 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12315 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12316 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12317 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12318 | {__LINE__, |
| 12319 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12320 | AUTH_SYNC, |
| 12321 | OK, |
| 12322 | kSecureServer, |
| 12323 | AUTH_ASYNC, |
| 12324 | OK, |
| 12325 | 3, |
| 12326 | 1, |
| 12327 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12328 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12329 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12330 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12331 | {__LINE__, |
| 12332 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12333 | AUTH_SYNC, |
| 12334 | OK, |
| 12335 | kSecureServer, |
| 12336 | AUTH_ASYNC, |
| 12337 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12338 | 3, |
| 12339 | 1, |
| 12340 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12341 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12342 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12343 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12344 | {__LINE__, |
| 12345 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12346 | AUTH_ASYNC, |
| 12347 | OK, |
| 12348 | kSecureServer, |
| 12349 | AUTH_ASYNC, |
| 12350 | OK, |
| 12351 | 3, |
| 12352 | 1, |
| 12353 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12354 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12355 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12356 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12357 | {__LINE__, |
| 12358 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12359 | AUTH_ASYNC, |
| 12360 | OK, |
| 12361 | kSecureServer, |
| 12362 | AUTH_ASYNC, |
| 12363 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12364 | 3, |
| 12365 | 1, |
| 12366 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12367 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12368 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12369 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12370 | {__LINE__, |
| 12371 | kProxy, |
| 12372 | AUTH_ASYNC, |
| 12373 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12374 | kSecureServer, |
| 12375 | AUTH_ASYNC, |
| 12376 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12377 | 4, |
| 12378 | 2, |
| 12379 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12380 | TestRound(kConnect, kProxyChallenge, OK), |
| 12381 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12382 | &kServerChallenge), |
| 12383 | TestRound(kGet, kSuccess, OK)}}, |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12384 | }; |
| 12385 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12386 | for (const auto& test_config : test_configs) { |
| 12387 | SCOPED_TRACE(::testing::Message() << "Test config at " |
| 12388 | << test_config.line_number); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12389 | HttpAuthHandlerMock::Factory* auth_factory( |
| 12390 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12391 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 12392 | SSLInfo empty_ssl_info; |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 12393 | |
| 12394 | // Set up authentication handlers as necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12395 | if (test_config.proxy_auth_timing != AUTH_NONE) { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12396 | for (int n = 0; n < 3; n++) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12397 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 12398 | std::string auth_challenge = "Mock realm=proxy"; |
| 12399 | GURL origin(test_config.proxy_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 12400 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 12401 | auth_challenge.end()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12402 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12403 | empty_ssl_info, origin, |
| 12404 | NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12405 | auth_handler->SetGenerateExpectation( |
| 12406 | test_config.proxy_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12407 | n == 0 ? test_config.first_generate_proxy_token_rv : OK); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12408 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 12409 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12410 | } |
| 12411 | if (test_config.server_auth_timing != AUTH_NONE) { |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 12412 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12413 | std::string auth_challenge = "Mock realm=server"; |
| 12414 | GURL origin(test_config.server_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 12415 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 12416 | auth_challenge.end()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12417 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12418 | empty_ssl_info, origin, |
| 12419 | NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12420 | auth_handler->SetGenerateExpectation( |
| 12421 | test_config.server_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12422 | test_config.first_generate_server_token_rv); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12423 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12424 | |
| 12425 | // The second handler always succeeds. It should only be used where there |
| 12426 | // are multiple auth sessions for server auth in the same network |
| 12427 | // transaction using the same auth scheme. |
| 12428 | std::unique_ptr<HttpAuthHandlerMock> second_handler = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12429 | std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12430 | second_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 12431 | empty_ssl_info, origin, |
| 12432 | NetLogWithSource()); |
| 12433 | second_handler->SetGenerateExpectation(true, OK); |
| 12434 | auth_factory->AddMockHandler(second_handler.release(), |
| 12435 | HttpAuth::AUTH_SERVER); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12436 | } |
| 12437 | if (test_config.proxy_url) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12438 | session_deps_.proxy_service = |
| 12439 | ProxyService::CreateFixed(test_config.proxy_url); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12440 | } else { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12441 | session_deps_.proxy_service = ProxyService::CreateDirect(); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12442 | } |
| 12443 | |
| 12444 | HttpRequestInfo request; |
| 12445 | request.method = "GET"; |
| 12446 | request.url = GURL(test_config.server_url); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12447 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12448 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12449 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12450 | SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
| 12451 | |
| 12452 | std::vector<std::vector<MockRead>> mock_reads(1); |
| 12453 | std::vector<std::vector<MockWrite>> mock_writes(1); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12454 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 12455 | SCOPED_TRACE(round); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12456 | const TestRound& read_write_round = test_config.rounds[round]; |
| 12457 | |
| 12458 | // Set up expected reads and writes. |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12459 | mock_reads.back().push_back(read_write_round.read); |
| 12460 | mock_writes.back().push_back(read_write_round.write); |
| 12461 | |
| 12462 | // kProxyChallenge uses Proxy-Connection: close which means that the |
| 12463 | // socket is closed and a new one will be created for the next request. |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 12464 | if (read_write_round.read.data == kProxyChallenge.data) { |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12465 | mock_reads.push_back(std::vector<MockRead>()); |
| 12466 | mock_writes.push_back(std::vector<MockWrite>()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12467 | } |
| 12468 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12469 | if (read_write_round.extra_read) { |
| 12470 | mock_reads.back().push_back(*read_write_round.extra_read); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12471 | } |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12472 | if (read_write_round.extra_write) { |
| 12473 | mock_writes.back().push_back(*read_write_round.extra_write); |
| 12474 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12475 | |
| 12476 | // Add an SSL sequence if necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12477 | if (round >= test_config.first_ssl_round) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12478 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12479 | &ssl_socket_data_provider); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12480 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12481 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12482 | std::vector<std::unique_ptr<StaticSocketDataProvider>> data_providers; |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12483 | for (size_t i = 0; i < mock_reads.size(); ++i) { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12484 | data_providers.push_back(std::make_unique<StaticSocketDataProvider>( |
davidben | 5f8b6bc | 2015-11-25 03:19:54 | [diff] [blame] | 12485 | mock_reads[i].data(), mock_reads[i].size(), mock_writes[i].data(), |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12486 | mock_writes[i].size())); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12487 | session_deps_.socket_factory->AddSocketDataProvider( |
olli.raula | 525048c | 2015-12-10 07:38:32 | [diff] [blame] | 12488 | data_providers.back().get()); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12489 | } |
| 12490 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12491 | // Transaction must be created after DataProviders, so it's destroyed before |
| 12492 | // they are as well. |
| 12493 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 12494 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12495 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 12496 | SCOPED_TRACE(round); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12497 | const TestRound& read_write_round = test_config.rounds[round]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12498 | // Start or restart the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12499 | TestCompletionCallback callback; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12500 | int rv; |
| 12501 | if (round == 0) { |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12502 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12503 | } else { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12504 | rv = trans.RestartWithAuth( |
| 12505 | AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12506 | } |
| 12507 | if (rv == ERR_IO_PENDING) |
| 12508 | rv = callback.WaitForResult(); |
| 12509 | |
| 12510 | // Compare results with expected data. |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12511 | EXPECT_THAT(rv, IsError(read_write_round.expected_rv)); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12512 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | c0c82849 | 2015-05-15 01:25:55 | [diff] [blame] | 12513 | if (read_write_round.expected_rv != OK) { |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12514 | EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
| 12515 | continue; |
| 12516 | } |
| 12517 | if (round + 1 < test_config.num_auth_rounds) { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12518 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12519 | } else { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12520 | EXPECT_FALSE(response->auth_challenge); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12521 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12522 | } |
| 12523 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 12524 | } |
| 12525 | } |
| 12526 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12527 | TEST_F(HttpNetworkTransactionTest, MultiRoundAuth) { |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12528 | // Do multi-round authentication and make sure it works correctly. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12529 | HttpAuthHandlerMock::Factory* auth_factory( |
| 12530 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12531 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12532 | session_deps_.proxy_service = ProxyService::CreateDirect(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12533 | session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
| 12534 | session_deps_.host_resolver->set_synchronous_mode(true); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12535 | |
| 12536 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 12537 | auth_handler->set_connection_based(true); |
| 12538 | std::string auth_challenge = "Mock realm=server"; |
| 12539 | GURL origin("http://www.example.com"); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 12540 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 12541 | auth_challenge.end()); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 12542 | SSLInfo empty_ssl_info; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12543 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12544 | empty_ssl_info, origin, NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12545 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12546 | |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12547 | int rv = OK; |
| 12548 | const HttpResponseInfo* response = NULL; |
| 12549 | HttpRequestInfo request; |
| 12550 | request.method = "GET"; |
| 12551 | request.url = origin; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12552 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12553 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12554 | |
| 12555 | // Use a TCP Socket Pool with only one connection per group. This is used |
| 12556 | // to validate that the TCP socket is not released to the pool between |
| 12557 | // each round of multi-round authentication. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12558 | HttpNetworkSessionPeer session_peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12559 | TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12560 | 50, // Max sockets for pool |
| 12561 | 1, // Max sockets per group |
tbansal | 7b403bcc | 2016-04-13 22:33:21 | [diff] [blame] | 12562 | session_deps_.host_resolver.get(), session_deps_.socket_factory.get(), |
| 12563 | NULL, session_deps_.net_log); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12564 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 12565 | mock_pool_manager->SetTransportSocketPool(transport_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 12566 | session_peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12567 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12568 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12569 | TestCompletionCallback callback; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12570 | |
| 12571 | const MockWrite kGet( |
| 12572 | "GET / HTTP/1.1\r\n" |
| 12573 | "Host: www.example.com\r\n" |
| 12574 | "Connection: keep-alive\r\n\r\n"); |
| 12575 | const MockWrite kGetAuth( |
| 12576 | "GET / HTTP/1.1\r\n" |
| 12577 | "Host: www.example.com\r\n" |
| 12578 | "Connection: keep-alive\r\n" |
| 12579 | "Authorization: auth_token\r\n\r\n"); |
| 12580 | |
| 12581 | const MockRead kServerChallenge( |
| 12582 | "HTTP/1.1 401 Unauthorized\r\n" |
| 12583 | "WWW-Authenticate: Mock realm=server\r\n" |
| 12584 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12585 | "Content-Length: 14\r\n\r\n" |
| 12586 | "Unauthorized\r\n"); |
| 12587 | const MockRead kSuccess( |
| 12588 | "HTTP/1.1 200 OK\r\n" |
| 12589 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12590 | "Content-Length: 3\r\n\r\n" |
| 12591 | "Yes"); |
| 12592 | |
| 12593 | MockWrite writes[] = { |
| 12594 | // First round |
| 12595 | kGet, |
| 12596 | // Second round |
| 12597 | kGetAuth, |
| 12598 | // Third round |
| 12599 | kGetAuth, |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 12600 | // Fourth round |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12601 | kGetAuth, |
| 12602 | // Competing request |
| 12603 | kGet, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12604 | }; |
| 12605 | MockRead reads[] = { |
| 12606 | // First round |
| 12607 | kServerChallenge, |
| 12608 | // Second round |
| 12609 | kServerChallenge, |
| 12610 | // Third round |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 12611 | kServerChallenge, |
| 12612 | // Fourth round |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12613 | kSuccess, |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12614 | // Competing response |
| 12615 | kSuccess, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12616 | }; |
| 12617 | StaticSocketDataProvider data_provider(reads, arraysize(reads), |
| 12618 | writes, arraysize(writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12619 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12620 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 12621 | const char kSocketGroup[] = "www.example.com:80"; |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12622 | |
| 12623 | // First round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12624 | auth_handler->SetGenerateExpectation(false, OK); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12625 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12626 | if (rv == ERR_IO_PENDING) |
| 12627 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12628 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12629 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12630 | ASSERT_TRUE(response); |
| 12631 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12632 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12633 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 12634 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12635 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12636 | // In between rounds, another request comes in for the same domain. |
| 12637 | // It should not be able to grab the TCP socket that trans has already |
| 12638 | // claimed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12639 | HttpNetworkTransaction trans_compete(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12640 | TestCompletionCallback callback_compete; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12641 | rv = trans_compete.Start(&request, callback_compete.callback(), |
| 12642 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12643 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12644 | // callback_compete.WaitForResult at this point would stall forever, |
| 12645 | // since the HttpNetworkTransaction does not release the request back to |
| 12646 | // the pool until after authentication completes. |
| 12647 | |
| 12648 | // Second round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12649 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12650 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12651 | if (rv == ERR_IO_PENDING) |
| 12652 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12653 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12654 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12655 | ASSERT_TRUE(response); |
| 12656 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12657 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12658 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 12659 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12660 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12661 | // Third round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12662 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12663 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12664 | if (rv == ERR_IO_PENDING) |
| 12665 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12666 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12667 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12668 | ASSERT_TRUE(response); |
| 12669 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12670 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12671 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 12672 | auth_handler->state()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 12673 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12674 | // Fourth round of authentication, which completes successfully. |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 12675 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12676 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 12677 | if (rv == ERR_IO_PENDING) |
| 12678 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12679 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12680 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12681 | ASSERT_TRUE(response); |
| 12682 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12683 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12684 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12685 | // In WAIT_FOR_CHALLENGE, although in reality the auth handler is done. A real |
| 12686 | // auth handler should transition to a DONE state in concert with the remote |
| 12687 | // server. But that's not something we can test here with a mock handler. |
| 12688 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_CHALLENGE, |
| 12689 | auth_handler->state()); |
| 12690 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12691 | // Read the body since the fourth round was successful. This will also |
| 12692 | // release the socket back to the pool. |
| 12693 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(50)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12694 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12695 | if (rv == ERR_IO_PENDING) |
| 12696 | rv = callback.WaitForResult(); |
| 12697 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12698 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12699 | EXPECT_EQ(0, rv); |
| 12700 | // There are still 0 idle sockets, since the trans_compete transaction |
| 12701 | // will be handed it immediately after trans releases it to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12702 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12703 | |
| 12704 | // The competing request can now finish. Wait for the headers and then |
| 12705 | // read the body. |
| 12706 | rv = callback_compete.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12707 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12708 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12709 | if (rv == ERR_IO_PENDING) |
| 12710 | rv = callback.WaitForResult(); |
| 12711 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12712 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12713 | EXPECT_EQ(0, rv); |
| 12714 | |
| 12715 | // Finally, the socket is released to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12716 | EXPECT_EQ(1, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12717 | } |
| 12718 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12719 | // This tests the case that a request is issued via http instead of spdy after |
| 12720 | // npn is negotiated. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12721 | TEST_F(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12722 | HttpRequestInfo request; |
| 12723 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12724 | request.url = GURL("https://www.example.org/"); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12725 | |
| 12726 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12727 | MockWrite( |
| 12728 | "GET / HTTP/1.1\r\n" |
| 12729 | "Host: www.example.org\r\n" |
| 12730 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12731 | }; |
| 12732 | |
| 12733 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12734 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12735 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12736 | MockRead("\r\n"), |
| 12737 | MockRead("hello world"), |
| 12738 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12739 | }; |
| 12740 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12741 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12742 | ssl.next_proto = kProtoHTTP11; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12743 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12744 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12745 | |
| 12746 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 12747 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12748 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12749 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12750 | TestCompletionCallback callback; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12751 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12752 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12753 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12754 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12755 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12756 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12757 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12758 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12759 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12760 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12761 | ASSERT_TRUE(response); |
| 12762 | ASSERT_TRUE(response->headers); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12763 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12764 | |
| 12765 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12766 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12767 | EXPECT_EQ("hello world", response_data); |
| 12768 | |
| 12769 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12770 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12771 | } |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12772 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12773 | // Simulate the SSL handshake completing with an NPN negotiation followed by an |
| 12774 | // immediate server closing of the socket. |
| 12775 | // Regression test for https://crbug.com/46369. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12776 | TEST_F(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12777 | HttpRequestInfo request; |
| 12778 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12779 | request.url = GURL("https://www.example.org/"); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12780 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12781 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12782 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12783 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12784 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12785 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 12786 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12787 | MockWrite spdy_writes[] = {CreateMockWrite(req, 1)}; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12788 | |
| 12789 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12790 | MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12791 | }; |
| 12792 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12793 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 12794 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12795 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12796 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12797 | TestCompletionCallback callback; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12798 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12799 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12800 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12801 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12802 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12803 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12804 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12805 | } |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 12806 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 12807 | // A subclass of HttpAuthHandlerMock that records the request URL when |
| 12808 | // it gets it. This is needed since the auth handler may get destroyed |
| 12809 | // before we get a chance to query it. |
| 12810 | class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock { |
| 12811 | public: |
| 12812 | explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {} |
| 12813 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12814 | ~UrlRecordingHttpAuthHandlerMock() override {} |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 12815 | |
| 12816 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12817 | int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 12818 | const HttpRequestInfo* request, |
| 12819 | const CompletionCallback& callback, |
| 12820 | std::string* auth_token) override { |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 12821 | *url_ = request->url; |
| 12822 | return HttpAuthHandlerMock::GenerateAuthTokenImpl( |
| 12823 | credentials, request, callback, auth_token); |
| 12824 | } |
| 12825 | |
| 12826 | private: |
| 12827 | GURL* url_; |
| 12828 | }; |
| 12829 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12830 | // Test that if we cancel the transaction as the connection is completing, that |
| 12831 | // everything tears down correctly. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12832 | TEST_F(HttpNetworkTransactionTest, SimpleCancel) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12833 | // Setup everything about the connection to complete synchronously, so that |
| 12834 | // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
| 12835 | // for is the callback from the HttpStreamRequest. |
| 12836 | // Then cancel the transaction. |
| 12837 | // Verify that we don't crash. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12838 | MockConnect mock_connect(SYNCHRONOUS, OK); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12839 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12840 | MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), |
| 12841 | MockRead(SYNCHRONOUS, "hello world"), |
| 12842 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12843 | }; |
| 12844 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12845 | HttpRequestInfo request; |
| 12846 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12847 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12848 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12849 | session_deps_.host_resolver->set_synchronous_mode(true); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12850 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12851 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12852 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12853 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12854 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 12855 | data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12856 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12857 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12858 | TestCompletionCallback callback; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12859 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12860 | BoundTestNetLog log; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12861 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12862 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12863 | trans.reset(); // Cancel the transaction here. |
| 12864 | |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 12865 | base::RunLoop().RunUntilIdle(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 12866 | } |
| 12867 | |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12868 | // Test that if a transaction is cancelled after receiving the headers, the |
| 12869 | // stream is drained properly and added back to the socket pool. The main |
| 12870 | // purpose of this test is to make sure that an HttpStreamParser can be read |
| 12871 | // from after the HttpNetworkTransaction and the objects it owns have been |
| 12872 | // deleted. |
| 12873 | // See http://crbug.com/368418 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12874 | TEST_F(HttpNetworkTransactionTest, CancelAfterHeaders) { |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12875 | MockRead data_reads[] = { |
| 12876 | MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"), |
| 12877 | MockRead(ASYNC, "Content-Length: 2\r\n"), |
| 12878 | MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"), |
| 12879 | MockRead(ASYNC, "1"), |
| 12880 | // 2 async reads are necessary to trigger a ReadResponseBody call after the |
| 12881 | // HttpNetworkTransaction has been deleted. |
| 12882 | MockRead(ASYNC, "2"), |
| 12883 | MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this. |
| 12884 | }; |
| 12885 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 12886 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12887 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12888 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12889 | |
| 12890 | { |
| 12891 | HttpRequestInfo request; |
| 12892 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12893 | request.url = GURL("http://www.example.org/"); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12894 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12895 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12896 | TestCompletionCallback callback; |
| 12897 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12898 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12899 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12900 | callback.WaitForResult(); |
| 12901 | |
| 12902 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12903 | ASSERT_TRUE(response); |
| 12904 | EXPECT_TRUE(response->headers); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12905 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12906 | |
| 12907 | // The transaction and HttpRequestInfo are deleted. |
| 12908 | } |
| 12909 | |
| 12910 | // Let the HttpResponseBodyDrainer drain the socket. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 12911 | base::RunLoop().RunUntilIdle(); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12912 | |
| 12913 | // Socket should now be idle, waiting to be reused. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 12914 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 12915 | } |
| 12916 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12917 | // Test a basic GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12918 | TEST_F(HttpNetworkTransactionTest, ProxyGet) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12919 | session_deps_.proxy_service = |
| 12920 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12921 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12922 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12923 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12924 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12925 | HttpRequestInfo request; |
| 12926 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12927 | request.url = GURL("http://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12928 | |
| 12929 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12930 | MockWrite( |
| 12931 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 12932 | "Host: www.example.org\r\n" |
| 12933 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12934 | }; |
| 12935 | |
| 12936 | MockRead data_reads1[] = { |
| 12937 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12938 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 12939 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12940 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12941 | }; |
| 12942 | |
| 12943 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 12944 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12945 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12946 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12947 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12948 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12949 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 12950 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12951 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 12952 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 12953 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12954 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12955 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12956 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12957 | |
| 12958 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12959 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12960 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12961 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12962 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12963 | |
| 12964 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 12965 | EXPECT_EQ(200, response->headers->response_code()); |
| 12966 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 12967 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 12968 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 12969 | HostPortPair::FromString("myproxy:70")), |
| 12970 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 12971 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 12972 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 12973 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12974 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12975 | |
| 12976 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12977 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12978 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12979 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12980 | } |
| 12981 | |
| 12982 | // Test a basic HTTPS GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12983 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGet) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12984 | session_deps_.proxy_service = |
| 12985 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12986 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12987 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12988 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12989 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12990 | HttpRequestInfo request; |
| 12991 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12992 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12993 | |
| 12994 | // Since we have proxy, should try to establish tunnel. |
| 12995 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12996 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 12997 | "Host: www.example.org:443\r\n" |
| 12998 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 12999 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13000 | MockWrite("GET / HTTP/1.1\r\n" |
| 13001 | "Host: www.example.org\r\n" |
| 13002 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13003 | }; |
| 13004 | |
| 13005 | MockRead data_reads1[] = { |
| 13006 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 13007 | |
| 13008 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13009 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 13010 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13011 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13012 | }; |
| 13013 | |
| 13014 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 13015 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13016 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13017 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13018 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13019 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13020 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13021 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13022 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13023 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13024 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13025 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 13026 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13027 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13028 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13029 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13030 | |
| 13031 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13032 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 13033 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 13034 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13035 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13036 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 13037 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13038 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 13039 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13040 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 13041 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13042 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13043 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13044 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13045 | |
| 13046 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 13047 | EXPECT_EQ(200, response->headers->response_code()); |
| 13048 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 13049 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 13050 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 13051 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 13052 | HostPortPair::FromString("myproxy:70")), |
| 13053 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13054 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 13055 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 13056 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13057 | |
| 13058 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13059 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13060 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 13061 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13062 | } |
| 13063 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13064 | // Test a basic HTTPS GET request through a proxy, connecting to an IPv6 |
| 13065 | // literal host. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13066 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetIPv6) { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13067 | session_deps_.proxy_service = |
| 13068 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 13069 | BoundTestNetLog log; |
| 13070 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13071 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13072 | |
| 13073 | HttpRequestInfo request; |
| 13074 | request.method = "GET"; |
| 13075 | request.url = GURL("https://[::1]:443/"); |
| 13076 | |
| 13077 | // Since we have proxy, should try to establish tunnel. |
| 13078 | MockWrite data_writes1[] = { |
| 13079 | MockWrite("CONNECT [::1]:443 HTTP/1.1\r\n" |
| 13080 | "Host: [::1]:443\r\n" |
| 13081 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 13082 | |
| 13083 | MockWrite("GET / HTTP/1.1\r\n" |
| 13084 | "Host: [::1]\r\n" |
| 13085 | "Connection: keep-alive\r\n\r\n"), |
| 13086 | }; |
| 13087 | |
| 13088 | MockRead data_reads1[] = { |
| 13089 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 13090 | |
| 13091 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13092 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 13093 | MockRead("Content-Length: 100\r\n\r\n"), |
| 13094 | MockRead(SYNCHRONOUS, OK), |
| 13095 | }; |
| 13096 | |
| 13097 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 13098 | data_writes1, arraysize(data_writes1)); |
| 13099 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 13100 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 13101 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13102 | |
| 13103 | TestCompletionCallback callback1; |
| 13104 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13105 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13106 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13107 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13108 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13109 | |
| 13110 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13111 | EXPECT_THAT(rv, IsOk()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13112 | TestNetLogEntry::List entries; |
| 13113 | log.GetEntries(&entries); |
| 13114 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13115 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 13116 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13117 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13118 | entries, pos, |
| 13119 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 13120 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13121 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13122 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13123 | ASSERT_TRUE(response); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13124 | |
| 13125 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 13126 | EXPECT_EQ(200, response->headers->response_code()); |
| 13127 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 13128 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 13129 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 13130 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 13131 | HostPortPair::FromString("myproxy:70")), |
| 13132 | response->proxy_server); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13133 | |
| 13134 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13135 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13136 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 13137 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 13138 | } |
| 13139 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13140 | // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 13141 | // while establishing the tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13142 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 13143 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13144 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13145 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13146 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13147 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13148 | HttpRequestInfo request; |
| 13149 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13150 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13151 | |
| 13152 | // Since we have proxy, should try to establish tunnel. |
| 13153 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13154 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 13155 | "Host: www.example.org:443\r\n" |
| 13156 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13157 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13158 | MockWrite("GET / HTTP/1.1\r\n" |
| 13159 | "Host: www.example.org\r\n" |
| 13160 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13161 | }; |
| 13162 | |
| 13163 | MockRead data_reads1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13164 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13165 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13166 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13167 | }; |
| 13168 | |
| 13169 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 13170 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13171 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13172 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13173 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13174 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13175 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13176 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13177 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13178 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13179 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13180 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13181 | |
| 13182 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13183 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 13184 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 13185 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13186 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13187 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 13188 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13189 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 13190 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13191 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 13192 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13193 | } |
| 13194 | |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13195 | // Test for crbug.com/55424. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13196 | TEST_F(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13197 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13198 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13199 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13200 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13201 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13202 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13203 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13204 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13205 | }; |
| 13206 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13207 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 13208 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13209 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13210 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13211 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13212 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13213 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13214 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13215 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13216 | |
| 13217 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13218 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 13219 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 13220 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13221 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 13222 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13223 | |
| 13224 | HttpRequestInfo request; |
| 13225 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13226 | request.url = GURL("https://www.example.org/"); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13227 | |
| 13228 | // This is the important line that marks this as a preconnect. |
| 13229 | request.motivation = HttpRequestInfo::PRECONNECT_MOTIVATED; |
| 13230 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13231 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13232 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13233 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13234 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13235 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13236 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13237 | } |
| 13238 | |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13239 | // Given a net error, cause that error to be returned from the first Write() |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13240 | // call and verify that the HttpNetworkTransaction fails with that error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13241 | void HttpNetworkTransactionTest::CheckErrorIsPassedBack( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13242 | int error, IoMode mode) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13243 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13244 | request_info.url = GURL("https://www.example.com/"); |
| 13245 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13246 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13247 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13248 | SSLSocketDataProvider ssl_data(mode, OK); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13249 | MockWrite data_writes[] = { |
| 13250 | MockWrite(mode, error), |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13251 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13252 | StaticSocketDataProvider data(NULL, 0, data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13253 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13254 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13255 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13256 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13257 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13258 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13259 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13260 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13261 | if (rv == ERR_IO_PENDING) |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13262 | rv = callback.WaitForResult(); |
| 13263 | ASSERT_EQ(error, rv); |
| 13264 | } |
| 13265 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13266 | TEST_F(HttpNetworkTransactionTest, SSLWriteCertError) { |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13267 | // Just check a grab bag of cert errors. |
| 13268 | static const int kErrors[] = { |
| 13269 | ERR_CERT_COMMON_NAME_INVALID, |
| 13270 | ERR_CERT_AUTHORITY_INVALID, |
| 13271 | ERR_CERT_DATE_INVALID, |
| 13272 | }; |
| 13273 | for (size_t i = 0; i < arraysize(kErrors); i++) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13274 | CheckErrorIsPassedBack(kErrors[i], ASYNC); |
| 13275 | CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13276 | } |
| 13277 | } |
| 13278 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13279 | // Ensure that a client certificate is removed from the SSL client auth |
| 13280 | // cache when: |
| 13281 | // 1) No proxy is involved. |
| 13282 | // 2) TLS False Start is disabled. |
| 13283 | // 3) The initial TLS handshake requests a client certificate. |
| 13284 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13285 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_NoFalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13286 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13287 | request_info.url = GURL("https://www.example.com/"); |
| 13288 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13289 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13290 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13291 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13292 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13293 | |
| 13294 | // [ssl_]data1 contains the data for the first SSL handshake. When a |
| 13295 | // CertificateRequest is received for the first time, the handshake will |
| 13296 | // be aborted to allow the caller to provide a certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13297 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13298 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13299 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13300 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13301 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13302 | |
| 13303 | // [ssl_]data2 contains the data for the second SSL handshake. When TLS |
| 13304 | // False Start is not being used, the result of the SSL handshake will be |
| 13305 | // returned as part of the SSLClientSocket::Connect() call. This test |
| 13306 | // matches the result of a server sending a handshake_failure alert, |
| 13307 | // rather than a Finished message, because it requires a client |
| 13308 | // certificate and none was supplied. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13309 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13310 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13311 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13312 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13313 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13314 | |
| 13315 | // [ssl_]data3 contains the data for the third SSL handshake. When a |
| 13316 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 13317 | // HttpNetworkTransaction will attempt to fallback to TLSv1.1 if the previous |
| 13318 | // connection was attempted with TLSv1.2. This is transparent to the caller |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13319 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 13320 | // requiring a client certificate, this fallback handshake should also |
| 13321 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13322 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13323 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13324 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13325 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13326 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13327 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13328 | // [ssl_]data4 contains the data for the fourth SSL handshake. When a |
| 13329 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 13330 | // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous |
| 13331 | // connection was attempted with TLSv1.1. This is transparent to the caller |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13332 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 13333 | // requiring a client certificate, this fallback handshake should also |
| 13334 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13335 | SSLSocketDataProvider ssl_data4(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13336 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13337 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13338 | StaticSocketDataProvider data4(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13339 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13340 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13341 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13342 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13343 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13344 | // Begin the SSL handshake with the peer. This consumes ssl_data1. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13345 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13346 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13347 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13348 | |
| 13349 | // Complete the SSL handshake, which should abort due to requiring a |
| 13350 | // client certificate. |
| 13351 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13352 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13353 | |
| 13354 | // Indicate that no certificate should be supplied. From the perspective |
| 13355 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 13356 | // certificate, so this is the same as supply a |
| 13357 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13358 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13359 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13360 | |
| 13361 | // Ensure the certificate was added to the client auth cache before |
| 13362 | // allowing the connection to continue restarting. |
| 13363 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13364 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13365 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13366 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13367 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13368 | |
| 13369 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13370 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 13371 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13372 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13373 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13374 | |
| 13375 | // Ensure that the client certificate is removed from the cache on a |
| 13376 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13377 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13378 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13379 | } |
| 13380 | |
| 13381 | // Ensure that a client certificate is removed from the SSL client auth |
| 13382 | // cache when: |
| 13383 | // 1) No proxy is involved. |
| 13384 | // 2) TLS False Start is enabled. |
| 13385 | // 3) The initial TLS handshake requests a client certificate. |
| 13386 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13387 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_FalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13388 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13389 | request_info.url = GURL("https://www.example.com/"); |
| 13390 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13391 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13392 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13393 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13394 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13395 | |
| 13396 | // When TLS False Start is used, SSLClientSocket::Connect() calls will |
| 13397 | // return successfully after reading up to the peer's Certificate message. |
| 13398 | // This is to allow the caller to call SSLClientSocket::Write(), which can |
| 13399 | // enqueue application data to be sent in the same packet as the |
| 13400 | // ChangeCipherSpec and Finished messages. |
| 13401 | // The actual handshake will be finished when SSLClientSocket::Read() is |
| 13402 | // called, which expects to process the peer's ChangeCipherSpec and |
| 13403 | // Finished messages. If there was an error negotiating with the peer, |
| 13404 | // such as due to the peer requiring a client certificate when none was |
| 13405 | // supplied, the alert sent by the peer won't be processed until Read() is |
| 13406 | // called. |
| 13407 | |
| 13408 | // Like the non-False Start case, when a client certificate is requested by |
| 13409 | // the peer, the handshake is aborted during the Connect() call. |
| 13410 | // [ssl_]data1 represents the initial SSL handshake with the peer. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13411 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13412 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13413 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13414 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13415 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13416 | |
| 13417 | // When a client certificate is supplied, Connect() will not be aborted |
| 13418 | // when the peer requests the certificate. Instead, the handshake will |
| 13419 | // artificially succeed, allowing the caller to write the HTTP request to |
| 13420 | // the socket. The handshake messages are not processed until Read() is |
| 13421 | // called, which then detects that the handshake was aborted, due to the |
| 13422 | // peer sending a handshake_failure because it requires a client |
| 13423 | // certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13424 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13425 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13426 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13427 | MockRead data2_reads[] = { |
| 13428 | MockRead(ASYNC /* async */, ERR_SSL_PROTOCOL_ERROR), |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13429 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13430 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13431 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13432 | |
| 13433 | // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13434 | // the data for the SSL handshake once the TLSv1.1 connection falls back to |
| 13435 | // TLSv1. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13436 | SSLSocketDataProvider ssl_data3(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13437 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13438 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13439 | StaticSocketDataProvider data3(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13440 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13441 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13442 | // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection |
| 13443 | // falls back to SSLv3. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13444 | SSLSocketDataProvider ssl_data4(ASYNC, OK); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13445 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13446 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13447 | StaticSocketDataProvider data4(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13448 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13449 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 13450 | // Need one more if TLSv1.2 is enabled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13451 | SSLSocketDataProvider ssl_data5(ASYNC, OK); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 13452 | ssl_data5.cert_request_info = cert_request.get(); |
| 13453 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13454 | StaticSocketDataProvider data5(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 13455 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 13456 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13457 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13458 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13459 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13460 | // Begin the initial SSL handshake. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13461 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13462 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13463 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13464 | |
| 13465 | // Complete the SSL handshake, which should abort due to requiring a |
| 13466 | // client certificate. |
| 13467 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13468 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13469 | |
| 13470 | // Indicate that no certificate should be supplied. From the perspective |
| 13471 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 13472 | // certificate, so this is the same as supply a |
| 13473 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13474 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13475 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13476 | |
| 13477 | // Ensure the certificate was added to the client auth cache before |
| 13478 | // allowing the connection to continue restarting. |
| 13479 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13480 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13481 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13482 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13483 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13484 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13485 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13486 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 13487 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13488 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13489 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13490 | |
| 13491 | // Ensure that the client certificate is removed from the cache on a |
| 13492 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13493 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13494 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13495 | } |
| 13496 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13497 | // Ensure that a client certificate is removed from the SSL client auth |
| 13498 | // cache when: |
| 13499 | // 1) An HTTPS proxy is involved. |
| 13500 | // 3) The HTTPS proxy requests a client certificate. |
| 13501 | // 4) The client supplies an invalid/unacceptable certificate for the |
| 13502 | // proxy. |
| 13503 | // The test is repeated twice, first for connecting to an HTTPS endpoint, |
| 13504 | // then for connecting to an HTTP endpoint. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13505 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 13506 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13507 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13508 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13509 | |
| 13510 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13511 | cert_request->host_and_port = HostPortPair("proxy", 70); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13512 | |
| 13513 | // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of |
| 13514 | // [ssl_]data[1-3]. Rather than represending the endpoint |
| 13515 | // (www.example.com:443), they represent failures with the HTTPS proxy |
| 13516 | // (proxy:70). |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13517 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13518 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13519 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13520 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13521 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13522 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13523 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13524 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13525 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13526 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13527 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13528 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13529 | // TODO(wtc): find out why this unit test doesn't need [ssl_]data3. |
| 13530 | #if 0 |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13531 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13532 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13533 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13534 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13535 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13536 | #endif |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13537 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13538 | HttpRequestInfo requests[2]; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13539 | requests[0].url = GURL("https://www.example.com/"); |
| 13540 | requests[0].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13541 | requests[0].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13542 | |
| 13543 | requests[1].url = GURL("http://www.example.com/"); |
| 13544 | requests[1].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13545 | requests[1].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13546 | |
| 13547 | for (size_t i = 0; i < arraysize(requests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13548 | session_deps_.socket_factory->ResetNextMockIndexes(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13549 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13550 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13551 | |
| 13552 | // Begin the SSL handshake with the proxy. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13553 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13554 | int rv = trans.Start(&requests[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13555 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13556 | |
| 13557 | // Complete the SSL handshake, which should abort due to requiring a |
| 13558 | // client certificate. |
| 13559 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13560 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13561 | |
| 13562 | // Indicate that no certificate should be supplied. From the perspective |
| 13563 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 13564 | // certificate, so this is the same as supply a |
| 13565 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13566 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13567 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13568 | |
| 13569 | // Ensure the certificate was added to the client auth cache before |
| 13570 | // allowing the connection to continue restarting. |
| 13571 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13572 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13573 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13574 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13575 | ASSERT_FALSE(client_cert); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13576 | // Ensure the certificate was NOT cached for the endpoint. This only |
| 13577 | // applies to HTTPS requests, but is fine to check for HTTP requests. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13578 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13579 | HostPortPair("www.example.com", 443), &client_cert, |
| 13580 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13581 | |
| 13582 | // Restart the handshake. This will consume ssl_data2, which fails, and |
| 13583 | // then consume ssl_data3, which should also fail. The result code is |
| 13584 | // checked against what ssl_data3 should return. |
| 13585 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13586 | ASSERT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13587 | |
| 13588 | // Now that the new handshake has failed, ensure that the client |
| 13589 | // certificate was removed from the client auth cache. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13590 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13591 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13592 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13593 | HostPortPair("www.example.com", 443), &client_cert, |
| 13594 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13595 | } |
| 13596 | } |
| 13597 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13598 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPooling) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13599 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13600 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13601 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13602 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13603 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13604 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13605 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13606 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13607 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13608 | SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13609 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13610 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13611 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13612 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13613 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13614 | SpdySerializedFrame host1_resp_body( |
| 13615 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13616 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13617 | SpdySerializedFrame host2_resp_body( |
| 13618 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13619 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13620 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 13621 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13622 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13623 | }; |
| 13624 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 13625 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13626 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13627 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 13628 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13629 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13630 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 13631 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13632 | HttpRequestInfo request1; |
| 13633 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13634 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13635 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13636 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13637 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13638 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13639 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13640 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13641 | |
| 13642 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13643 | ASSERT_TRUE(response); |
| 13644 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13645 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13646 | |
| 13647 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13648 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13649 | EXPECT_EQ("hello!", response_data); |
| 13650 | |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13651 | // Preload mail.example.com into HostCache. |
| 13652 | HostPortPair host_port("mail.example.com", 443); |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 13653 | HostResolver::RequestInfo resolve_info(host_port); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13654 | AddressList ignored; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 13655 | std::unique_ptr<HostResolver::Request> request; |
| 13656 | rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 13657 | &ignored, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13658 | &request, NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13659 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 13660 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13661 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13662 | |
| 13663 | HttpRequestInfo request2; |
| 13664 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13665 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13666 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13667 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13668 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13669 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13670 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13671 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13672 | |
| 13673 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13674 | ASSERT_TRUE(response); |
| 13675 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13676 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13677 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13678 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13679 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13680 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13681 | } |
| 13682 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13683 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) { |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13684 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13685 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13686 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13687 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13688 | AddSSLSocketData(); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13689 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13690 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13691 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13692 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13693 | SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13694 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13695 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13696 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13697 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13698 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13699 | SpdySerializedFrame host1_resp_body( |
| 13700 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13701 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13702 | SpdySerializedFrame host2_resp_body( |
| 13703 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13704 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13705 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 13706 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13707 | MockRead(ASYNC, 0, 6), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13708 | }; |
| 13709 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 13710 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13711 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13712 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 13713 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13714 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13715 | |
| 13716 | TestCompletionCallback callback; |
| 13717 | HttpRequestInfo request1; |
| 13718 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13719 | request1.url = GURL("https://www.example.org/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13720 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13721 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13722 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13723 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13724 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13725 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13726 | |
| 13727 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13728 | ASSERT_TRUE(response); |
| 13729 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13730 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13731 | |
| 13732 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13733 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13734 | EXPECT_EQ("hello!", response_data); |
| 13735 | |
| 13736 | HttpRequestInfo request2; |
| 13737 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13738 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13739 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13740 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13741 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13742 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13743 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13744 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13745 | |
| 13746 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13747 | ASSERT_TRUE(response); |
| 13748 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13749 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13750 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13751 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13752 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13753 | EXPECT_EQ("hello!", response_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13754 | } |
| 13755 | |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 13756 | // Regression test for https://crbug.com/546991. |
| 13757 | // The server might not be able to serve an IP pooled request, and might send a |
| 13758 | // 421 Misdirected Request response status to indicate this. |
| 13759 | // HttpNetworkTransaction should reset the request and retry without IP pooling. |
| 13760 | TEST_F(HttpNetworkTransactionTest, RetryWithoutConnectionPooling) { |
| 13761 | // Two hosts resolve to the same IP address. |
| 13762 | const std::string ip_addr = "1.2.3.4"; |
| 13763 | IPAddress ip; |
| 13764 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 13765 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 13766 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13767 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 13768 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 13769 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 13770 | |
| 13771 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13772 | |
| 13773 | // Two requests on the first connection. |
| 13774 | SpdySerializedFrame req1( |
| 13775 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 13776 | spdy_util_.UpdateWithStreamDestruction(1); |
| 13777 | SpdySerializedFrame req2( |
| 13778 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
| 13779 | SpdySerializedFrame rst( |
| 13780 | spdy_util_.ConstructSpdyRstStream(3, ERROR_CODE_CANCEL)); |
| 13781 | MockWrite writes1[] = { |
| 13782 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 13783 | CreateMockWrite(rst, 6), |
| 13784 | }; |
| 13785 | |
| 13786 | // The first one succeeds, the second gets error 421 Misdirected Request. |
| 13787 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 13788 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 13789 | SpdyHeaderBlock response_headers; |
| 13790 | response_headers[SpdyTestUtil::GetStatusKey()] = "421"; |
| 13791 | SpdySerializedFrame resp2( |
| 13792 | spdy_util_.ConstructSpdyReply(3, std::move(response_headers))); |
| 13793 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 13794 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 13795 | |
| 13796 | MockConnect connect1(ASYNC, OK, peer_addr); |
| 13797 | SequencedSocketData data1(connect1, reads1, arraysize(reads1), writes1, |
| 13798 | arraysize(writes1)); |
| 13799 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 13800 | |
| 13801 | AddSSLSocketData(); |
| 13802 | |
| 13803 | // Retry the second request on a second connection. |
| 13804 | SpdyTestUtil spdy_util2; |
| 13805 | SpdySerializedFrame req3( |
| 13806 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 13807 | MockWrite writes2[] = { |
| 13808 | CreateMockWrite(req3, 0), |
| 13809 | }; |
| 13810 | |
| 13811 | SpdySerializedFrame resp3(spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 13812 | SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 13813 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 13814 | MockRead(ASYNC, 0, 3)}; |
| 13815 | |
| 13816 | MockConnect connect2(ASYNC, OK, peer_addr); |
| 13817 | SequencedSocketData data2(connect2, reads2, arraysize(reads2), writes2, |
| 13818 | arraysize(writes2)); |
| 13819 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 13820 | |
| 13821 | AddSSLSocketData(); |
| 13822 | |
| 13823 | // Preload mail.example.org into HostCache. |
| 13824 | HostPortPair host_port("mail.example.org", 443); |
| 13825 | HostResolver::RequestInfo resolve_info(host_port); |
| 13826 | AddressList ignored; |
| 13827 | std::unique_ptr<HostResolver::Request> request; |
| 13828 | TestCompletionCallback callback; |
| 13829 | int rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 13830 | &ignored, callback.callback(), |
| 13831 | &request, NetLogWithSource()); |
| 13832 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13833 | rv = callback.WaitForResult(); |
| 13834 | EXPECT_THAT(rv, IsOk()); |
| 13835 | |
| 13836 | HttpRequestInfo request1; |
| 13837 | request1.method = "GET"; |
| 13838 | request1.url = GURL("https://www.example.org/"); |
| 13839 | request1.load_flags = 0; |
| 13840 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 13841 | |
| 13842 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 13843 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13844 | rv = callback.WaitForResult(); |
| 13845 | EXPECT_THAT(rv, IsOk()); |
| 13846 | |
| 13847 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 13848 | ASSERT_TRUE(response); |
| 13849 | ASSERT_TRUE(response->headers); |
| 13850 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 13851 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 13852 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 13853 | std::string response_data; |
| 13854 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 13855 | EXPECT_EQ("hello!", response_data); |
| 13856 | |
| 13857 | HttpRequestInfo request2; |
| 13858 | request2.method = "GET"; |
| 13859 | request2.url = GURL("https://mail.example.org/"); |
| 13860 | request2.load_flags = 0; |
| 13861 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 13862 | |
| 13863 | BoundTestNetLog log; |
| 13864 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 13865 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13866 | rv = callback.WaitForResult(); |
| 13867 | EXPECT_THAT(rv, IsOk()); |
| 13868 | |
| 13869 | response = trans2.GetResponseInfo(); |
| 13870 | ASSERT_TRUE(response); |
| 13871 | ASSERT_TRUE(response->headers); |
| 13872 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 13873 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 13874 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 13875 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 13876 | EXPECT_EQ("hello!", response_data); |
| 13877 | |
| 13878 | TestNetLogEntry::List entries; |
| 13879 | log.GetEntries(&entries); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 13880 | ExpectLogContainsSomewhere( |
| 13881 | entries, 0, NetLogEventType::HTTP_TRANSACTION_RESTART_MISDIRECTED_REQUEST, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 13882 | NetLogEventPhase::NONE); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 13883 | } |
| 13884 | |
| 13885 | // Test that HTTP 421 responses are properly returned to the caller if received |
| 13886 | // on the retry as well. HttpNetworkTransaction should not infinite loop or lose |
| 13887 | // portions of the response. |
| 13888 | TEST_F(HttpNetworkTransactionTest, ReturnHTTP421OnRetry) { |
| 13889 | // Two hosts resolve to the same IP address. |
| 13890 | const std::string ip_addr = "1.2.3.4"; |
| 13891 | IPAddress ip; |
| 13892 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 13893 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 13894 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13895 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 13896 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 13897 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 13898 | |
| 13899 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13900 | |
| 13901 | // Two requests on the first connection. |
| 13902 | SpdySerializedFrame req1( |
| 13903 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 13904 | spdy_util_.UpdateWithStreamDestruction(1); |
| 13905 | SpdySerializedFrame req2( |
| 13906 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
| 13907 | SpdySerializedFrame rst( |
| 13908 | spdy_util_.ConstructSpdyRstStream(3, ERROR_CODE_CANCEL)); |
| 13909 | MockWrite writes1[] = { |
| 13910 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 13911 | CreateMockWrite(rst, 6), |
| 13912 | }; |
| 13913 | |
| 13914 | // The first one succeeds, the second gets error 421 Misdirected Request. |
| 13915 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 13916 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 13917 | SpdyHeaderBlock response_headers; |
| 13918 | response_headers[SpdyTestUtil::GetStatusKey()] = "421"; |
| 13919 | SpdySerializedFrame resp2( |
| 13920 | spdy_util_.ConstructSpdyReply(3, response_headers.Clone())); |
| 13921 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 13922 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 13923 | |
| 13924 | MockConnect connect1(ASYNC, OK, peer_addr); |
| 13925 | SequencedSocketData data1(connect1, reads1, arraysize(reads1), writes1, |
| 13926 | arraysize(writes1)); |
| 13927 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 13928 | |
| 13929 | AddSSLSocketData(); |
| 13930 | |
| 13931 | // Retry the second request on a second connection. It returns 421 Misdirected |
| 13932 | // Retry again. |
| 13933 | SpdyTestUtil spdy_util2; |
| 13934 | SpdySerializedFrame req3( |
| 13935 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 13936 | MockWrite writes2[] = { |
| 13937 | CreateMockWrite(req3, 0), |
| 13938 | }; |
| 13939 | |
| 13940 | SpdySerializedFrame resp3( |
| 13941 | spdy_util2.ConstructSpdyReply(1, std::move(response_headers))); |
| 13942 | SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 13943 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 13944 | MockRead(ASYNC, 0, 3)}; |
| 13945 | |
| 13946 | MockConnect connect2(ASYNC, OK, peer_addr); |
| 13947 | SequencedSocketData data2(connect2, reads2, arraysize(reads2), writes2, |
| 13948 | arraysize(writes2)); |
| 13949 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 13950 | |
| 13951 | AddSSLSocketData(); |
| 13952 | |
| 13953 | // Preload mail.example.org into HostCache. |
| 13954 | HostPortPair host_port("mail.example.org", 443); |
| 13955 | HostResolver::RequestInfo resolve_info(host_port); |
| 13956 | AddressList ignored; |
| 13957 | std::unique_ptr<HostResolver::Request> request; |
| 13958 | TestCompletionCallback callback; |
| 13959 | int rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 13960 | &ignored, callback.callback(), |
| 13961 | &request, NetLogWithSource()); |
| 13962 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13963 | rv = callback.WaitForResult(); |
| 13964 | EXPECT_THAT(rv, IsOk()); |
| 13965 | |
| 13966 | HttpRequestInfo request1; |
| 13967 | request1.method = "GET"; |
| 13968 | request1.url = GURL("https://www.example.org/"); |
| 13969 | request1.load_flags = 0; |
| 13970 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 13971 | |
| 13972 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 13973 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13974 | rv = callback.WaitForResult(); |
| 13975 | EXPECT_THAT(rv, IsOk()); |
| 13976 | |
| 13977 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 13978 | ASSERT_TRUE(response); |
| 13979 | ASSERT_TRUE(response->headers); |
| 13980 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 13981 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 13982 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 13983 | std::string response_data; |
| 13984 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 13985 | EXPECT_EQ("hello!", response_data); |
| 13986 | |
| 13987 | HttpRequestInfo request2; |
| 13988 | request2.method = "GET"; |
| 13989 | request2.url = GURL("https://mail.example.org/"); |
| 13990 | request2.load_flags = 0; |
| 13991 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 13992 | |
| 13993 | BoundTestNetLog log; |
| 13994 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 13995 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13996 | rv = callback.WaitForResult(); |
| 13997 | EXPECT_THAT(rv, IsOk()); |
| 13998 | |
| 13999 | // After a retry, the 421 Misdirected Request is reported back up to the |
| 14000 | // caller. |
| 14001 | response = trans2.GetResponseInfo(); |
| 14002 | ASSERT_TRUE(response); |
| 14003 | ASSERT_TRUE(response->headers); |
| 14004 | EXPECT_EQ("HTTP/1.1 421", response->headers->GetStatusLine()); |
| 14005 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 14006 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 14007 | EXPECT_TRUE(response->ssl_info.cert); |
| 14008 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 14009 | EXPECT_EQ("hello!", response_data); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14010 | } |
| 14011 | |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 14012 | class OneTimeCachingHostResolver : public MockHostResolverBase { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14013 | public: |
| 14014 | explicit OneTimeCachingHostResolver(const HostPortPair& host_port) |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 14015 | : MockHostResolverBase(/* use_caching = */ true), host_port_(host_port) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14016 | ~OneTimeCachingHostResolver() override {} |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14017 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14018 | int ResolveFromCache(const RequestInfo& info, |
| 14019 | AddressList* addresses, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14020 | const NetLogWithSource& net_log) override { |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 14021 | int rv = MockHostResolverBase::ResolveFromCache(info, addresses, net_log); |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 14022 | if (rv == OK && info.host_port_pair().Equals(host_port_)) |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 14023 | GetHostCache()->clear(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14024 | return rv; |
| 14025 | } |
| 14026 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14027 | private: |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14028 | const HostPortPair host_port_; |
| 14029 | }; |
| 14030 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14031 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 14032 | UseIPConnectionPoolingWithHostCacheExpiration) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14033 | // Set up a special HttpNetworkSession with a OneTimeCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14034 | session_deps_.host_resolver = std::make_unique<OneTimeCachingHostResolver>( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14035 | HostPortPair("mail.example.com", 443)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14036 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14037 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 14038 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14039 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14040 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14041 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14042 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14043 | SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14044 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14045 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14046 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14047 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14048 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14049 | SpdySerializedFrame host1_resp_body( |
| 14050 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14051 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14052 | SpdySerializedFrame host2_resp_body( |
| 14053 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14054 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14055 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 14056 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14057 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14058 | }; |
| 14059 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 14060 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14061 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14062 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 14063 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14064 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14065 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 14066 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14067 | HttpRequestInfo request1; |
| 14068 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14069 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14070 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14071 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14072 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14073 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14074 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14075 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14076 | |
| 14077 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14078 | ASSERT_TRUE(response); |
| 14079 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14080 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14081 | |
| 14082 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14083 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14084 | EXPECT_EQ("hello!", response_data); |
| 14085 | |
| 14086 | // Preload cache entries into HostCache. |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14087 | HostResolver::RequestInfo resolve_info(HostPortPair("mail.example.com", 443)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14088 | AddressList ignored; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 14089 | std::unique_ptr<HostResolver::Request> request; |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 14090 | rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 14091 | &ignored, callback.callback(), |
| 14092 | &request, NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14093 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 14094 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14095 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14096 | |
| 14097 | HttpRequestInfo request2; |
| 14098 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14099 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14100 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14101 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14102 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14103 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14104 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14105 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14106 | |
| 14107 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14108 | ASSERT_TRUE(response); |
| 14109 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14110 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14111 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14112 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14113 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14114 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14115 | } |
| 14116 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14117 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14118 | const std::string https_url = "https://www.example.org:8080/"; |
| 14119 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14120 | |
| 14121 | // SPDY GET for HTTPS URL |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14122 | SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14123 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14124 | |
| 14125 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14126 | CreateMockWrite(req1, 0), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14127 | }; |
| 14128 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14129 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14130 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 14131 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 14132 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3)}; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14133 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14134 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 14135 | arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14136 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 14137 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14138 | |
| 14139 | // HTTP GET for the HTTP URL |
| 14140 | MockWrite writes2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14141 | MockWrite(ASYNC, 0, |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 14142 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14143 | "Host: www.example.org:8080\r\n" |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 14144 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14145 | }; |
| 14146 | |
| 14147 | MockRead reads2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14148 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 14149 | MockRead(ASYNC, 2, "hello"), |
| 14150 | MockRead(ASYNC, OK, 3), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14151 | }; |
| 14152 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14153 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 14154 | arraysize(writes2)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14155 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14156 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14157 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14158 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14159 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 14160 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14161 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14162 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14163 | |
| 14164 | // Start the first transaction to set up the SpdySession |
| 14165 | HttpRequestInfo request1; |
| 14166 | request1.method = "GET"; |
| 14167 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14168 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14169 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14170 | TestCompletionCallback callback1; |
| 14171 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14172 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 14173 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14174 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14175 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14176 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 14177 | |
| 14178 | // Now, start the HTTP request |
| 14179 | HttpRequestInfo request2; |
| 14180 | request2.method = "GET"; |
| 14181 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14182 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14183 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14184 | TestCompletionCallback callback2; |
| 14185 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14186 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 14187 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14188 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14189 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14190 | EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 14191 | } |
| 14192 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14193 | // Alternative service requires HTTP/2 (or SPDY), but HTTP/1.1 is negotiated |
| 14194 | // with the alternative server. That connection should not be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14195 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceNotOnHttp11) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14196 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 14197 | HostPortPair alternative("www.example.org", 444); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14198 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14199 | // Negotiate HTTP/1.1 with alternative. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14200 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14201 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14202 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14203 | |
| 14204 | // No data should be read from the alternative, because HTTP/1.1 is |
| 14205 | // negotiated. |
| 14206 | StaticSocketDataProvider data; |
| 14207 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14208 | |
| 14209 | // 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] | 14210 | // negotiated. In order to test this, a failed connection to the server is |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14211 | // mocked. This way the request relies on the alternate Job. |
| 14212 | StaticSocketDataProvider data_refused; |
| 14213 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 14214 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 14215 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14216 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14217 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 14218 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14219 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 14220 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 14221 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 14222 | http_server_properties->SetHttp2AlternativeService( |
| 14223 | server, alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14224 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14225 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 14226 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14227 | request.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14228 | request.url = GURL("https://www.example.org:443"); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14229 | TestCompletionCallback callback; |
| 14230 | |
| 14231 | // HTTP/2 (or SPDY) is required for alternative service, if HTTP/1.1 is |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14232 | // negotiated, the alternate Job should fail with ERR_ALPN_NEGOTIATION_FAILED. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14233 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14234 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_ALPN_NEGOTIATION_FAILED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14235 | } |
| 14236 | |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14237 | // 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] | 14238 | // server, and an alternate one to the alternative server. If the former |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14239 | // succeeds, the request should succeed, even if the latter fails because |
| 14240 | // HTTP/1.1 is negotiated which is insufficient for alternative service. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14241 | TEST_F(HttpNetworkTransactionTest, FailedAlternativeServiceIsNotUserVisible) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14242 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 14243 | HostPortPair alternative("www.example.org", 444); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14244 | |
| 14245 | // Negotiate HTTP/1.1 with alternative. |
| 14246 | SSLSocketDataProvider alternative_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14247 | alternative_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14248 | session_deps_.socket_factory->AddSSLSocketDataProvider(&alternative_ssl); |
| 14249 | |
| 14250 | // No data should be read from the alternative, because HTTP/1.1 is |
| 14251 | // negotiated. |
| 14252 | StaticSocketDataProvider data; |
| 14253 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14254 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14255 | // Negotiate HTTP/1.1 with server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14256 | SSLSocketDataProvider origin_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14257 | origin_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14258 | session_deps_.socket_factory->AddSSLSocketDataProvider(&origin_ssl); |
| 14259 | |
| 14260 | MockWrite http_writes[] = { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14261 | MockWrite("GET / HTTP/1.1\r\n" |
| 14262 | "Host: www.example.org\r\n" |
| 14263 | "Connection: keep-alive\r\n\r\n"), |
| 14264 | MockWrite("GET /second HTTP/1.1\r\n" |
| 14265 | "Host: www.example.org\r\n" |
| 14266 | "Connection: keep-alive\r\n\r\n"), |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14267 | }; |
| 14268 | |
| 14269 | MockRead http_reads[] = { |
| 14270 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14271 | MockRead("Content-Type: text/html\r\n"), |
| 14272 | MockRead("Content-Length: 6\r\n\r\n"), |
| 14273 | MockRead("foobar"), |
| 14274 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14275 | MockRead("Content-Type: text/html\r\n"), |
| 14276 | MockRead("Content-Length: 7\r\n\r\n"), |
| 14277 | MockRead("another"), |
| 14278 | }; |
| 14279 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 14280 | http_writes, arraysize(http_writes)); |
| 14281 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 14282 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14283 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14284 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 14285 | HttpServerProperties* http_server_properties = |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14286 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 14287 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 14288 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 14289 | http_server_properties->SetHttp2AlternativeService( |
| 14290 | server, alternative_service, expiration); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14291 | |
| 14292 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 14293 | HttpRequestInfo request1; |
| 14294 | request1.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14295 | request1.url = GURL("https://www.example.org:443"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14296 | request1.load_flags = 0; |
| 14297 | TestCompletionCallback callback1; |
| 14298 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14299 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14300 | rv = callback1.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14301 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14302 | |
| 14303 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14304 | ASSERT_TRUE(response1); |
| 14305 | ASSERT_TRUE(response1->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14306 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 14307 | |
| 14308 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14309 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14310 | EXPECT_EQ("foobar", response_data1); |
| 14311 | |
| 14312 | // Alternative should be marked as broken, because HTTP/1.1 is not sufficient |
| 14313 | // for alternative service. |
| 14314 | EXPECT_TRUE( |
| 14315 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
| 14316 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14317 | // Since |alternative_service| is broken, a second transaction to server |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14318 | // should not start an alternate Job. It should pool to existing connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14319 | // to server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14320 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 14321 | HttpRequestInfo request2; |
| 14322 | request2.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14323 | request2.url = GURL("https://www.example.org:443/second"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14324 | request2.load_flags = 0; |
| 14325 | TestCompletionCallback callback2; |
| 14326 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14327 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14328 | rv = callback2.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14329 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14330 | |
| 14331 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14332 | ASSERT_TRUE(response2); |
| 14333 | ASSERT_TRUE(response2->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14334 | EXPECT_EQ("HTTP/1.1 200 OK", response2->headers->GetStatusLine()); |
| 14335 | |
| 14336 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14337 | ASSERT_THAT(ReadTransaction(&trans2, &response_data2), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14338 | EXPECT_EQ("another", response_data2); |
| 14339 | } |
| 14340 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14341 | // Alternative service requires HTTP/2 (or SPDY), but there is already a |
| 14342 | // HTTP/1.1 socket open to the alternative server. That socket should not be |
| 14343 | // used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14344 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceShouldNotPoolToHttp11) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14345 | url::SchemeHostPort server("https", "origin.example.org", 443); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14346 | HostPortPair alternative("alternative.example.org", 443); |
| 14347 | std::string origin_url = "https://origin.example.org:443"; |
| 14348 | std::string alternative_url = "https://alternative.example.org:443"; |
| 14349 | |
| 14350 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 14351 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14352 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14353 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14354 | |
| 14355 | // HTTP/1.1 data for |request1| and |request2|. |
| 14356 | MockWrite http_writes[] = { |
| 14357 | MockWrite( |
| 14358 | "GET / HTTP/1.1\r\n" |
| 14359 | "Host: alternative.example.org\r\n" |
| 14360 | "Connection: keep-alive\r\n\r\n"), |
| 14361 | MockWrite( |
| 14362 | "GET / HTTP/1.1\r\n" |
| 14363 | "Host: alternative.example.org\r\n" |
| 14364 | "Connection: keep-alive\r\n\r\n"), |
| 14365 | }; |
| 14366 | |
| 14367 | MockRead http_reads[] = { |
| 14368 | MockRead( |
| 14369 | "HTTP/1.1 200 OK\r\n" |
| 14370 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 14371 | "Content-Length: 40\r\n\r\n" |
| 14372 | "first HTTP/1.1 response from alternative"), |
| 14373 | MockRead( |
| 14374 | "HTTP/1.1 200 OK\r\n" |
| 14375 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 14376 | "Content-Length: 41\r\n\r\n" |
| 14377 | "second HTTP/1.1 response from alternative"), |
| 14378 | }; |
| 14379 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 14380 | http_writes, arraysize(http_writes)); |
| 14381 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 14382 | |
| 14383 | // This test documents that an alternate Job should not pool to an already |
| 14384 | // existing HTTP/1.1 connection. In order to test this, a failed connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14385 | // to the server is mocked. This way |request2| relies on the alternate Job. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14386 | StaticSocketDataProvider data_refused; |
| 14387 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 14388 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 14389 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14390 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14391 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 14392 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14393 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 14394 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 14395 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 14396 | http_server_properties->SetHttp2AlternativeService( |
| 14397 | server, alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14398 | |
| 14399 | // First transaction to alternative to open an HTTP/1.1 socket. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14400 | HttpRequestInfo request1; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 14401 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14402 | request1.method = "GET"; |
| 14403 | request1.url = GURL(alternative_url); |
| 14404 | request1.load_flags = 0; |
| 14405 | TestCompletionCallback callback1; |
| 14406 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14407 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14408 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14409 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14410 | ASSERT_TRUE(response1); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14411 | ASSERT_TRUE(response1->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14412 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14413 | EXPECT_TRUE(response1->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14414 | EXPECT_FALSE(response1->was_fetched_via_spdy); |
| 14415 | std::string response_data1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14416 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14417 | EXPECT_EQ("first HTTP/1.1 response from alternative", response_data1); |
| 14418 | |
| 14419 | // Request for origin.example.org, which has an alternative service. This |
| 14420 | // will start two Jobs: the alternative looks for connections to pool to, |
| 14421 | // 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] | 14422 | // open other connections to alternative server. The Job to server fails, so |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14423 | // this request fails. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14424 | HttpRequestInfo request2; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 14425 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14426 | request2.method = "GET"; |
| 14427 | request2.url = GURL(origin_url); |
| 14428 | request2.load_flags = 0; |
| 14429 | TestCompletionCallback callback2; |
| 14430 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14431 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14432 | EXPECT_THAT(callback2.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14433 | |
| 14434 | // Another transaction to alternative. This is to test that the HTTP/1.1 |
| 14435 | // socket is still open and in the pool. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14436 | HttpRequestInfo request3; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 14437 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14438 | request3.method = "GET"; |
| 14439 | request3.url = GURL(alternative_url); |
| 14440 | request3.load_flags = 0; |
| 14441 | TestCompletionCallback callback3; |
| 14442 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14443 | rv = trans3.Start(&request3, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14444 | EXPECT_THAT(callback3.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14445 | const HttpResponseInfo* response3 = trans3.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14446 | ASSERT_TRUE(response3); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14447 | ASSERT_TRUE(response3->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14448 | EXPECT_EQ("HTTP/1.1 200 OK", response3->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14449 | EXPECT_TRUE(response3->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14450 | EXPECT_FALSE(response3->was_fetched_via_spdy); |
| 14451 | std::string response_data3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14452 | ASSERT_THAT(ReadTransaction(&trans3, &response_data3), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14453 | EXPECT_EQ("second HTTP/1.1 response from alternative", response_data3); |
| 14454 | } |
| 14455 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14456 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14457 | const std::string https_url = "https://www.example.org:8080/"; |
| 14458 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14459 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14460 | // Separate SPDY util instance for naked and wrapped requests. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14461 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14462 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14463 | // SPDY GET for HTTPS URL (through CONNECT tunnel) |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14464 | const HostPortPair host_port_pair("www.example.org", 8080); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14465 | SpdySerializedFrame connect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 14466 | spdy_util_.ConstructSpdyConnect(NULL, 0, 1, LOWEST, host_port_pair)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14467 | SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14468 | spdy_util_wrapped.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14469 | SpdySerializedFrame wrapped_req1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 14470 | spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 14471 | |
| 14472 | // SPDY GET for HTTP URL (through the proxy, but not the tunnel). |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 14473 | SpdyHeaderBlock req2_block; |
| 14474 | req2_block[spdy_util_.GetMethodKey()] = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14475 | req2_block[spdy_util_.GetHostKey()] = "www.example.org:8080"; |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 14476 | req2_block[spdy_util_.GetSchemeKey()] = "http"; |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 14477 | req2_block[spdy_util_.GetPathKey()] = "/"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14478 | SpdySerializedFrame req2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14479 | spdy_util_.ConstructSpdyHeaders(3, std::move(req2_block), MEDIUM, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14480 | |
| 14481 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14482 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_req1, 2), |
| 14483 | CreateMockWrite(req2, 6), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14484 | }; |
| 14485 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14486 | SpdySerializedFrame conn_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14487 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14488 | SpdySerializedFrame resp1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14489 | spdy_util_wrapped.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14490 | SpdySerializedFrame body1(spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 14491 | SpdySerializedFrame wrapped_resp1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14492 | spdy_util_wrapped.ConstructWrappedSpdyFrame(resp1, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14493 | SpdySerializedFrame wrapped_body1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14494 | spdy_util_wrapped.ConstructWrappedSpdyFrame(body1, 1)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14495 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14496 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14497 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14498 | CreateMockRead(conn_resp, 1), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14499 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14500 | CreateMockRead(wrapped_resp1, 4), |
| 14501 | CreateMockRead(wrapped_body1, 5), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14502 | MockRead(ASYNC, ERR_IO_PENDING, 7), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14503 | CreateMockRead(resp2, 8), |
| 14504 | CreateMockRead(body2, 9), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14505 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 10), |
| 14506 | }; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14507 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14508 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 14509 | arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14510 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 14511 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14512 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 14513 | session_deps_.proxy_service = |
| 14514 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14515 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14516 | session_deps_.net_log = &log; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14517 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14518 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14519 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14520 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14521 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14522 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 14523 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14524 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14525 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14526 | |
| 14527 | // Start the first transaction to set up the SpdySession |
| 14528 | HttpRequestInfo request1; |
| 14529 | request1.method = "GET"; |
| 14530 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14531 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14532 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14533 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14534 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14535 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14536 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 14537 | data1.RunUntilPaused(); |
| 14538 | base::RunLoop().RunUntilIdle(); |
| 14539 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14540 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14541 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 14542 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 14543 | LoadTimingInfo load_timing_info1; |
| 14544 | EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); |
| 14545 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 14546 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 14547 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14548 | // Now, start the HTTP request. |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14549 | HttpRequestInfo request2; |
| 14550 | request2.method = "GET"; |
| 14551 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14552 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14553 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14554 | TestCompletionCallback callback2; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14555 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14556 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14557 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 14558 | data1.RunUntilPaused(); |
| 14559 | base::RunLoop().RunUntilIdle(); |
| 14560 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14561 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14562 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14563 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 14564 | |
| 14565 | LoadTimingInfo load_timing_info2; |
| 14566 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
| 14567 | // The established SPDY sessions is considered reused by the HTTP request. |
| 14568 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 14569 | // HTTP requests over a SPDY session should have a different connection |
| 14570 | // socket_log_id than requests over a tunnel. |
| 14571 | 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] | 14572 | } |
| 14573 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14574 | // Test that in the case where we have a SPDY session to a SPDY proxy |
| 14575 | // that we do not pool other origins that resolve to the same IP when |
| 14576 | // the certificate does not match the new origin. |
| 14577 | // http://crbug.com/134690 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14578 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14579 | const std::string url1 = "http://www.example.org/"; |
| 14580 | const std::string url2 = "https://news.example.org/"; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14581 | const std::string ip_addr = "1.2.3.4"; |
| 14582 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14583 | // Second SpdyTestUtil instance for the second socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14584 | SpdyTestUtil spdy_util_secure; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14585 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14586 | // SPDY GET for HTTP URL (through SPDY proxy) |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 14587 | SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14588 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14589 | SpdySerializedFrame req1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14590 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14591 | |
| 14592 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14593 | CreateMockWrite(req1, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14594 | }; |
| 14595 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14596 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14597 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14598 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14599 | MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(resp1, 2), |
| 14600 | CreateMockRead(body1, 3), MockRead(ASYNC, OK, 4), // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14601 | }; |
| 14602 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14603 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 14604 | arraysize(writes1)); |
martijn | fe9636e | 2016-02-06 14:33:32 | [diff] [blame] | 14605 | IPAddress ip; |
martijn | 654c8c4 | 2016-02-10 22:10:59 | [diff] [blame] | 14606 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14607 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 14608 | MockConnect connect_data1(ASYNC, OK, peer_addr); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14609 | data1.set_connect_data(connect_data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14610 | |
| 14611 | // SPDY GET for HTTPS URL (direct) |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14612 | SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14613 | spdy_util_secure.ConstructSpdyGet(url2.c_str(), 1, MEDIUM)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14614 | |
| 14615 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14616 | CreateMockWrite(req2, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14617 | }; |
| 14618 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14619 | SpdySerializedFrame resp2(spdy_util_secure.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14620 | SpdySerializedFrame body2(spdy_util_secure.ConstructSpdyDataFrame(1, true)); |
| 14621 | MockRead reads2[] = {CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14622 | MockRead(ASYNC, OK, 3)}; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14623 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14624 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 14625 | arraysize(writes2)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14626 | MockConnect connect_data2(ASYNC, OK); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14627 | data2.set_connect_data(connect_data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14628 | |
| 14629 | // Set up a proxy config that sends HTTP requests to a proxy, and |
| 14630 | // all others direct. |
| 14631 | ProxyConfig proxy_config; |
| 14632 | proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14633 | session_deps_.proxy_service = std::make_unique<ProxyService>( |
| 14634 | std::make_unique<ProxyConfigServiceFixed>(proxy_config), nullptr, |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14635 | nullptr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14636 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14637 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14638 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14639 | // Load a valid cert. Note, that this does not need to |
| 14640 | // be valid for proxy because the MockSSLClientSocket does |
| 14641 | // not actually verify it. But SpdySession will use this |
| 14642 | // to see if it is valid for the new origin |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14643 | ssl1.cert = ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem"); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14644 | ASSERT_TRUE(ssl1.cert); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14645 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 14646 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14647 | |
| 14648 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14649 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14650 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 14651 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14652 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14653 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14654 | session_deps_.host_resolver->rules()->AddRule("news.example.org", ip_addr); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14655 | session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14656 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14657 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14658 | |
| 14659 | // Start the first transaction to set up the SpdySession |
| 14660 | HttpRequestInfo request1; |
| 14661 | request1.method = "GET"; |
| 14662 | request1.url = GURL(url1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14663 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14664 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14665 | TestCompletionCallback callback1; |
| 14666 | ASSERT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14667 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14668 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 14669 | data1.RunUntilPaused(); |
| 14670 | base::RunLoop().RunUntilIdle(); |
| 14671 | data1.Resume(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14672 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14673 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14674 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 14675 | |
| 14676 | // Now, start the HTTP request |
| 14677 | HttpRequestInfo request2; |
| 14678 | request2.method = "GET"; |
| 14679 | request2.url = GURL(url2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14680 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14681 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14682 | TestCompletionCallback callback2; |
| 14683 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14684 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 14685 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14686 | |
| 14687 | ASSERT_TRUE(callback2.have_result()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14688 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14689 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 14690 | } |
| 14691 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14692 | // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 14693 | // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 14694 | // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 14695 | // SpdySession) do work. http://crbug.com/224701 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14696 | TEST_F(HttpNetworkTransactionTest, ErrorSocketNotConnected) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14697 | const std::string https_url = "https://www.example.org/"; |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14698 | |
| 14699 | MockRead reads1[] = { |
| 14700 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 14701 | }; |
| 14702 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14703 | SequencedSocketData data1(reads1, arraysize(reads1), NULL, 0); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14704 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14705 | SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14706 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, MEDIUM)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14707 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14708 | CreateMockWrite(req2, 0), |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14709 | }; |
| 14710 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14711 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14712 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14713 | MockRead reads2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14714 | CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
| 14715 | MockRead(ASYNC, OK, 3) // EOF |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14716 | }; |
| 14717 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14718 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 14719 | arraysize(writes2)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14720 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14721 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14722 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14723 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 14724 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14725 | |
| 14726 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14727 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14728 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 14729 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14730 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14731 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14732 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14733 | |
| 14734 | // Start the first transaction to set up the SpdySession and verify that |
| 14735 | // connection was closed. |
| 14736 | HttpRequestInfo request1; |
| 14737 | request1.method = "GET"; |
| 14738 | request1.url = GURL(https_url); |
| 14739 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14740 | HttpNetworkTransaction trans1(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14741 | TestCompletionCallback callback1; |
| 14742 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14743 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14744 | EXPECT_THAT(callback1.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14745 | |
| 14746 | // Now, start the second request and make sure it succeeds. |
| 14747 | HttpRequestInfo request2; |
| 14748 | request2.method = "GET"; |
| 14749 | request2.url = GURL(https_url); |
| 14750 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14751 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14752 | TestCompletionCallback callback2; |
| 14753 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14754 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14755 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14756 | ASSERT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14757 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 14758 | } |
| 14759 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14760 | TEST_F(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14761 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 14762 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14763 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 14764 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14765 | |
| 14766 | // Use two different hosts with different IPs so they don't get pooled. |
| 14767 | session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); |
| 14768 | session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14769 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14770 | |
| 14771 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14772 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14773 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14774 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14775 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 14776 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 14777 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14778 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14779 | spdy_util_.ConstructSpdyGet("https://www.a.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14780 | MockWrite spdy1_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14781 | CreateMockWrite(host1_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14782 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14783 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14784 | SpdySerializedFrame host1_resp_body( |
| 14785 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14786 | MockRead spdy1_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14787 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 14788 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14789 | }; |
| 14790 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14791 | // Use a separate test instance for the separate SpdySession that will be |
| 14792 | // created. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14793 | SpdyTestUtil spdy_util_2; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14794 | auto spdy1_data = std::make_unique<SequencedSocketData>( |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14795 | spdy1_reads, arraysize(spdy1_reads), spdy1_writes, |
| 14796 | arraysize(spdy1_writes)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14797 | session_deps_.socket_factory->AddSocketDataProvider(spdy1_data.get()); |
| 14798 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14799 | SpdySerializedFrame host2_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14800 | spdy_util_2.ConstructSpdyGet("https://www.b.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14801 | MockWrite spdy2_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14802 | CreateMockWrite(host2_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14803 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14804 | SpdySerializedFrame host2_resp(spdy_util_2.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14805 | SpdySerializedFrame host2_resp_body( |
| 14806 | spdy_util_2.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14807 | MockRead spdy2_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14808 | CreateMockRead(host2_resp, 1), CreateMockRead(host2_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 14809 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14810 | }; |
| 14811 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14812 | auto spdy2_data = std::make_unique<SequencedSocketData>( |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14813 | spdy2_reads, arraysize(spdy2_reads), spdy2_writes, |
| 14814 | arraysize(spdy2_writes)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14815 | session_deps_.socket_factory->AddSocketDataProvider(spdy2_data.get()); |
| 14816 | |
| 14817 | MockWrite http_write[] = { |
| 14818 | MockWrite("GET / HTTP/1.1\r\n" |
| 14819 | "Host: www.a.com\r\n" |
| 14820 | "Connection: keep-alive\r\n\r\n"), |
| 14821 | }; |
| 14822 | |
| 14823 | MockRead http_read[] = { |
| 14824 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14825 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 14826 | MockRead("Content-Length: 6\r\n\r\n"), |
| 14827 | MockRead("hello!"), |
| 14828 | }; |
| 14829 | StaticSocketDataProvider http_data(http_read, arraysize(http_read), |
| 14830 | http_write, arraysize(http_write)); |
| 14831 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 14832 | |
| 14833 | HostPortPair host_port_pair_a("www.a.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 14834 | SpdySessionKey spdy_session_key_a( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 14835 | host_port_pair_a, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14836 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14837 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14838 | |
| 14839 | TestCompletionCallback callback; |
| 14840 | HttpRequestInfo request1; |
| 14841 | request1.method = "GET"; |
| 14842 | request1.url = GURL("https://www.a.com/"); |
| 14843 | request1.load_flags = 0; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14844 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14845 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14846 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14847 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14848 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14849 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14850 | |
| 14851 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14852 | ASSERT_TRUE(response); |
| 14853 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14854 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14855 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14856 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14857 | |
| 14858 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14859 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14860 | EXPECT_EQ("hello!", response_data); |
| 14861 | trans.reset(); |
| 14862 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14863 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14864 | |
| 14865 | HostPortPair host_port_pair_b("www.b.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 14866 | SpdySessionKey spdy_session_key_b( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 14867 | host_port_pair_b, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14868 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14869 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14870 | HttpRequestInfo request2; |
| 14871 | request2.method = "GET"; |
| 14872 | request2.url = GURL("https://www.b.com/"); |
| 14873 | request2.load_flags = 0; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14874 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14875 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14876 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14877 | rv = trans->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14878 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14879 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14880 | |
| 14881 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14882 | ASSERT_TRUE(response); |
| 14883 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14884 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14885 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14886 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14887 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14888 | EXPECT_EQ("hello!", response_data); |
| 14889 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14890 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14891 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14892 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14893 | |
| 14894 | HostPortPair host_port_pair_a1("www.a.com", 80); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 14895 | SpdySessionKey spdy_session_key_a1( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 14896 | host_port_pair_a1, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14897 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14898 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14899 | HttpRequestInfo request3; |
| 14900 | request3.method = "GET"; |
| 14901 | request3.url = GURL("http://www.a.com/"); |
| 14902 | request3.load_flags = 0; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14903 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14904 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14905 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14906 | rv = trans->Start(&request3, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14907 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14908 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14909 | |
| 14910 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14911 | ASSERT_TRUE(response); |
| 14912 | ASSERT_TRUE(response->headers); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14913 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 14914 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14915 | EXPECT_FALSE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14916 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14917 | EXPECT_EQ("hello!", response_data); |
| 14918 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14919 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14920 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14921 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14922 | } |
| 14923 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14924 | TEST_F(HttpNetworkTransactionTest, HttpSyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14925 | HttpRequestInfo request; |
| 14926 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14927 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14928 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14929 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14930 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14931 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14932 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14933 | StaticSocketDataProvider data; |
| 14934 | data.set_connect_data(mock_connect); |
| 14935 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14936 | |
| 14937 | TestCompletionCallback callback; |
| 14938 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14939 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14940 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14941 | |
| 14942 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14943 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14944 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14945 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 14946 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14947 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 14948 | |
| 14949 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14950 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 14951 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14952 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14953 | |
| 14954 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14955 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14956 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14957 | } |
| 14958 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14959 | TEST_F(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14960 | HttpRequestInfo request; |
| 14961 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14962 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14963 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14964 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14965 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14966 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14967 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14968 | StaticSocketDataProvider data; |
| 14969 | data.set_connect_data(mock_connect); |
| 14970 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14971 | |
| 14972 | TestCompletionCallback callback; |
| 14973 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14974 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14975 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14976 | |
| 14977 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14978 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14979 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14980 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 14981 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14982 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 14983 | |
| 14984 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14985 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 14986 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14987 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14988 | |
| 14989 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14990 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 14991 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14992 | } |
| 14993 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14994 | TEST_F(HttpNetworkTransactionTest, HttpSyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14995 | HttpRequestInfo request; |
| 14996 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14997 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 14998 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14999 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15000 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15001 | |
| 15002 | MockWrite data_writes[] = { |
| 15003 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15004 | }; |
| 15005 | MockRead data_reads[] = { |
| 15006 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 15007 | }; |
| 15008 | |
| 15009 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 15010 | data_writes, arraysize(data_writes)); |
| 15011 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15012 | |
| 15013 | TestCompletionCallback callback; |
| 15014 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15015 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15016 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15017 | |
| 15018 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15019 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15020 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15021 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15022 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15023 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 15024 | } |
| 15025 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15026 | TEST_F(HttpNetworkTransactionTest, HttpAsyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15027 | HttpRequestInfo request; |
| 15028 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15029 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15030 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15031 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15032 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15033 | |
| 15034 | MockWrite data_writes[] = { |
| 15035 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
| 15036 | }; |
| 15037 | MockRead data_reads[] = { |
| 15038 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 15039 | }; |
| 15040 | |
| 15041 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 15042 | data_writes, arraysize(data_writes)); |
| 15043 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15044 | |
| 15045 | TestCompletionCallback callback; |
| 15046 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15047 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15048 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15049 | |
| 15050 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15051 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15052 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15053 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15054 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15055 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 15056 | } |
| 15057 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15058 | TEST_F(HttpNetworkTransactionTest, HttpSyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15059 | HttpRequestInfo request; |
| 15060 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15061 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15062 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15063 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15064 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15065 | |
| 15066 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15067 | MockWrite( |
| 15068 | "GET / HTTP/1.1\r\n" |
| 15069 | "Host: www.example.org\r\n" |
| 15070 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15071 | }; |
| 15072 | MockRead data_reads[] = { |
| 15073 | MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15074 | }; |
| 15075 | |
| 15076 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 15077 | data_writes, arraysize(data_writes)); |
| 15078 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15079 | |
| 15080 | TestCompletionCallback callback; |
| 15081 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15082 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15083 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15084 | |
| 15085 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15086 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15087 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15088 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15089 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15090 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 15091 | } |
| 15092 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15093 | TEST_F(HttpNetworkTransactionTest, HttpAsyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15094 | HttpRequestInfo request; |
| 15095 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15096 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15097 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15098 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15099 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15100 | |
| 15101 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15102 | MockWrite( |
| 15103 | "GET / HTTP/1.1\r\n" |
| 15104 | "Host: www.example.org\r\n" |
| 15105 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15106 | }; |
| 15107 | MockRead data_reads[] = { |
| 15108 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 15109 | }; |
| 15110 | |
| 15111 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 15112 | data_writes, arraysize(data_writes)); |
| 15113 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15114 | |
| 15115 | TestCompletionCallback callback; |
| 15116 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15117 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15118 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15119 | |
| 15120 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15121 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15122 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15123 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15124 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15125 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 15126 | } |
| 15127 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15128 | TEST_F(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15129 | HttpRequestInfo request; |
| 15130 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15131 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15132 | request.extra_headers.SetHeader("X-Foo", "bar"); |
| 15133 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15134 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15135 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15136 | |
| 15137 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15138 | MockWrite( |
| 15139 | "GET / HTTP/1.1\r\n" |
| 15140 | "Host: www.example.org\r\n" |
| 15141 | "Connection: keep-alive\r\n" |
| 15142 | "X-Foo: bar\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15143 | }; |
| 15144 | MockRead data_reads[] = { |
| 15145 | MockRead("HTTP/1.1 200 OK\r\n" |
| 15146 | "Content-Length: 5\r\n\r\n" |
| 15147 | "hello"), |
| 15148 | MockRead(ASYNC, ERR_UNEXPECTED), |
| 15149 | }; |
| 15150 | |
| 15151 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 15152 | data_writes, arraysize(data_writes)); |
| 15153 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15154 | |
| 15155 | TestCompletionCallback callback; |
| 15156 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15157 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15158 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15159 | |
| 15160 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15161 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15162 | |
| 15163 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15164 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15165 | std::string foo; |
| 15166 | EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo)); |
| 15167 | EXPECT_EQ("bar", foo); |
| 15168 | } |
| 15169 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15170 | namespace { |
| 15171 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 15172 | // Fake HttpStream that simply records calls to SetPriority(). |
| 15173 | class FakeStream : public HttpStream, |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15174 | public base::SupportsWeakPtr<FakeStream> { |
| 15175 | public: |
| 15176 | explicit FakeStream(RequestPriority priority) : priority_(priority) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15177 | ~FakeStream() override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15178 | |
| 15179 | RequestPriority priority() const { return priority_; } |
| 15180 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15181 | int InitializeStream(const HttpRequestInfo* request_info, |
| 15182 | RequestPriority priority, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15183 | const NetLogWithSource& net_log, |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15184 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15185 | return ERR_IO_PENDING; |
| 15186 | } |
| 15187 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15188 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 15189 | HttpResponseInfo* response, |
| 15190 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15191 | ADD_FAILURE(); |
| 15192 | return ERR_UNEXPECTED; |
| 15193 | } |
| 15194 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15195 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15196 | ADD_FAILURE(); |
| 15197 | return ERR_UNEXPECTED; |
| 15198 | } |
| 15199 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15200 | int ReadResponseBody(IOBuffer* buf, |
| 15201 | int buf_len, |
| 15202 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15203 | ADD_FAILURE(); |
| 15204 | return ERR_UNEXPECTED; |
| 15205 | } |
| 15206 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15207 | void Close(bool not_reusable) override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15208 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15209 | bool IsResponseBodyComplete() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15210 | ADD_FAILURE(); |
| 15211 | return false; |
| 15212 | } |
| 15213 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15214 | bool IsConnectionReused() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15215 | ADD_FAILURE(); |
| 15216 | return false; |
| 15217 | } |
| 15218 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15219 | void SetConnectionReused() override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15220 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 15221 | bool CanReuseConnection() const override { return false; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15222 | |
sclittle | 4de1bab9 | 2015-09-22 21:28:24 | [diff] [blame] | 15223 | int64_t GetTotalReceivedBytes() const override { |
[email protected] | bc92bc97 | 2013-12-13 08:32:59 | [diff] [blame] | 15224 | ADD_FAILURE(); |
| 15225 | return 0; |
| 15226 | } |
| 15227 | |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 15228 | int64_t GetTotalSentBytes() const override { |
| 15229 | ADD_FAILURE(); |
| 15230 | return 0; |
| 15231 | } |
| 15232 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15233 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15234 | ADD_FAILURE(); |
| 15235 | return false; |
| 15236 | } |
| 15237 | |
rch | cd37901 | 2017-04-12 21:53:32 | [diff] [blame] | 15238 | bool GetAlternativeService( |
| 15239 | AlternativeService* alternative_service) const override { |
| 15240 | ADD_FAILURE(); |
| 15241 | return false; |
| 15242 | } |
| 15243 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15244 | void GetSSLInfo(SSLInfo* ssl_info) override { ADD_FAILURE(); } |
| 15245 | |
| 15246 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15247 | ADD_FAILURE(); |
| 15248 | } |
| 15249 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15250 | bool GetRemoteEndpoint(IPEndPoint* endpoint) override { return false; } |
| 15251 | |
nharper | 78e6d2b | 2016-09-21 05:42:35 | [diff] [blame] | 15252 | Error GetTokenBindingSignature(crypto::ECPrivateKey* key, |
| 15253 | TokenBindingType tb_type, |
| 15254 | std::vector<uint8_t>* out) override { |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 15255 | ADD_FAILURE(); |
| 15256 | return ERR_NOT_IMPLEMENTED; |
| 15257 | } |
| 15258 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15259 | void Drain(HttpNetworkSession* session) override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15260 | |
zhongyi | ca364fbb | 2015-12-12 03:39:12 | [diff] [blame] | 15261 | void PopulateNetErrorDetails(NetErrorDetails* details) override { return; } |
| 15262 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15263 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15264 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 15265 | HttpStream* RenewStreamForAuth() override { return NULL; } |
| 15266 | |
Andrey Kosyakov | 83a6eee | 2017-08-14 19:20:04 | [diff] [blame] | 15267 | void SetRequestHeadersCallback(RequestHeadersCallback callback) override {} |
| 15268 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15269 | private: |
| 15270 | RequestPriority priority_; |
| 15271 | |
| 15272 | DISALLOW_COPY_AND_ASSIGN(FakeStream); |
| 15273 | }; |
| 15274 | |
| 15275 | // Fake HttpStreamRequest that simply records calls to SetPriority() |
| 15276 | // and vends FakeStreams with its current priority. |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15277 | class FakeStreamRequest : public HttpStreamRequest, |
| 15278 | public base::SupportsWeakPtr<FakeStreamRequest> { |
| 15279 | public: |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15280 | FakeStreamRequest(RequestPriority priority, |
| 15281 | HttpStreamRequest::Delegate* delegate) |
| 15282 | : priority_(priority), |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15283 | delegate_(delegate), |
| 15284 | websocket_stream_create_helper_(NULL) {} |
| 15285 | |
| 15286 | FakeStreamRequest(RequestPriority priority, |
| 15287 | HttpStreamRequest::Delegate* delegate, |
| 15288 | WebSocketHandshakeStreamBase::CreateHelper* create_helper) |
| 15289 | : priority_(priority), |
| 15290 | delegate_(delegate), |
| 15291 | websocket_stream_create_helper_(create_helper) {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15292 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15293 | ~FakeStreamRequest() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15294 | |
| 15295 | RequestPriority priority() const { return priority_; } |
| 15296 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15297 | const WebSocketHandshakeStreamBase::CreateHelper* |
| 15298 | websocket_stream_create_helper() const { |
| 15299 | return websocket_stream_create_helper_; |
| 15300 | } |
| 15301 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15302 | // Create a new FakeStream and pass it to the request's |
| 15303 | // delegate. Returns a weak pointer to the FakeStream. |
| 15304 | base::WeakPtr<FakeStream> FinishStreamRequest() { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15305 | auto fake_stream = std::make_unique<FakeStream>(priority_); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15306 | // Do this before calling OnStreamReady() as OnStreamReady() may |
| 15307 | // immediately delete |fake_stream|. |
| 15308 | base::WeakPtr<FakeStream> weak_stream = fake_stream->AsWeakPtr(); |
bnc | 5029f463 | 2017-06-08 16:19:00 | [diff] [blame] | 15309 | delegate_->OnStreamReady(SSLConfig(), ProxyInfo(), std::move(fake_stream)); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15310 | return weak_stream; |
| 15311 | } |
| 15312 | |
asanka | 681f02d | 2017-02-22 17:06:39 | [diff] [blame] | 15313 | int RestartTunnelWithProxyAuth() override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15314 | ADD_FAILURE(); |
| 15315 | return ERR_UNEXPECTED; |
| 15316 | } |
| 15317 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15318 | LoadState GetLoadState() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15319 | ADD_FAILURE(); |
| 15320 | return LoadState(); |
| 15321 | } |
| 15322 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15323 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15324 | |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15325 | bool was_alpn_negotiated() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15326 | |
bnc | 6227b26e | 2016-08-12 02:00:43 | [diff] [blame] | 15327 | NextProto negotiated_protocol() const override { return kProtoUnknown; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15328 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15329 | bool using_spdy() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15330 | |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 15331 | const ConnectionAttempts& connection_attempts() const override { |
| 15332 | static ConnectionAttempts no_attempts; |
| 15333 | return no_attempts; |
| 15334 | } |
| 15335 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15336 | private: |
| 15337 | RequestPriority priority_; |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15338 | HttpStreamRequest::Delegate* const delegate_; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15339 | WebSocketHandshakeStreamBase::CreateHelper* websocket_stream_create_helper_; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15340 | |
| 15341 | DISALLOW_COPY_AND_ASSIGN(FakeStreamRequest); |
| 15342 | }; |
| 15343 | |
| 15344 | // Fake HttpStreamFactory that vends FakeStreamRequests. |
| 15345 | class FakeStreamFactory : public HttpStreamFactory { |
| 15346 | public: |
| 15347 | FakeStreamFactory() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15348 | ~FakeStreamFactory() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15349 | |
| 15350 | // Returns a WeakPtr<> to the last HttpStreamRequest returned by |
| 15351 | // RequestStream() (which may be NULL if it was destroyed already). |
| 15352 | base::WeakPtr<FakeStreamRequest> last_stream_request() { |
| 15353 | return last_stream_request_; |
| 15354 | } |
| 15355 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15356 | std::unique_ptr<HttpStreamRequest> RequestStream( |
| 15357 | const HttpRequestInfo& info, |
| 15358 | RequestPriority priority, |
| 15359 | const SSLConfig& server_ssl_config, |
| 15360 | const SSLConfig& proxy_ssl_config, |
| 15361 | HttpStreamRequest::Delegate* delegate, |
| 15362 | bool enable_ip_based_pooling, |
| 15363 | bool enable_alternative_services, |
| 15364 | const NetLogWithSource& net_log) override { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15365 | auto fake_request = std::make_unique<FakeStreamRequest>(priority, delegate); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15366 | last_stream_request_ = fake_request->AsWeakPtr(); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15367 | return std::move(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15368 | } |
| 15369 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15370 | std::unique_ptr<HttpStreamRequest> RequestBidirectionalStreamImpl( |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 15371 | const HttpRequestInfo& info, |
| 15372 | RequestPriority priority, |
| 15373 | const SSLConfig& server_ssl_config, |
| 15374 | const SSLConfig& proxy_ssl_config, |
| 15375 | HttpStreamRequest::Delegate* delegate, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15376 | bool enable_ip_based_pooling, |
bnc | accd496 | 2017-04-06 21:00:26 | [diff] [blame] | 15377 | bool enable_alternative_services, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15378 | const NetLogWithSource& net_log) override { |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 15379 | NOTREACHED(); |
| 15380 | return nullptr; |
| 15381 | } |
| 15382 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15383 | std::unique_ptr<HttpStreamRequest> RequestWebSocketHandshakeStream( |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15384 | const HttpRequestInfo& info, |
| 15385 | RequestPriority priority, |
| 15386 | const SSLConfig& server_ssl_config, |
| 15387 | const SSLConfig& proxy_ssl_config, |
| 15388 | HttpStreamRequest::Delegate* delegate, |
[email protected] | 467086b | 2013-11-12 08:19:46 | [diff] [blame] | 15389 | WebSocketHandshakeStreamBase::CreateHelper* create_helper, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15390 | bool enable_ip_based_pooling, |
bnc | accd496 | 2017-04-06 21:00:26 | [diff] [blame] | 15391 | bool enable_alternative_services, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15392 | const NetLogWithSource& net_log) override { |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15393 | auto fake_request = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15394 | std::make_unique<FakeStreamRequest>(priority, delegate, create_helper); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15395 | last_stream_request_ = fake_request->AsWeakPtr(); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15396 | return std::move(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15397 | } |
| 15398 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15399 | void PreconnectStreams(int num_streams, |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 15400 | const HttpRequestInfo& info) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15401 | ADD_FAILURE(); |
| 15402 | } |
| 15403 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15404 | const HostMappingRules* GetHostMappingRules() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15405 | ADD_FAILURE(); |
| 15406 | return NULL; |
| 15407 | } |
| 15408 | |
xunjieli | f5267de | 2017-01-20 21:18:57 | [diff] [blame] | 15409 | void DumpMemoryStats(base::trace_event::ProcessMemoryDump* pmd, |
| 15410 | const std::string& parent_absolute_name) const override { |
| 15411 | ADD_FAILURE(); |
| 15412 | } |
| 15413 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15414 | private: |
| 15415 | base::WeakPtr<FakeStreamRequest> last_stream_request_; |
| 15416 | |
| 15417 | DISALLOW_COPY_AND_ASSIGN(FakeStreamFactory); |
| 15418 | }; |
| 15419 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15420 | // TODO(ricea): Maybe unify this with the one in |
| 15421 | // url_request_http_job_unittest.cc ? |
| 15422 | class FakeWebSocketBasicHandshakeStream : public WebSocketHandshakeStreamBase { |
| 15423 | public: |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15424 | FakeWebSocketBasicHandshakeStream( |
| 15425 | std::unique_ptr<ClientSocketHandle> connection, |
| 15426 | bool using_proxy) |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 15427 | : state_(std::move(connection), using_proxy, false) {} |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15428 | |
| 15429 | // Fake implementation of HttpStreamBase methods. |
| 15430 | // This ends up being quite "real" because this object has to really send data |
| 15431 | // on the mock socket. It might be easier to use the real implementation, but |
| 15432 | // the fact that the WebSocket code is not compiled on iOS makes that |
| 15433 | // difficult. |
| 15434 | int InitializeStream(const HttpRequestInfo* request_info, |
| 15435 | RequestPriority priority, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15436 | const NetLogWithSource& net_log, |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15437 | const CompletionCallback& callback) override { |
| 15438 | state_.Initialize(request_info, priority, net_log, callback); |
| 15439 | return OK; |
| 15440 | } |
| 15441 | |
| 15442 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 15443 | HttpResponseInfo* response, |
| 15444 | const CompletionCallback& callback) override { |
| 15445 | return parser()->SendRequest(state_.GenerateRequestLine(), request_headers, |
| 15446 | response, callback); |
| 15447 | } |
| 15448 | |
| 15449 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
| 15450 | return parser()->ReadResponseHeaders(callback); |
| 15451 | } |
| 15452 | |
| 15453 | int ReadResponseBody(IOBuffer* buf, |
| 15454 | int buf_len, |
| 15455 | const CompletionCallback& callback) override { |
| 15456 | NOTREACHED(); |
| 15457 | return ERR_IO_PENDING; |
| 15458 | } |
| 15459 | |
| 15460 | void Close(bool not_reusable) override { |
| 15461 | if (parser()) |
| 15462 | parser()->Close(true); |
| 15463 | } |
| 15464 | |
| 15465 | bool IsResponseBodyComplete() const override { |
| 15466 | NOTREACHED(); |
| 15467 | return false; |
| 15468 | } |
| 15469 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15470 | bool IsConnectionReused() const override { |
| 15471 | NOTREACHED(); |
| 15472 | return false; |
| 15473 | } |
| 15474 | void SetConnectionReused() override { NOTREACHED(); } |
| 15475 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 15476 | bool CanReuseConnection() const override { return false; } |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15477 | |
sclittle | 4de1bab9 | 2015-09-22 21:28:24 | [diff] [blame] | 15478 | int64_t GetTotalReceivedBytes() const override { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15479 | NOTREACHED(); |
| 15480 | return 0; |
| 15481 | } |
| 15482 | |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 15483 | int64_t GetTotalSentBytes() const override { |
| 15484 | NOTREACHED(); |
| 15485 | return 0; |
| 15486 | } |
| 15487 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15488 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
| 15489 | NOTREACHED(); |
| 15490 | return false; |
| 15491 | } |
| 15492 | |
rch | cd37901 | 2017-04-12 21:53:32 | [diff] [blame] | 15493 | bool GetAlternativeService( |
| 15494 | AlternativeService* alternative_service) const override { |
| 15495 | ADD_FAILURE(); |
| 15496 | return false; |
| 15497 | } |
| 15498 | |
Adam Rice | cb76ac6 | 2015-02-20 05:33:25 | [diff] [blame] | 15499 | void GetSSLInfo(SSLInfo* ssl_info) override {} |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15500 | |
| 15501 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
| 15502 | NOTREACHED(); |
| 15503 | } |
| 15504 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15505 | bool GetRemoteEndpoint(IPEndPoint* endpoint) override { return false; } |
| 15506 | |
nharper | 78e6d2b | 2016-09-21 05:42:35 | [diff] [blame] | 15507 | Error GetTokenBindingSignature(crypto::ECPrivateKey* key, |
| 15508 | TokenBindingType tb_type, |
| 15509 | std::vector<uint8_t>* out) override { |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 15510 | ADD_FAILURE(); |
| 15511 | return ERR_NOT_IMPLEMENTED; |
| 15512 | } |
| 15513 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15514 | void Drain(HttpNetworkSession* session) override { NOTREACHED(); } |
| 15515 | |
zhongyi | ca364fbb | 2015-12-12 03:39:12 | [diff] [blame] | 15516 | void PopulateNetErrorDetails(NetErrorDetails* details) override { return; } |
| 15517 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15518 | void SetPriority(RequestPriority priority) override { NOTREACHED(); } |
| 15519 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15520 | HttpStream* RenewStreamForAuth() override { |
| 15521 | NOTREACHED(); |
| 15522 | return nullptr; |
| 15523 | } |
| 15524 | |
| 15525 | // Fake implementation of WebSocketHandshakeStreamBase method(s) |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15526 | std::unique_ptr<WebSocketStream> Upgrade() override { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15527 | NOTREACHED(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15528 | return std::unique_ptr<WebSocketStream>(); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15529 | } |
| 15530 | |
| 15531 | private: |
| 15532 | HttpStreamParser* parser() const { return state_.parser(); } |
| 15533 | HttpBasicState state_; |
| 15534 | |
| 15535 | DISALLOW_COPY_AND_ASSIGN(FakeWebSocketBasicHandshakeStream); |
| 15536 | }; |
| 15537 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15538 | // TODO(yhirano): Split this class out into a net/websockets file, if it is |
| 15539 | // worth doing. |
| 15540 | class FakeWebSocketStreamCreateHelper : |
| 15541 | public WebSocketHandshakeStreamBase::CreateHelper { |
| 15542 | public: |
bnc | 615cf2f | 2017-05-19 18:53:26 | [diff] [blame] | 15543 | std::unique_ptr<WebSocketHandshakeStreamBase> CreateBasicStream( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15544 | std::unique_ptr<ClientSocketHandle> connection, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 15545 | bool using_proxy) override { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15546 | return std::make_unique<FakeWebSocketBasicHandshakeStream>( |
bnc | 615cf2f | 2017-05-19 18:53:26 | [diff] [blame] | 15547 | std::move(connection), using_proxy); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15548 | } |
| 15549 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15550 | ~FakeWebSocketStreamCreateHelper() override {} |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15551 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15552 | virtual std::unique_ptr<WebSocketStream> Upgrade() { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15553 | NOTREACHED(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15554 | return std::unique_ptr<WebSocketStream>(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15555 | } |
| 15556 | }; |
| 15557 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15558 | } // namespace |
| 15559 | |
| 15560 | // Make sure that HttpNetworkTransaction passes on its priority to its |
| 15561 | // stream request on start. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15562 | TEST_F(HttpNetworkTransactionTest, SetStreamRequestPriorityOnStart) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15563 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15564 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15565 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15566 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15567 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15568 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15569 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15570 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15571 | ASSERT_FALSE(fake_factory->last_stream_request()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15572 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15573 | TestCompletionCallback callback; |
| 15574 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15575 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15576 | |
| 15577 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 15578 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15579 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15580 | EXPECT_EQ(LOW, fake_request->priority()); |
| 15581 | } |
| 15582 | |
| 15583 | // Make sure that HttpNetworkTransaction passes on its priority |
| 15584 | // updates to its stream request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15585 | TEST_F(HttpNetworkTransactionTest, SetStreamRequestPriority) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15586 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15587 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15588 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15589 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15590 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15591 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15592 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15593 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15594 | TestCompletionCallback callback; |
| 15595 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15596 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15597 | |
| 15598 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 15599 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15600 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15601 | EXPECT_EQ(LOW, fake_request->priority()); |
| 15602 | |
| 15603 | trans.SetPriority(LOWEST); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15604 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15605 | EXPECT_EQ(LOWEST, fake_request->priority()); |
| 15606 | } |
| 15607 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15608 | // Make sure that HttpNetworkTransaction passes on its priority |
| 15609 | // updates to its stream. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15610 | TEST_F(HttpNetworkTransactionTest, SetStreamPriority) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15611 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15612 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15613 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15614 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15615 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15616 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15617 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15618 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15619 | TestCompletionCallback callback; |
| 15620 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15621 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15622 | |
| 15623 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 15624 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15625 | ASSERT_TRUE(fake_request); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15626 | base::WeakPtr<FakeStream> fake_stream = fake_request->FinishStreamRequest(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15627 | ASSERT_TRUE(fake_stream); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15628 | EXPECT_EQ(LOW, fake_stream->priority()); |
| 15629 | |
| 15630 | trans.SetPriority(LOWEST); |
| 15631 | EXPECT_EQ(LOWEST, fake_stream->priority()); |
| 15632 | } |
| 15633 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15634 | TEST_F(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15635 | // The same logic needs to be tested for both ws: and wss: schemes, but this |
| 15636 | // test is already parameterised on NextProto, so it uses a loop to verify |
| 15637 | // that the different schemes work. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15638 | std::string test_cases[] = {"ws://www.example.org/", |
| 15639 | "wss://www.example.org/"}; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15640 | for (size_t i = 0; i < arraysize(test_cases); ++i) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15641 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15642 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15643 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
| 15644 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
[email protected] | 0191b51c | 2013-11-18 10:55:23 | [diff] [blame] | 15645 | peer.SetHttpStreamFactoryForWebSocket( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15646 | std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15647 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15648 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15649 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15650 | trans.SetWebSocketHandshakeStreamCreateHelper( |
| 15651 | &websocket_stream_create_helper); |
| 15652 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15653 | TestCompletionCallback callback; |
| 15654 | request.method = "GET"; |
| 15655 | request.url = GURL(test_cases[i]); |
| 15656 | |
| 15657 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15658 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15659 | |
| 15660 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 15661 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15662 | ASSERT_TRUE(fake_request); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15663 | EXPECT_EQ(&websocket_stream_create_helper, |
| 15664 | fake_request->websocket_stream_create_helper()); |
| 15665 | } |
| 15666 | } |
| 15667 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15668 | // Tests that when a used socket is returned to the SSL socket pool, it's closed |
| 15669 | // if the transport socket pool is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15670 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15671 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 15672 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15673 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 15674 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15675 | |
| 15676 | // Set up SSL request. |
| 15677 | |
| 15678 | HttpRequestInfo ssl_request; |
| 15679 | ssl_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15680 | ssl_request.url = GURL("https://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15681 | |
| 15682 | MockWrite ssl_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15683 | MockWrite( |
| 15684 | "GET / HTTP/1.1\r\n" |
| 15685 | "Host: www.example.org\r\n" |
| 15686 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15687 | }; |
| 15688 | MockRead ssl_reads[] = { |
| 15689 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15690 | MockRead("Content-Length: 11\r\n\r\n"), |
| 15691 | MockRead("hello world"), |
| 15692 | MockRead(SYNCHRONOUS, OK), |
| 15693 | }; |
| 15694 | StaticSocketDataProvider ssl_data(ssl_reads, arraysize(ssl_reads), |
| 15695 | ssl_writes, arraysize(ssl_writes)); |
| 15696 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 15697 | |
| 15698 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 15699 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15700 | |
| 15701 | // Set up HTTP request. |
| 15702 | |
| 15703 | HttpRequestInfo http_request; |
| 15704 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15705 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15706 | |
| 15707 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15708 | MockWrite( |
| 15709 | "GET / HTTP/1.1\r\n" |
| 15710 | "Host: www.example.org\r\n" |
| 15711 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15712 | }; |
| 15713 | MockRead http_reads[] = { |
| 15714 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15715 | MockRead("Content-Length: 7\r\n\r\n"), |
| 15716 | MockRead("falafel"), |
| 15717 | MockRead(SYNCHRONOUS, OK), |
| 15718 | }; |
| 15719 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 15720 | http_writes, arraysize(http_writes)); |
| 15721 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 15722 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15723 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15724 | |
| 15725 | // Start the SSL request. |
| 15726 | TestCompletionCallback ssl_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15727 | HttpNetworkTransaction ssl_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15728 | ASSERT_EQ(ERR_IO_PENDING, |
| 15729 | ssl_trans.Start(&ssl_request, ssl_callback.callback(), |
| 15730 | NetLogWithSource())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15731 | |
| 15732 | // Start the HTTP request. Pool should stall. |
| 15733 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15734 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15735 | ASSERT_EQ(ERR_IO_PENDING, |
| 15736 | http_trans.Start(&http_request, http_callback.callback(), |
| 15737 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15738 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15739 | |
| 15740 | // Wait for response from SSL request. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15741 | ASSERT_THAT(ssl_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15742 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15743 | ASSERT_THAT(ReadTransaction(&ssl_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15744 | EXPECT_EQ("hello world", response_data); |
| 15745 | |
| 15746 | // The SSL socket should automatically be closed, so the HTTP request can |
| 15747 | // start. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15748 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 15749 | ASSERT_FALSE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15750 | |
| 15751 | // The HTTP request can now complete. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15752 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15753 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15754 | EXPECT_EQ("falafel", response_data); |
| 15755 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15756 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15757 | } |
| 15758 | |
| 15759 | // Tests that when a SSL connection is established but there's no corresponding |
| 15760 | // request that needs it, the new socket is closed if the transport socket pool |
| 15761 | // is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15762 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15763 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 15764 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15765 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 15766 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15767 | |
| 15768 | // Set up an ssl request. |
| 15769 | |
| 15770 | HttpRequestInfo ssl_request; |
| 15771 | ssl_request.method = "GET"; |
| 15772 | ssl_request.url = GURL("https://www.foopy.com/"); |
| 15773 | |
| 15774 | // No data will be sent on the SSL socket. |
| 15775 | StaticSocketDataProvider ssl_data; |
| 15776 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 15777 | |
| 15778 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 15779 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15780 | |
| 15781 | // Set up HTTP request. |
| 15782 | |
| 15783 | HttpRequestInfo http_request; |
| 15784 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15785 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15786 | |
| 15787 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15788 | MockWrite( |
| 15789 | "GET / HTTP/1.1\r\n" |
| 15790 | "Host: www.example.org\r\n" |
| 15791 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15792 | }; |
| 15793 | MockRead http_reads[] = { |
| 15794 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15795 | MockRead("Content-Length: 7\r\n\r\n"), |
| 15796 | MockRead("falafel"), |
| 15797 | MockRead(SYNCHRONOUS, OK), |
| 15798 | }; |
| 15799 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 15800 | http_writes, arraysize(http_writes)); |
| 15801 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 15802 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15803 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15804 | |
| 15805 | // Preconnect an SSL socket. A preconnect is needed because connect jobs are |
| 15806 | // cancelled when a normal transaction is cancelled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15807 | HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 15808 | http_stream_factory->PreconnectStreams(1, ssl_request); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15809 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15810 | |
| 15811 | // Start the HTTP request. Pool should stall. |
| 15812 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15813 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15814 | ASSERT_EQ(ERR_IO_PENDING, |
| 15815 | http_trans.Start(&http_request, http_callback.callback(), |
| 15816 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15817 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15818 | |
| 15819 | // The SSL connection will automatically be closed once the connection is |
| 15820 | // established, to let the HTTP request start. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15821 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15822 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15823 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15824 | EXPECT_EQ("falafel", response_data); |
| 15825 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15826 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15827 | } |
| 15828 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15829 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15830 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15831 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15832 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15833 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15834 | |
| 15835 | HttpRequestInfo request; |
| 15836 | request.method = "POST"; |
| 15837 | request.url = GURL("http://www.foo.com/"); |
| 15838 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15839 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15840 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15841 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15842 | // Send headers successfully, but get an error while sending the body. |
| 15843 | MockWrite data_writes[] = { |
| 15844 | MockWrite("POST / HTTP/1.1\r\n" |
| 15845 | "Host: www.foo.com\r\n" |
| 15846 | "Connection: keep-alive\r\n" |
| 15847 | "Content-Length: 3\r\n\r\n"), |
| 15848 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15849 | }; |
| 15850 | |
| 15851 | MockRead data_reads[] = { |
| 15852 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 15853 | MockRead("hello world"), |
| 15854 | MockRead(SYNCHRONOUS, OK), |
| 15855 | }; |
| 15856 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15857 | arraysize(data_writes)); |
| 15858 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15859 | |
| 15860 | TestCompletionCallback callback; |
| 15861 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15862 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15863 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15864 | |
| 15865 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15866 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15867 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15868 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15869 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15870 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15871 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15872 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 15873 | |
| 15874 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15875 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15876 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15877 | EXPECT_EQ("hello world", response_data); |
| 15878 | } |
| 15879 | |
| 15880 | // This test makes sure the retry logic doesn't trigger when reading an error |
| 15881 | // response from a server that rejected a POST with a CONNECTION_RESET. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15882 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15883 | PostReadsErrorResponseAfterResetOnReusedSocket) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15884 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15885 | MockWrite data_writes[] = { |
| 15886 | MockWrite("GET / HTTP/1.1\r\n" |
| 15887 | "Host: www.foo.com\r\n" |
| 15888 | "Connection: keep-alive\r\n\r\n"), |
| 15889 | MockWrite("POST / HTTP/1.1\r\n" |
| 15890 | "Host: www.foo.com\r\n" |
| 15891 | "Connection: keep-alive\r\n" |
| 15892 | "Content-Length: 3\r\n\r\n"), |
| 15893 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15894 | }; |
| 15895 | |
| 15896 | MockRead data_reads[] = { |
| 15897 | MockRead("HTTP/1.1 200 Peachy\r\n" |
| 15898 | "Content-Length: 14\r\n\r\n"), |
| 15899 | MockRead("first response"), |
| 15900 | MockRead("HTTP/1.1 400 Not OK\r\n" |
| 15901 | "Content-Length: 15\r\n\r\n"), |
| 15902 | MockRead("second response"), |
| 15903 | MockRead(SYNCHRONOUS, OK), |
| 15904 | }; |
| 15905 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15906 | arraysize(data_writes)); |
| 15907 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15908 | |
| 15909 | TestCompletionCallback callback; |
| 15910 | HttpRequestInfo request1; |
| 15911 | request1.method = "GET"; |
| 15912 | request1.url = GURL("http://www.foo.com/"); |
| 15913 | request1.load_flags = 0; |
| 15914 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15915 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15916 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15917 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15918 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15919 | |
| 15920 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15921 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15922 | |
| 15923 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15924 | ASSERT_TRUE(response1); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15925 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15926 | EXPECT_TRUE(response1->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15927 | EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine()); |
| 15928 | |
| 15929 | std::string response_data1; |
| 15930 | rv = ReadTransaction(trans1.get(), &response_data1); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15931 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15932 | EXPECT_EQ("first response", response_data1); |
| 15933 | // Delete the transaction to release the socket back into the socket pool. |
| 15934 | trans1.reset(); |
| 15935 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15936 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15937 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15938 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15939 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15940 | |
| 15941 | HttpRequestInfo request2; |
| 15942 | request2.method = "POST"; |
| 15943 | request2.url = GURL("http://www.foo.com/"); |
| 15944 | request2.upload_data_stream = &upload_data_stream; |
| 15945 | request2.load_flags = 0; |
| 15946 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15947 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15948 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15949 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15950 | |
| 15951 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15952 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15953 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15954 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15955 | ASSERT_TRUE(response2); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15956 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15957 | EXPECT_TRUE(response2->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15958 | EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine()); |
| 15959 | |
| 15960 | std::string response_data2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15961 | rv = ReadTransaction(&trans2, &response_data2); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15962 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15963 | EXPECT_EQ("second response", response_data2); |
| 15964 | } |
| 15965 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15966 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15967 | PostReadsErrorResponseAfterResetPartialBodySent) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15968 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15969 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15970 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15971 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15972 | |
| 15973 | HttpRequestInfo request; |
| 15974 | request.method = "POST"; |
| 15975 | request.url = GURL("http://www.foo.com/"); |
| 15976 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15977 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15978 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15979 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15980 | // Send headers successfully, but get an error while sending the body. |
| 15981 | MockWrite data_writes[] = { |
| 15982 | MockWrite("POST / HTTP/1.1\r\n" |
| 15983 | "Host: www.foo.com\r\n" |
| 15984 | "Connection: keep-alive\r\n" |
| 15985 | "Content-Length: 3\r\n\r\n" |
| 15986 | "fo"), |
| 15987 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15988 | }; |
| 15989 | |
| 15990 | MockRead data_reads[] = { |
| 15991 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 15992 | MockRead("hello world"), |
| 15993 | MockRead(SYNCHRONOUS, OK), |
| 15994 | }; |
| 15995 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 15996 | arraysize(data_writes)); |
| 15997 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15998 | |
| 15999 | TestCompletionCallback callback; |
| 16000 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16001 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16002 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16003 | |
| 16004 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16005 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16006 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16007 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16008 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16009 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16010 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16011 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 16012 | |
| 16013 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16014 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16015 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16016 | EXPECT_EQ("hello world", response_data); |
| 16017 | } |
| 16018 | |
| 16019 | // This tests the more common case than the previous test, where headers and |
| 16020 | // body are not merged into a single request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16021 | TEST_F(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) { |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 16022 | ChunkedUploadDataStream upload_data_stream(0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16023 | |
| 16024 | HttpRequestInfo request; |
| 16025 | request.method = "POST"; |
| 16026 | request.url = GURL("http://www.foo.com/"); |
| 16027 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16028 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16029 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16030 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16031 | // Send headers successfully, but get an error while sending the body. |
| 16032 | MockWrite data_writes[] = { |
| 16033 | MockWrite("POST / HTTP/1.1\r\n" |
| 16034 | "Host: www.foo.com\r\n" |
| 16035 | "Connection: keep-alive\r\n" |
| 16036 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 16037 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16038 | }; |
| 16039 | |
| 16040 | MockRead data_reads[] = { |
| 16041 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 16042 | MockRead("hello world"), |
| 16043 | MockRead(SYNCHRONOUS, OK), |
| 16044 | }; |
| 16045 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16046 | arraysize(data_writes)); |
| 16047 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16048 | |
| 16049 | TestCompletionCallback callback; |
| 16050 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16051 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16052 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16053 | // Make sure the headers are sent before adding a chunk. This ensures that |
| 16054 | // they can't be merged with the body in a single send. Not currently |
| 16055 | // necessary since a chunked body is never merged with headers, but this makes |
| 16056 | // the test more future proof. |
| 16057 | base::RunLoop().RunUntilIdle(); |
| 16058 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 16059 | upload_data_stream.AppendData("last chunk", 10, true); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16060 | |
| 16061 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16062 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16063 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16064 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16065 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16066 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16067 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16068 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 16069 | |
| 16070 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16071 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16072 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16073 | EXPECT_EQ("hello world", response_data); |
| 16074 | } |
| 16075 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16076 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16077 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16078 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16079 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16080 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16081 | |
| 16082 | HttpRequestInfo request; |
| 16083 | request.method = "POST"; |
| 16084 | request.url = GURL("http://www.foo.com/"); |
| 16085 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16086 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16087 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16088 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16089 | |
| 16090 | MockWrite data_writes[] = { |
| 16091 | MockWrite("POST / HTTP/1.1\r\n" |
| 16092 | "Host: www.foo.com\r\n" |
| 16093 | "Connection: keep-alive\r\n" |
| 16094 | "Content-Length: 3\r\n\r\n"), |
| 16095 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16096 | }; |
| 16097 | |
| 16098 | MockRead data_reads[] = { |
| 16099 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 16100 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 16101 | MockRead("hello world"), |
| 16102 | MockRead(SYNCHRONOUS, OK), |
| 16103 | }; |
| 16104 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16105 | arraysize(data_writes)); |
| 16106 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16107 | |
| 16108 | TestCompletionCallback callback; |
| 16109 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16110 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16111 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16112 | |
| 16113 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16114 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16115 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16116 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16117 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16118 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16119 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16120 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 16121 | |
| 16122 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16123 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16124 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16125 | EXPECT_EQ("hello world", response_data); |
| 16126 | } |
| 16127 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16128 | TEST_F(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16129 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16130 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16131 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16132 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16133 | |
| 16134 | HttpRequestInfo request; |
| 16135 | request.method = "POST"; |
| 16136 | request.url = GURL("http://www.foo.com/"); |
| 16137 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16138 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16139 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16140 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16141 | // Send headers successfully, but get an error while sending the body. |
| 16142 | MockWrite data_writes[] = { |
| 16143 | MockWrite("POST / HTTP/1.1\r\n" |
| 16144 | "Host: www.foo.com\r\n" |
| 16145 | "Connection: keep-alive\r\n" |
| 16146 | "Content-Length: 3\r\n\r\n"), |
| 16147 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16148 | }; |
| 16149 | |
| 16150 | MockRead data_reads[] = { |
| 16151 | MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"), |
| 16152 | MockRead("hello world"), |
| 16153 | MockRead(SYNCHRONOUS, OK), |
| 16154 | }; |
| 16155 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16156 | arraysize(data_writes)); |
| 16157 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16158 | |
| 16159 | TestCompletionCallback callback; |
| 16160 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16161 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16162 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16163 | |
| 16164 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16165 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16166 | } |
| 16167 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16168 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16169 | PostIgnoresNonErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16170 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16171 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16172 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16173 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16174 | |
| 16175 | HttpRequestInfo request; |
| 16176 | request.method = "POST"; |
| 16177 | request.url = GURL("http://www.foo.com/"); |
| 16178 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16179 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16180 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16181 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16182 | // Send headers successfully, but get an error while sending the body. |
| 16183 | MockWrite data_writes[] = { |
| 16184 | MockWrite("POST / HTTP/1.1\r\n" |
| 16185 | "Host: www.foo.com\r\n" |
| 16186 | "Connection: keep-alive\r\n" |
| 16187 | "Content-Length: 3\r\n\r\n"), |
| 16188 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16189 | }; |
| 16190 | |
| 16191 | MockRead data_reads[] = { |
| 16192 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 16193 | MockRead("HTTP/1.0 302 Redirect\r\n"), |
| 16194 | MockRead("Location: http://somewhere-else.com/\r\n"), |
| 16195 | MockRead("Content-Length: 0\r\n\r\n"), |
| 16196 | MockRead(SYNCHRONOUS, OK), |
| 16197 | }; |
| 16198 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16199 | arraysize(data_writes)); |
| 16200 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16201 | |
| 16202 | TestCompletionCallback callback; |
| 16203 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16204 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16205 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16206 | |
| 16207 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16208 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16209 | } |
| 16210 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16211 | TEST_F(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16212 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16213 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16214 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16215 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16216 | |
| 16217 | HttpRequestInfo request; |
| 16218 | request.method = "POST"; |
| 16219 | request.url = GURL("http://www.foo.com/"); |
| 16220 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16221 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16222 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16223 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16224 | // Send headers successfully, but get an error while sending the body. |
| 16225 | MockWrite data_writes[] = { |
| 16226 | MockWrite("POST / HTTP/1.1\r\n" |
| 16227 | "Host: www.foo.com\r\n" |
| 16228 | "Connection: keep-alive\r\n" |
| 16229 | "Content-Length: 3\r\n\r\n"), |
| 16230 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16231 | }; |
| 16232 | |
| 16233 | MockRead data_reads[] = { |
| 16234 | MockRead("HTTP 0.9 rocks!"), |
| 16235 | MockRead(SYNCHRONOUS, OK), |
| 16236 | }; |
| 16237 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16238 | arraysize(data_writes)); |
| 16239 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16240 | |
| 16241 | TestCompletionCallback callback; |
| 16242 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16243 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16244 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16245 | |
| 16246 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16247 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16248 | } |
| 16249 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16250 | TEST_F(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16251 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16252 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16253 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16254 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16255 | |
| 16256 | HttpRequestInfo request; |
| 16257 | request.method = "POST"; |
| 16258 | request.url = GURL("http://www.foo.com/"); |
| 16259 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16260 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16261 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16262 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16263 | // Send headers successfully, but get an error while sending the body. |
| 16264 | MockWrite data_writes[] = { |
| 16265 | MockWrite("POST / HTTP/1.1\r\n" |
| 16266 | "Host: www.foo.com\r\n" |
| 16267 | "Connection: keep-alive\r\n" |
| 16268 | "Content-Length: 3\r\n\r\n"), |
| 16269 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16270 | }; |
| 16271 | |
| 16272 | MockRead data_reads[] = { |
| 16273 | MockRead("HTTP/1.0 400 Not a Full Response\r\n"), |
| 16274 | MockRead(SYNCHRONOUS, OK), |
| 16275 | }; |
| 16276 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16277 | arraysize(data_writes)); |
| 16278 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16279 | |
| 16280 | TestCompletionCallback callback; |
| 16281 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16282 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16283 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16284 | |
| 16285 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16286 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16287 | } |
| 16288 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16289 | // Verify that proxy headers are not sent to the destination server when |
| 16290 | // establishing a tunnel for a secure WebSocket connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16291 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWssTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16292 | HttpRequestInfo request; |
| 16293 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16294 | request.url = GURL("wss://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16295 | AddWebSocketHeaders(&request.extra_headers); |
| 16296 | |
| 16297 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 16298 | session_deps_.proxy_service = |
| 16299 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16300 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16301 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16302 | |
| 16303 | // Since a proxy is configured, try to establish a tunnel. |
| 16304 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16305 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 16306 | "Host: www.example.org:443\r\n" |
| 16307 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16308 | |
| 16309 | // After calling trans->RestartWithAuth(), this is the request we should |
| 16310 | // be issuing -- the final header line contains the credentials. |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16311 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 16312 | "Host: www.example.org:443\r\n" |
| 16313 | "Proxy-Connection: keep-alive\r\n" |
| 16314 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16315 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16316 | MockWrite("GET / HTTP/1.1\r\n" |
| 16317 | "Host: www.example.org\r\n" |
| 16318 | "Connection: Upgrade\r\n" |
| 16319 | "Upgrade: websocket\r\n" |
| 16320 | "Origin: http://www.example.org\r\n" |
| 16321 | "Sec-WebSocket-Version: 13\r\n" |
| 16322 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16323 | }; |
| 16324 | |
| 16325 | // The proxy responds to the connect with a 407, using a persistent |
| 16326 | // connection. |
| 16327 | MockRead data_reads[] = { |
| 16328 | // No credentials. |
| 16329 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 16330 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 16331 | MockRead("Content-Length: 0\r\n"), |
| 16332 | MockRead("Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16333 | |
| 16334 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 16335 | |
| 16336 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 16337 | MockRead("Upgrade: websocket\r\n"), |
| 16338 | MockRead("Connection: Upgrade\r\n"), |
| 16339 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 16340 | }; |
| 16341 | |
| 16342 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16343 | arraysize(data_writes)); |
| 16344 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16345 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 16346 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16347 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16348 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16349 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16350 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 16351 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 16352 | &websocket_stream_create_helper); |
| 16353 | |
| 16354 | { |
| 16355 | TestCompletionCallback callback; |
| 16356 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16357 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16358 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16359 | |
| 16360 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16361 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16362 | } |
| 16363 | |
| 16364 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 16365 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16366 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16367 | EXPECT_EQ(407, response->headers->response_code()); |
| 16368 | |
| 16369 | { |
| 16370 | TestCompletionCallback callback; |
| 16371 | |
| 16372 | int rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 16373 | callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16374 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16375 | |
| 16376 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16377 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16378 | } |
| 16379 | |
| 16380 | response = trans->GetResponseInfo(); |
| 16381 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16382 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16383 | |
| 16384 | EXPECT_EQ(101, response->headers->response_code()); |
| 16385 | |
| 16386 | trans.reset(); |
| 16387 | session->CloseAllConnections(); |
| 16388 | } |
| 16389 | |
| 16390 | // Verify that proxy headers are not sent to the destination server when |
| 16391 | // establishing a tunnel for an insecure WebSocket connection. |
| 16392 | // This requires the authentication info to be injected into the auth cache |
| 16393 | // due to crbug.com/395064 |
| 16394 | // TODO(ricea): Change to use a 407 response once issue 395064 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16395 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWsTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16396 | HttpRequestInfo request; |
| 16397 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16398 | request.url = GURL("ws://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16399 | AddWebSocketHeaders(&request.extra_headers); |
| 16400 | |
| 16401 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 16402 | session_deps_.proxy_service = |
| 16403 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16404 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16405 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16406 | |
| 16407 | MockWrite data_writes[] = { |
| 16408 | // Try to establish a tunnel for the WebSocket connection, with |
| 16409 | // credentials. Because WebSockets have a separate set of socket pools, |
| 16410 | // they cannot and will not use the same TCP/IP connection as the |
| 16411 | // preflight HTTP request. |
| 16412 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16413 | "CONNECT www.example.org:80 HTTP/1.1\r\n" |
| 16414 | "Host: www.example.org:80\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16415 | "Proxy-Connection: keep-alive\r\n" |
| 16416 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 16417 | |
| 16418 | MockWrite( |
| 16419 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16420 | "Host: www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16421 | "Connection: Upgrade\r\n" |
| 16422 | "Upgrade: websocket\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16423 | "Origin: http://www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16424 | "Sec-WebSocket-Version: 13\r\n" |
| 16425 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
| 16426 | }; |
| 16427 | |
| 16428 | MockRead data_reads[] = { |
| 16429 | // HTTP CONNECT with credentials. |
| 16430 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 16431 | |
| 16432 | // WebSocket connection established inside tunnel. |
| 16433 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 16434 | MockRead("Upgrade: websocket\r\n"), |
| 16435 | MockRead("Connection: Upgrade\r\n"), |
| 16436 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 16437 | }; |
| 16438 | |
| 16439 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16440 | arraysize(data_writes)); |
| 16441 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16442 | |
| 16443 | session->http_auth_cache()->Add( |
| 16444 | GURL("http://myproxy:70/"), "MyRealm1", HttpAuth::AUTH_SCHEME_BASIC, |
| 16445 | "Basic realm=MyRealm1", AuthCredentials(kFoo, kBar), "/"); |
| 16446 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16447 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16448 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16449 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 16450 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 16451 | &websocket_stream_create_helper); |
| 16452 | |
| 16453 | TestCompletionCallback callback; |
| 16454 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16455 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16456 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16457 | |
| 16458 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16459 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16460 | |
| 16461 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 16462 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16463 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16464 | |
| 16465 | EXPECT_EQ(101, response->headers->response_code()); |
| 16466 | |
| 16467 | trans.reset(); |
| 16468 | session->CloseAllConnections(); |
| 16469 | } |
| 16470 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16471 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16472 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16473 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16474 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16475 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16476 | |
| 16477 | HttpRequestInfo request; |
| 16478 | request.method = "POST"; |
| 16479 | request.url = GURL("http://www.foo.com/"); |
| 16480 | request.upload_data_stream = &upload_data_stream; |
| 16481 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16482 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16483 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16484 | MockWrite data_writes[] = { |
| 16485 | MockWrite("POST / HTTP/1.1\r\n" |
| 16486 | "Host: www.foo.com\r\n" |
| 16487 | "Connection: keep-alive\r\n" |
| 16488 | "Content-Length: 3\r\n\r\n"), |
| 16489 | MockWrite("foo"), |
| 16490 | }; |
| 16491 | |
| 16492 | MockRead data_reads[] = { |
| 16493 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16494 | MockRead(SYNCHRONOUS, OK), |
| 16495 | }; |
| 16496 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16497 | arraysize(data_writes)); |
| 16498 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16499 | |
| 16500 | TestCompletionCallback callback; |
| 16501 | |
| 16502 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16503 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16504 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16505 | |
| 16506 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16507 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16508 | |
| 16509 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16510 | trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16511 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16512 | trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16513 | } |
| 16514 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16515 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost100Continue) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16516 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16517 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16518 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16519 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16520 | |
| 16521 | HttpRequestInfo request; |
| 16522 | request.method = "POST"; |
| 16523 | request.url = GURL("http://www.foo.com/"); |
| 16524 | request.upload_data_stream = &upload_data_stream; |
| 16525 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16526 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16527 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16528 | MockWrite data_writes[] = { |
| 16529 | MockWrite("POST / HTTP/1.1\r\n" |
| 16530 | "Host: www.foo.com\r\n" |
| 16531 | "Connection: keep-alive\r\n" |
| 16532 | "Content-Length: 3\r\n\r\n"), |
| 16533 | MockWrite("foo"), |
| 16534 | }; |
| 16535 | |
| 16536 | MockRead data_reads[] = { |
| 16537 | MockRead("HTTP/1.1 100 Continue\r\n\r\n"), |
| 16538 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16539 | MockRead(SYNCHRONOUS, OK), |
| 16540 | }; |
| 16541 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16542 | arraysize(data_writes)); |
| 16543 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16544 | |
| 16545 | TestCompletionCallback callback; |
| 16546 | |
| 16547 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16548 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16549 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16550 | |
| 16551 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16552 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16553 | |
| 16554 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16555 | trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16556 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16557 | trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16558 | } |
| 16559 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16560 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesChunkedPost) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16561 | ChunkedUploadDataStream upload_data_stream(0); |
| 16562 | |
| 16563 | HttpRequestInfo request; |
| 16564 | request.method = "POST"; |
| 16565 | request.url = GURL("http://www.foo.com/"); |
| 16566 | request.upload_data_stream = &upload_data_stream; |
| 16567 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16568 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16569 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16570 | // Send headers successfully, but get an error while sending the body. |
| 16571 | MockWrite data_writes[] = { |
| 16572 | MockWrite("POST / HTTP/1.1\r\n" |
| 16573 | "Host: www.foo.com\r\n" |
| 16574 | "Connection: keep-alive\r\n" |
| 16575 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 16576 | MockWrite("1\r\nf\r\n"), MockWrite("2\r\noo\r\n"), MockWrite("0\r\n\r\n"), |
| 16577 | }; |
| 16578 | |
| 16579 | MockRead data_reads[] = { |
| 16580 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16581 | MockRead(SYNCHRONOUS, OK), |
| 16582 | }; |
| 16583 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16584 | arraysize(data_writes)); |
| 16585 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16586 | |
| 16587 | TestCompletionCallback callback; |
| 16588 | |
| 16589 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16590 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16591 | |
| 16592 | base::RunLoop().RunUntilIdle(); |
| 16593 | upload_data_stream.AppendData("f", 1, false); |
| 16594 | |
| 16595 | base::RunLoop().RunUntilIdle(); |
| 16596 | upload_data_stream.AppendData("oo", 2, true); |
| 16597 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16598 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16599 | |
| 16600 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16601 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16602 | |
| 16603 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16604 | trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16605 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16606 | trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16607 | } |
| 16608 | |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16609 | // Confirm that transactions whose throttle is created in (and stays in) |
| 16610 | // the unthrottled state are not blocked. |
| 16611 | TEST_F(HttpNetworkTransactionTest, ThrottlingUnthrottled) { |
| 16612 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16613 | std::unique_ptr<HttpNetworkSession> session( |
| 16614 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16615 | |
| 16616 | // Send a simple request and make sure it goes through. |
| 16617 | HttpRequestInfo request; |
| 16618 | request.method = "GET"; |
| 16619 | request.url = GURL("http://www.example.org/"); |
| 16620 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16621 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16622 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16623 | |
| 16624 | MockWrite data_writes[] = { |
| 16625 | MockWrite("GET / HTTP/1.1\r\n" |
| 16626 | "Host: www.example.org\r\n" |
| 16627 | "Connection: keep-alive\r\n\r\n"), |
| 16628 | }; |
| 16629 | MockRead data_reads[] = { |
| 16630 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16631 | MockRead(SYNCHRONOUS, OK), |
| 16632 | }; |
| 16633 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16634 | arraysize(data_writes)); |
| 16635 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16636 | |
| 16637 | TestCompletionCallback callback; |
| 16638 | trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16639 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 16640 | } |
| 16641 | |
| 16642 | // Confirm requests can be blocked by a throttler, and are resumed |
| 16643 | // when the throttle is unblocked. |
| 16644 | TEST_F(HttpNetworkTransactionTest, ThrottlingBasic) { |
| 16645 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16646 | std::unique_ptr<HttpNetworkSession> session( |
| 16647 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16648 | |
| 16649 | // Send a simple request and make sure it goes through. |
| 16650 | HttpRequestInfo request; |
| 16651 | request.method = "GET"; |
| 16652 | request.url = GURL("http://www.example.org/"); |
| 16653 | |
| 16654 | MockWrite data_writes[] = { |
| 16655 | MockWrite("GET / HTTP/1.1\r\n" |
| 16656 | "Host: www.example.org\r\n" |
| 16657 | "Connection: keep-alive\r\n\r\n"), |
| 16658 | }; |
| 16659 | MockRead data_reads[] = { |
| 16660 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16661 | MockRead(SYNCHRONOUS, OK), |
| 16662 | }; |
| 16663 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16664 | arraysize(data_writes)); |
| 16665 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16666 | |
| 16667 | // Start a request that will be throttled at start; confirm it |
| 16668 | // doesn't complete. |
| 16669 | throttler->set_throttle_new_requests(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16670 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16671 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16672 | |
| 16673 | TestCompletionCallback callback; |
| 16674 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16675 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16676 | |
| 16677 | base::RunLoop().RunUntilIdle(); |
| 16678 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 16679 | EXPECT_FALSE(callback.have_result()); |
| 16680 | |
| 16681 | // Confirm the request goes on to complete when unthrottled. |
| 16682 | throttler->UnthrottleAllRequests(); |
| 16683 | base::RunLoop().RunUntilIdle(); |
| 16684 | ASSERT_TRUE(callback.have_result()); |
| 16685 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 16686 | } |
| 16687 | |
| 16688 | // Destroy a request while it's throttled. |
| 16689 | TEST_F(HttpNetworkTransactionTest, ThrottlingDestruction) { |
| 16690 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16691 | std::unique_ptr<HttpNetworkSession> session( |
| 16692 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16693 | |
| 16694 | // Send a simple request and make sure it goes through. |
| 16695 | HttpRequestInfo request; |
| 16696 | request.method = "GET"; |
| 16697 | request.url = GURL("http://www.example.org/"); |
| 16698 | |
| 16699 | MockWrite data_writes[] = { |
| 16700 | MockWrite("GET / HTTP/1.1\r\n" |
| 16701 | "Host: www.example.org\r\n" |
| 16702 | "Connection: keep-alive\r\n\r\n"), |
| 16703 | }; |
| 16704 | MockRead data_reads[] = { |
| 16705 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16706 | MockRead(SYNCHRONOUS, OK), |
| 16707 | }; |
| 16708 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16709 | arraysize(data_writes)); |
| 16710 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16711 | |
| 16712 | // Start a request that will be throttled at start; confirm it |
| 16713 | // doesn't complete. |
| 16714 | throttler->set_throttle_new_requests(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16715 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16716 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16717 | |
| 16718 | TestCompletionCallback callback; |
| 16719 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16720 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16721 | |
| 16722 | base::RunLoop().RunUntilIdle(); |
| 16723 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 16724 | EXPECT_FALSE(callback.have_result()); |
| 16725 | |
| 16726 | EXPECT_EQ(1u, throttler->num_outstanding_requests()); |
| 16727 | trans.reset(); |
| 16728 | EXPECT_EQ(0u, throttler->num_outstanding_requests()); |
| 16729 | } |
| 16730 | |
| 16731 | // Confirm the throttler receives SetPriority calls. |
| 16732 | TEST_F(HttpNetworkTransactionTest, ThrottlingPrioritySet) { |
| 16733 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16734 | std::unique_ptr<HttpNetworkSession> session( |
| 16735 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16736 | |
| 16737 | // Send a simple request and make sure it goes through. |
| 16738 | HttpRequestInfo request; |
| 16739 | request.method = "GET"; |
| 16740 | request.url = GURL("http://www.example.org/"); |
| 16741 | |
| 16742 | MockWrite data_writes[] = { |
| 16743 | MockWrite("GET / HTTP/1.1\r\n" |
| 16744 | "Host: www.example.org\r\n" |
| 16745 | "Connection: keep-alive\r\n\r\n"), |
| 16746 | }; |
| 16747 | MockRead data_reads[] = { |
| 16748 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16749 | MockRead(SYNCHRONOUS, OK), |
| 16750 | }; |
| 16751 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16752 | arraysize(data_writes)); |
| 16753 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16754 | |
| 16755 | throttler->set_throttle_new_requests(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16756 | auto trans = std::make_unique<HttpNetworkTransaction>(IDLE, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16757 | // Start the transaction to associate a throttle with it. |
| 16758 | TestCompletionCallback callback; |
| 16759 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16760 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16761 | |
| 16762 | EXPECT_EQ(0, throttler->num_set_priority_calls()); |
| 16763 | trans->SetPriority(LOW); |
| 16764 | EXPECT_EQ(1, throttler->num_set_priority_calls()); |
| 16765 | EXPECT_EQ(LOW, throttler->last_priority_set()); |
| 16766 | |
| 16767 | throttler->UnthrottleAllRequests(); |
| 16768 | base::RunLoop().RunUntilIdle(); |
| 16769 | ASSERT_TRUE(callback.have_result()); |
| 16770 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 16771 | } |
| 16772 | |
| 16773 | // Confirm that unthrottling from a SetPriority call by the |
| 16774 | // throttler works properly. |
| 16775 | TEST_F(HttpNetworkTransactionTest, ThrottlingPrioritySetUnthrottle) { |
| 16776 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16777 | std::unique_ptr<HttpNetworkSession> session( |
| 16778 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16779 | |
| 16780 | // Send a simple request and make sure it goes through. |
| 16781 | HttpRequestInfo request; |
| 16782 | request.method = "GET"; |
| 16783 | request.url = GURL("http://www.example.org/"); |
| 16784 | |
| 16785 | MockWrite data_writes[] = { |
| 16786 | MockWrite("GET / HTTP/1.1\r\n" |
| 16787 | "Host: www.example.org\r\n" |
| 16788 | "Connection: keep-alive\r\n\r\n"), |
| 16789 | }; |
| 16790 | MockRead data_reads[] = { |
| 16791 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16792 | MockRead(SYNCHRONOUS, OK), |
| 16793 | }; |
| 16794 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16795 | arraysize(data_writes)); |
| 16796 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16797 | |
| 16798 | StaticSocketDataProvider reads1(data_reads, arraysize(data_reads), |
| 16799 | data_writes, arraysize(data_writes)); |
| 16800 | session_deps_.socket_factory->AddSocketDataProvider(&reads1); |
| 16801 | |
| 16802 | // Start a request that will be throttled at start; confirm it |
| 16803 | // doesn't complete. |
| 16804 | throttler->set_throttle_new_requests(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16805 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16806 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16807 | |
| 16808 | TestCompletionCallback callback; |
| 16809 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16810 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16811 | |
| 16812 | base::RunLoop().RunUntilIdle(); |
| 16813 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 16814 | EXPECT_FALSE(callback.have_result()); |
| 16815 | |
| 16816 | // Create a new request, call SetPriority on it to unthrottle, |
| 16817 | // and make sure that allows the original request to complete. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16818 | auto trans1 = std::make_unique<HttpNetworkTransaction>(LOW, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16819 | throttler->set_priority_change_closure( |
| 16820 | base::Bind(&TestNetworkStreamThrottler::UnthrottleAllRequests, |
| 16821 | base::Unretained(throttler))); |
| 16822 | |
| 16823 | // Start the transaction to associate a throttle with it. |
| 16824 | TestCompletionCallback callback1; |
| 16825 | rv = trans1->Start(&request, callback1.callback(), NetLogWithSource()); |
| 16826 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16827 | |
| 16828 | trans1->SetPriority(IDLE); |
| 16829 | |
| 16830 | base::RunLoop().RunUntilIdle(); |
| 16831 | ASSERT_TRUE(callback.have_result()); |
| 16832 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 16833 | ASSERT_TRUE(callback1.have_result()); |
| 16834 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 16835 | } |
| 16836 | |
| 16837 | // Transaction will be destroyed when the unique_ptr goes out of scope. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16838 | void DestroyTransaction(std::unique_ptr<HttpNetworkTransaction> transaction) {} |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16839 | |
| 16840 | // Confirm that destroying a transaction from a SetPriority call by the |
| 16841 | // throttler works properly. |
| 16842 | TEST_F(HttpNetworkTransactionTest, ThrottlingPrioritySetDestroy) { |
| 16843 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16844 | std::unique_ptr<HttpNetworkSession> session( |
| 16845 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16846 | |
| 16847 | // Send a simple request and make sure it goes through. |
| 16848 | HttpRequestInfo request; |
| 16849 | request.method = "GET"; |
| 16850 | request.url = GURL("http://www.example.org/"); |
| 16851 | |
| 16852 | MockWrite data_writes[] = { |
| 16853 | MockWrite("GET / HTTP/1.1\r\n" |
| 16854 | "Host: www.example.org\r\n" |
| 16855 | "Connection: keep-alive\r\n\r\n"), |
| 16856 | }; |
| 16857 | MockRead data_reads[] = { |
| 16858 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16859 | MockRead(SYNCHRONOUS, OK), |
| 16860 | }; |
| 16861 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16862 | arraysize(data_writes)); |
| 16863 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16864 | |
| 16865 | StaticSocketDataProvider reads1(data_reads, arraysize(data_reads), |
| 16866 | data_writes, arraysize(data_writes)); |
| 16867 | session_deps_.socket_factory->AddSocketDataProvider(&reads1); |
| 16868 | |
| 16869 | // Start a request that will be throttled at start; confirm it |
| 16870 | // doesn't complete. |
| 16871 | throttler->set_throttle_new_requests(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16872 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16873 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16874 | |
| 16875 | TestCompletionCallback callback; |
| 16876 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16877 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16878 | |
| 16879 | base::RunLoop().RunUntilIdle(); |
| 16880 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 16881 | EXPECT_FALSE(callback.have_result()); |
| 16882 | |
| 16883 | // Arrange for the set priority call on the above transaction to delete |
| 16884 | // the transaction. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16885 | HttpNetworkTransaction* trans_ptr(trans.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16886 | throttler->set_priority_change_closure( |
| 16887 | base::Bind(&DestroyTransaction, base::Passed(&trans))); |
| 16888 | |
| 16889 | // Call it and check results (partially a "doesn't crash" test). |
| 16890 | trans_ptr->SetPriority(IDLE); |
| 16891 | trans_ptr = nullptr; // No longer a valid pointer. |
| 16892 | |
| 16893 | base::RunLoop().RunUntilIdle(); |
| 16894 | ASSERT_FALSE(callback.have_result()); |
| 16895 | } |
| 16896 | |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16897 | #if !defined(OS_IOS) |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16898 | TEST_F(HttpNetworkTransactionTest, TokenBindingSpdy) { |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16899 | const std::string https_url = "https://www.example.com"; |
| 16900 | HttpRequestInfo request; |
| 16901 | request.url = GURL(https_url); |
| 16902 | request.method = "GET"; |
| 16903 | |
| 16904 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 16905 | ssl.token_binding_negotiated = true; |
| 16906 | ssl.token_binding_key_param = TB_PARAM_ECDSAP256; |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16907 | ssl.next_proto = kProtoHTTP2; |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16908 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16909 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16910 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16911 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 16912 | MockRead reads[] = {CreateMockRead(resp), CreateMockRead(body), |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16913 | MockRead(ASYNC, ERR_IO_PENDING)}; |
| 16914 | StaticSocketDataProvider data(reads, arraysize(reads), nullptr, 0); |
| 16915 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16916 | session_deps_.channel_id_service = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16917 | std::make_unique<ChannelIDService>(new DefaultChannelIDStore(nullptr)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16918 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16919 | |
| 16920 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 16921 | TestCompletionCallback callback; |
| 16922 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16923 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
fdoray | f33fede | 2017-05-11 21:18:10 | [diff] [blame] | 16924 | |
| 16925 | NetTestSuite::GetScopedTaskEnvironment()->RunUntilIdle(); |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 16926 | |
| 16927 | EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); |
| 16928 | HttpRequestHeaders headers; |
| 16929 | ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); |
| 16930 | EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); |
| 16931 | } |
| 16932 | #endif // !defined(OS_IOS) |
| 16933 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 16934 | void CheckContentEncodingMatching(SpdySessionDependencies* session_deps, |
| 16935 | const std::string& accept_encoding, |
| 16936 | const std::string& content_encoding, |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 16937 | const std::string& location, |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 16938 | bool should_match) { |
| 16939 | HttpRequestInfo request; |
| 16940 | request.method = "GET"; |
| 16941 | request.url = GURL("http://www.foo.com/"); |
| 16942 | request.extra_headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, |
| 16943 | accept_encoding); |
| 16944 | |
| 16945 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps)); |
| 16946 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 16947 | // Send headers successfully, but get an error while sending the body. |
| 16948 | MockWrite data_writes[] = { |
| 16949 | MockWrite("GET / HTTP/1.1\r\n" |
| 16950 | "Host: www.foo.com\r\n" |
| 16951 | "Connection: keep-alive\r\n" |
| 16952 | "Accept-Encoding: "), |
| 16953 | MockWrite(accept_encoding.data()), MockWrite("\r\n\r\n"), |
| 16954 | }; |
| 16955 | |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 16956 | std::string response_code = "200 OK"; |
| 16957 | std::string extra; |
| 16958 | if (!location.empty()) { |
| 16959 | response_code = "301 Redirect\r\nLocation: "; |
| 16960 | response_code.append(location); |
| 16961 | } |
| 16962 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 16963 | MockRead data_reads[] = { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 16964 | MockRead("HTTP/1.0 "), |
| 16965 | MockRead(response_code.data()), |
| 16966 | MockRead("\r\nContent-Encoding: "), |
| 16967 | MockRead(content_encoding.data()), |
| 16968 | MockRead("\r\n\r\n"), |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 16969 | MockRead(SYNCHRONOUS, OK), |
| 16970 | }; |
| 16971 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16972 | arraysize(data_writes)); |
| 16973 | session_deps->socket_factory->AddSocketDataProvider(&data); |
| 16974 | |
| 16975 | TestCompletionCallback callback; |
| 16976 | |
| 16977 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 16978 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16979 | |
| 16980 | rv = callback.WaitForResult(); |
| 16981 | if (should_match) { |
| 16982 | EXPECT_THAT(rv, IsOk()); |
| 16983 | } else { |
| 16984 | EXPECT_THAT(rv, IsError(ERR_CONTENT_DECODING_FAILED)); |
| 16985 | } |
| 16986 | } |
| 16987 | |
| 16988 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding1) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 16989 | CheckContentEncodingMatching(&session_deps_, "gzip,sdch", "br", "", false); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 16990 | } |
| 16991 | |
| 16992 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding2) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 16993 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "", "", |
| 16994 | true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 16995 | } |
| 16996 | |
| 16997 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding3) { |
| 16998 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 16999 | "", false); |
| 17000 | } |
| 17001 | |
| 17002 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding4) { |
| 17003 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
| 17004 | "www.foo.com/other", true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17005 | } |
| 17006 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17007 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsSync) { |
| 17008 | ProxyConfig proxy_config; |
| 17009 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 17010 | proxy_config.set_pac_mandatory(true); |
| 17011 | MockAsyncProxyResolver resolver; |
| 17012 | session_deps_.proxy_service.reset(new ProxyService( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17013 | std::make_unique<ProxyConfigServiceFixed>(proxy_config), |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17014 | base::WrapUnique(new FailingProxyResolverFactory), nullptr)); |
| 17015 | |
| 17016 | HttpRequestInfo request; |
| 17017 | request.method = "GET"; |
| 17018 | request.url = GURL("http://www.example.org/"); |
| 17019 | |
| 17020 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 17021 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17022 | |
| 17023 | TestCompletionCallback callback; |
| 17024 | |
| 17025 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17026 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17027 | EXPECT_THAT(callback.WaitForResult(), |
| 17028 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 17029 | } |
| 17030 | |
| 17031 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsAsync) { |
| 17032 | ProxyConfig proxy_config; |
| 17033 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 17034 | proxy_config.set_pac_mandatory(true); |
| 17035 | MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 17036 | new MockAsyncProxyResolverFactory(false); |
| 17037 | MockAsyncProxyResolver resolver; |
| 17038 | session_deps_.proxy_service.reset( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17039 | new ProxyService(std::make_unique<ProxyConfigServiceFixed>(proxy_config), |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17040 | base::WrapUnique(proxy_resolver_factory), nullptr)); |
| 17041 | HttpRequestInfo request; |
| 17042 | request.method = "GET"; |
| 17043 | request.url = GURL("http://www.example.org/"); |
| 17044 | |
| 17045 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 17046 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17047 | |
| 17048 | TestCompletionCallback callback; |
| 17049 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17050 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17051 | |
| 17052 | proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder( |
| 17053 | ERR_FAILED, &resolver); |
| 17054 | EXPECT_THAT(callback.WaitForResult(), |
| 17055 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 17056 | } |
| 17057 | |
| 17058 | TEST_F(HttpNetworkTransactionTest, NoSupportedProxies) { |
| 17059 | session_deps_.proxy_service = |
| 17060 | ProxyService::CreateFixedFromPacResult("QUIC myproxy.org:443"); |
| 17061 | session_deps_.enable_quic = false; |
| 17062 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 17063 | |
| 17064 | HttpRequestInfo request; |
| 17065 | request.method = "GET"; |
| 17066 | request.url = GURL("http://www.example.org/"); |
| 17067 | |
| 17068 | TestCompletionCallback callback; |
| 17069 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17070 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17071 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17072 | |
| 17073 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_NO_SUPPORTED_PROXIES)); |
| 17074 | } |
| 17075 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 17076 | } // namespace net |