[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); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 808 | EXPECT_EQ("https://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"; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 5953 | request.url = GURL("https://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] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5979 | }; |
| 5980 | |
| 5981 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5982 | // After restarting with a null identity, this is the |
| 5983 | // request we should be issuing -- the final header line contains a Type |
| 5984 | // 1 message. |
| 5985 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5986 | "Host: 172.22.68.17\r\n" |
| 5987 | "Connection: keep-alive\r\n" |
| 5988 | "Authorization: NTLM " |
| 5989 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5990 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5991 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 5992 | // (the credentials for the origin server). The second request continues |
| 5993 | // on the same connection. |
| 5994 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5995 | "Host: 172.22.68.17\r\n" |
| 5996 | "Connection: keep-alive\r\n" |
| 5997 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 5998 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 5999 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBVKW" |
| 6000 | "Yma5xzVAAAAAAAAAAAAAAAAAAAAACH+gWcm+YsP9Tqb9zCR3WAeZZX" |
| 6001 | "ahlhx5I=\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6002 | }; |
| 6003 | |
| 6004 | MockRead data_reads2[] = { |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame^] | 6005 | // The origin server responds with a Type 2 message. |
| 6006 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 6007 | MockRead("WWW-Authenticate: NTLM " |
| 6008 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCjGpMpPGlYKkAAAAAAAAAALo" |
| 6009 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 6010 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 6011 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 6012 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 6013 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 6014 | "BtAAAAAAA=\r\n"), |
| 6015 | MockRead("Content-Length: 42\r\n"), |
| 6016 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6017 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6018 | |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame^] | 6019 | // Lastly we get the desired content. |
| 6020 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6021 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 6022 | MockRead("Content-Length: 14\r\n\r\n"), MockRead("Please Login\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6023 | }; |
| 6024 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6025 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6026 | data_writes1, arraysize(data_writes1)); |
| 6027 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6028 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6029 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6030 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6031 | |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6032 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 6033 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 6034 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 6035 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 6036 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6037 | TestCompletionCallback callback1; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6038 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6039 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6040 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6041 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6042 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6043 | |
| 6044 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6045 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6046 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6047 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6048 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6049 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6050 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6051 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6052 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6053 | TestCompletionCallback callback2; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6054 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6055 | rv = trans.RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
| 6056 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6057 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6058 | |
| 6059 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6060 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6061 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6062 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6063 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6064 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6065 | ASSERT_TRUE(response); |
| 6066 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6067 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6068 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6069 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6070 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6071 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6072 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6073 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6074 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6075 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6076 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6077 | ASSERT_TRUE(response); |
| 6078 | EXPECT_FALSE(response->auth_challenge); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame^] | 6079 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 6080 | |
| 6081 | std::string response_data; |
| 6082 | rv = ReadTransaction(&trans, &response_data); |
| 6083 | EXPECT_THAT(rv, IsOk()); |
| 6084 | EXPECT_EQ("Please Login\r\n", response_data); |
| 6085 | |
| 6086 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 6087 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
| 6088 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 6089 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6090 | } |
| 6091 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6092 | // Enter a wrong password, and then the correct one. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6093 | TEST_F(HttpNetworkTransactionTest, NTLMAuth2) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6094 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6095 | request.method = "GET"; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6096 | request.url = GURL("https://172.22.68.17/kids/login.aspx"); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6097 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6098 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom2, |
| 6099 | MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6100 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6101 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6102 | MockWrite data_writes1[] = { |
| 6103 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6104 | "Host: 172.22.68.17\r\n" |
| 6105 | "Connection: keep-alive\r\n\r\n"), |
| 6106 | }; |
| 6107 | |
| 6108 | MockRead data_reads1[] = { |
| 6109 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 6110 | // Negotiate and NTLM are often requested together. However, we only want |
| 6111 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 6112 | // the header that requests Negotiate for this test. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6113 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 6114 | MockRead("Connection: close\r\n"), |
| 6115 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6116 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6117 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6118 | }; |
| 6119 | |
| 6120 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6121 | // After restarting with a null identity, this is the |
| 6122 | // request we should be issuing -- the final header line contains a Type |
| 6123 | // 1 message. |
| 6124 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6125 | "Host: 172.22.68.17\r\n" |
| 6126 | "Connection: keep-alive\r\n" |
| 6127 | "Authorization: NTLM " |
| 6128 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6129 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6130 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 6131 | // (the credentials for the origin server). The second request continues |
| 6132 | // on the same connection. |
| 6133 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6134 | "Host: 172.22.68.17\r\n" |
| 6135 | "Connection: keep-alive\r\n" |
| 6136 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 6137 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 6138 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwCWeY" |
| 6139 | "XnSZNwoQAAAAAAAAAAAAAAAAAAAADLa34/phTTKzNTWdub+uyFleOj" |
| 6140 | "4Ww7b7E=\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6141 | }; |
| 6142 | |
| 6143 | MockRead data_reads2[] = { |
| 6144 | // The origin server responds with a Type 2 message. |
| 6145 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 6146 | MockRead("WWW-Authenticate: NTLM " |
| 6147 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCbVWUZezVGpAAAAAAAAAAALo" |
| 6148 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 6149 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 6150 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 6151 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 6152 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 6153 | "BtAAAAAAA=\r\n"), |
| 6154 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6155 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6156 | MockRead("You are not authorized to view this page\r\n"), |
| 6157 | |
| 6158 | // Wrong password. |
| 6159 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6160 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 6161 | MockRead("Connection: close\r\n"), |
| 6162 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6163 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6164 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6165 | }; |
| 6166 | |
| 6167 | MockWrite data_writes3[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6168 | // After restarting with a null identity, this is the |
| 6169 | // request we should be issuing -- the final header line contains a Type |
| 6170 | // 1 message. |
| 6171 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6172 | "Host: 172.22.68.17\r\n" |
| 6173 | "Connection: keep-alive\r\n" |
| 6174 | "Authorization: NTLM " |
| 6175 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6176 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6177 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 6178 | // (the credentials for the origin server). The second request continues |
| 6179 | // on the same connection. |
| 6180 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6181 | "Host: 172.22.68.17\r\n" |
| 6182 | "Connection: keep-alive\r\n" |
| 6183 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 6184 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 6185 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBO54" |
| 6186 | "dFMVvTHwAAAAAAAAAAAAAAAAAAAACS7sT6Uzw7L0L//WUqlIaVWpbI" |
| 6187 | "+4MUm7c=\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6188 | }; |
| 6189 | |
| 6190 | MockRead data_reads3[] = { |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame^] | 6191 | // The origin server responds with a Type 2 message. |
| 6192 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 6193 | MockRead("WWW-Authenticate: NTLM " |
| 6194 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCL24VN8dgOR8AAAAAAAAAALo" |
| 6195 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 6196 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 6197 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 6198 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 6199 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 6200 | "BtAAAAAAA=\r\n"), |
| 6201 | MockRead("Content-Length: 42\r\n"), |
| 6202 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6203 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6204 | |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame^] | 6205 | // Lastly we get the desired content. |
| 6206 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6207 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 6208 | MockRead("Content-Length: 14\r\n\r\n"), MockRead("Please Login\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6209 | }; |
| 6210 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6211 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6212 | data_writes1, arraysize(data_writes1)); |
| 6213 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6214 | data_writes2, arraysize(data_writes2)); |
| 6215 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6216 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6217 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6218 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6219 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6220 | |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6221 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 6222 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 6223 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 6224 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 6225 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 6226 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 6227 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6228 | TestCompletionCallback callback1; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6229 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6230 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6231 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6232 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6233 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6234 | |
| 6235 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6236 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6237 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6238 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6239 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6240 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6241 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6242 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6243 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6244 | TestCompletionCallback callback2; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6245 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6246 | // Enter the wrong password. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6247 | rv = trans.RestartWithAuth(AuthCredentials(kTestingNTLM, kWrongPassword), |
| 6248 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6249 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6250 | |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6251 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6252 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6253 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6254 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6255 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6256 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6257 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6258 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6259 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6260 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6261 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6262 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6263 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6264 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6265 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6266 | TestCompletionCallback callback4; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6267 | |
| 6268 | // Now enter the right password. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6269 | rv = trans.RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
| 6270 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6271 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6272 | |
| 6273 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6274 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6275 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6276 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6277 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6278 | TestCompletionCallback callback5; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6279 | |
| 6280 | // One more roundtrip |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6281 | rv = trans.RestartWithAuth(AuthCredentials(), callback5.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6282 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6283 | |
| 6284 | rv = callback5.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6285 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6286 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6287 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6288 | EXPECT_FALSE(response->auth_challenge); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame^] | 6289 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 6290 | |
| 6291 | std::string response_data; |
| 6292 | rv = ReadTransaction(&trans, &response_data); |
| 6293 | EXPECT_THAT(rv, IsOk()); |
| 6294 | EXPECT_EQ("Please Login\r\n", response_data); |
| 6295 | |
| 6296 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 6297 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
| 6298 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 6299 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
| 6300 | EXPECT_TRUE(data3.AllReadDataConsumed()); |
| 6301 | EXPECT_TRUE(data3.AllWriteDataConsumed()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6302 | } |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6303 | |
| 6304 | // NTLM is not supported over HTTP/2, therefore the server requests a downgrade, |
| 6305 | // and the request is retried on an HTTP/1.1 connection. |
| 6306 | TEST_F(HttpNetworkTransactionTest, NTLMOverHttp2) { |
| 6307 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom1, |
| 6308 | MockGetHostName); |
| 6309 | |
| 6310 | const char* kUrl = "https://172.22.68.17/kids/login.aspx"; |
| 6311 | |
| 6312 | HttpRequestInfo request; |
| 6313 | request.method = "GET"; |
| 6314 | request.url = GURL(kUrl); |
| 6315 | |
| 6316 | // First request without credentials. |
| 6317 | SpdyHeaderBlock request_headers0(spdy_util_.ConstructGetHeaderBlock(kUrl)); |
| 6318 | SpdySerializedFrame request0(spdy_util_.ConstructSpdyHeaders( |
| 6319 | 1, std::move(request_headers0), LOWEST, true)); |
| 6320 | |
| 6321 | SpdyHeaderBlock response_headers0; |
| 6322 | response_headers0[spdy_util_.GetStatusKey()] = "401"; |
| 6323 | response_headers0["www-authenticate"] = "NTLM"; |
| 6324 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyResponseHeaders( |
| 6325 | 1, std::move(response_headers0), true)); |
| 6326 | |
| 6327 | // Stream 1 is closed. |
| 6328 | spdy_util_.UpdateWithStreamDestruction(1); |
| 6329 | |
| 6330 | // Retry with authorization header. |
| 6331 | SpdyHeaderBlock request_headers1(spdy_util_.ConstructGetHeaderBlock(kUrl)); |
| 6332 | request_headers1["authorization"] = |
| 6333 | "NTLM TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA="; |
| 6334 | SpdySerializedFrame request1(spdy_util_.ConstructSpdyHeaders( |
| 6335 | 3, std::move(request_headers1), LOWEST, true)); |
| 6336 | |
| 6337 | SpdySerializedFrame go_away(spdy_util_.ConstructSpdyGoAway( |
| 6338 | 0, ERROR_CODE_HTTP_1_1_REQUIRED, "NTLM not supported over HTTP/2.")); |
| 6339 | |
| 6340 | MockWrite writes0[] = { |
| 6341 | CreateMockWrite(request0, 0), CreateMockWrite(request1, 2), |
| 6342 | }; |
| 6343 | MockRead reads0[] = {CreateMockRead(resp, 1), CreateMockRead(go_away, 3)}; |
| 6344 | |
| 6345 | // Retry yet again using HTTP/1.1. |
| 6346 | MockWrite writes1[] = { |
| 6347 | // After restarting with a null identity, this is the |
| 6348 | // request we should be issuing -- the final header line contains a Type |
| 6349 | // 1 message. |
| 6350 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6351 | "Host: 172.22.68.17\r\n" |
| 6352 | "Connection: keep-alive\r\n" |
| 6353 | "Authorization: NTLM " |
| 6354 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 6355 | |
| 6356 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 6357 | // (the credentials for the origin server). The second request continues |
| 6358 | // on the same connection. |
| 6359 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6360 | "Host: 172.22.68.17\r\n" |
| 6361 | "Connection: keep-alive\r\n" |
| 6362 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 6363 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 6364 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBVKW" |
| 6365 | "Yma5xzVAAAAAAAAAAAAAAAAAAAAACH+gWcm+YsP9Tqb9zCR3WAeZZX" |
| 6366 | "ahlhx5I=\r\n\r\n"), |
| 6367 | }; |
| 6368 | |
| 6369 | MockRead reads1[] = { |
| 6370 | // The origin server responds with a Type 2 message. |
| 6371 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 6372 | MockRead("WWW-Authenticate: NTLM " |
| 6373 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCjGpMpPGlYKkAAAAAAAAAALo" |
| 6374 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 6375 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 6376 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 6377 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 6378 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 6379 | "BtAAAAAAA=\r\n"), |
| 6380 | MockRead("Content-Length: 42\r\n"), |
| 6381 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6382 | MockRead("You are not authorized to view this page\r\n"), |
| 6383 | |
| 6384 | // Lastly we get the desired content. |
| 6385 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6386 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame^] | 6387 | MockRead("Content-Length: 14\r\n\r\n"), MockRead("Please Login\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6388 | }; |
| 6389 | SequencedSocketData data0(reads0, arraysize(reads0), writes0, |
| 6390 | arraysize(writes0)); |
| 6391 | StaticSocketDataProvider data1(reads1, arraysize(reads1), writes1, |
| 6392 | arraysize(writes1)); |
| 6393 | session_deps_.socket_factory->AddSocketDataProvider(&data0); |
| 6394 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6395 | |
| 6396 | SSLSocketDataProvider ssl0(ASYNC, OK); |
| 6397 | ssl0.next_proto = kProtoHTTP2; |
| 6398 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 6399 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl0); |
| 6400 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 6401 | |
| 6402 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6403 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 6404 | |
| 6405 | TestCompletionCallback callback1; |
| 6406 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
| 6407 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6408 | |
| 6409 | rv = callback1.WaitForResult(); |
| 6410 | EXPECT_THAT(rv, IsOk()); |
| 6411 | |
| 6412 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
| 6413 | |
| 6414 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 6415 | ASSERT_TRUE(response); |
| 6416 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
| 6417 | |
| 6418 | TestCompletionCallback callback2; |
| 6419 | |
| 6420 | rv = trans.RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
| 6421 | callback2.callback()); |
| 6422 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6423 | |
| 6424 | rv = callback2.WaitForResult(); |
| 6425 | EXPECT_THAT(rv, IsOk()); |
| 6426 | |
| 6427 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 6428 | |
| 6429 | response = trans.GetResponseInfo(); |
| 6430 | ASSERT_TRUE(response); |
| 6431 | EXPECT_FALSE(response->auth_challenge); |
| 6432 | |
| 6433 | TestCompletionCallback callback3; |
| 6434 | |
| 6435 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
| 6436 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6437 | |
| 6438 | rv = callback3.WaitForResult(); |
| 6439 | EXPECT_THAT(rv, IsOk()); |
| 6440 | |
| 6441 | response = trans.GetResponseInfo(); |
| 6442 | ASSERT_TRUE(response); |
| 6443 | EXPECT_FALSE(response->auth_challenge); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame^] | 6444 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 6445 | |
| 6446 | std::string response_data; |
| 6447 | rv = ReadTransaction(&trans, &response_data); |
| 6448 | EXPECT_THAT(rv, IsOk()); |
| 6449 | EXPECT_EQ("Please Login\r\n", response_data); |
| 6450 | |
| 6451 | EXPECT_TRUE(data0.AllReadDataConsumed()); |
| 6452 | EXPECT_TRUE(data0.AllWriteDataConsumed()); |
| 6453 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 6454 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6455 | } |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6456 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6457 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6458 | // Test reading a server response which has only headers, and no body. |
| 6459 | // After some maximum number of bytes is consumed, the transaction should |
| 6460 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6461 | TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6462 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6463 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6464 | request.url = GURL("http://www.example.org/"); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6465 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6466 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6467 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6468 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 6469 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 6470 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 6471 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6472 | |
| 6473 | MockRead data_reads[] = { |
| 6474 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6475 | MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6476 | MockRead("\r\nBODY"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6477 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6478 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6479 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6480 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6481 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6482 | TestCompletionCallback callback; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6483 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6484 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6485 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6486 | |
| 6487 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6488 | EXPECT_THAT(rv, IsError(ERR_RESPONSE_HEADERS_TOO_BIG)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6489 | } |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6490 | |
| 6491 | // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 6492 | // establish tunnel. |
| 6493 | // http://code.google.com/p/chromium/issues/detail?id=3772 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6494 | TEST_F(HttpNetworkTransactionTest, DontRecycleTransportSocketForSSLTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6495 | HttpRequestInfo request; |
| 6496 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6497 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6498 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6499 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 6500 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 6501 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6502 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6503 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6504 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6505 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6506 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6507 | // Since we have proxy, should try to establish tunnel. |
| 6508 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 6509 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6510 | "Host: www.example.org:443\r\n" |
| 6511 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6512 | }; |
| 6513 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 6514 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6515 | // connection. Usually a proxy would return 501 (not implemented), |
| 6516 | // or 200 (tunnel established). |
| 6517 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 6518 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 6519 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6520 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6521 | }; |
| 6522 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6523 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6524 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6525 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6526 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6527 | TestCompletionCallback callback1; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6528 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6529 | int rv = trans->Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6530 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6531 | |
| 6532 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6533 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6534 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6535 | // Empty the current queue. This is necessary because idle sockets are |
| 6536 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6537 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6538 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6539 | // We now check to make sure the TCPClientSocket was not added back to |
| 6540 | // the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6541 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6542 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6543 | base::RunLoop().RunUntilIdle(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6544 | // Make sure that the socket didn't get recycled after calling the destructor. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6545 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6546 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6547 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6548 | // Make sure that we recycle a socket after reading all of the response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6549 | TEST_F(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6550 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6551 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6552 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6553 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6554 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6555 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6556 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6557 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6558 | MockRead data_reads[] = { |
| 6559 | // A part of the response body is received with the response headers. |
| 6560 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 6561 | // The rest of the response body is received in two parts. |
| 6562 | MockRead("lo"), |
| 6563 | MockRead(" world"), |
| 6564 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6565 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6566 | }; |
| 6567 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6568 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6569 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6570 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6571 | TestCompletionCallback callback; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6572 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6573 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6574 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6575 | |
| 6576 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6577 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6578 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6579 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6580 | ASSERT_TRUE(response); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6581 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6582 | EXPECT_TRUE(response->headers); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6583 | std::string status_line = response->headers->GetStatusLine(); |
| 6584 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 6585 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6586 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6587 | |
| 6588 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6589 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6590 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6591 | EXPECT_EQ("hello world", response_data); |
| 6592 | |
| 6593 | // Empty the current queue. This is necessary because idle sockets are |
| 6594 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6595 | base::RunLoop().RunUntilIdle(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6596 | |
| 6597 | // 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] | 6598 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6599 | } |
| 6600 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6601 | // Make sure that we recycle a SSL socket after reading all of the response |
| 6602 | // body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6603 | TEST_F(HttpNetworkTransactionTest, RecycleSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6604 | HttpRequestInfo request; |
| 6605 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6606 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6607 | |
| 6608 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6609 | MockWrite( |
| 6610 | "GET / HTTP/1.1\r\n" |
| 6611 | "Host: www.example.org\r\n" |
| 6612 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6613 | }; |
| 6614 | |
| 6615 | MockRead data_reads[] = { |
| 6616 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6617 | MockRead("Content-Length: 11\r\n\r\n"), |
| 6618 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6619 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6620 | }; |
| 6621 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6622 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6623 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6624 | |
| 6625 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6626 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6627 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6628 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6629 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6630 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6631 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6632 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6633 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6634 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6635 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6636 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6637 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6638 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6639 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6640 | ASSERT_TRUE(response); |
| 6641 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6642 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6643 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6644 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6645 | |
| 6646 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6647 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6648 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6649 | EXPECT_EQ("hello world", response_data); |
| 6650 | |
| 6651 | // Empty the current queue. This is necessary because idle sockets are |
| 6652 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6653 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6654 | |
| 6655 | // 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] | 6656 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6657 | } |
| 6658 | |
| 6659 | // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it |
| 6660 | // from the pool and make sure that we recover okay. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6661 | TEST_F(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6662 | HttpRequestInfo request; |
| 6663 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6664 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6665 | |
| 6666 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6667 | MockWrite( |
| 6668 | "GET / HTTP/1.1\r\n" |
| 6669 | "Host: www.example.org\r\n" |
| 6670 | "Connection: keep-alive\r\n\r\n"), |
| 6671 | MockWrite( |
| 6672 | "GET / HTTP/1.1\r\n" |
| 6673 | "Host: www.example.org\r\n" |
| 6674 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6675 | }; |
| 6676 | |
| 6677 | MockRead data_reads[] = { |
mmenke | 911ee022 | 2015-12-04 03:58:42 | [diff] [blame] | 6678 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 6679 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6680 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6681 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6682 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6683 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6684 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6685 | |
| 6686 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6687 | data_writes, arraysize(data_writes)); |
| 6688 | StaticSocketDataProvider data2(data_reads, arraysize(data_reads), |
| 6689 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6690 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6691 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6692 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6693 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6694 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6695 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6696 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6697 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6698 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6699 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6700 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6701 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6702 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6703 | |
| 6704 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6705 | ASSERT_TRUE(response); |
| 6706 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6707 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6708 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6709 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6710 | |
| 6711 | std::string response_data; |
| 6712 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6713 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6714 | EXPECT_EQ("hello world", response_data); |
| 6715 | |
| 6716 | // Empty the current queue. This is necessary because idle sockets are |
| 6717 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6718 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6719 | |
| 6720 | // 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] | 6721 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6722 | |
| 6723 | // Now start the second transaction, which should reuse the previous socket. |
| 6724 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6725 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6726 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6727 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6728 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6729 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6730 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6731 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6732 | |
| 6733 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6734 | ASSERT_TRUE(response); |
| 6735 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6736 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6737 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6738 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6739 | |
| 6740 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6741 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6742 | EXPECT_EQ("hello world", response_data); |
| 6743 | |
| 6744 | // Empty the current queue. This is necessary because idle sockets are |
| 6745 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6746 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6747 | |
| 6748 | // 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] | 6749 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6750 | } |
| 6751 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6752 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 6753 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6754 | TEST_F(HttpNetworkTransactionTest, FlushSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6755 | HttpRequestInfo request; |
| 6756 | request.method = "GET"; |
| 6757 | request.url = GURL("http://www.example.org/"); |
| 6758 | request.load_flags = 0; |
| 6759 | |
| 6760 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6761 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6762 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6763 | |
| 6764 | MockRead data_reads[] = { |
| 6765 | // A part of the response body is received with the response headers. |
| 6766 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 6767 | // The rest of the response body is received in two parts. |
| 6768 | MockRead("lo"), MockRead(" world"), |
| 6769 | MockRead("junk"), // Should not be read!! |
| 6770 | MockRead(SYNCHRONOUS, OK), |
| 6771 | }; |
| 6772 | |
| 6773 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 6774 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6775 | |
| 6776 | TestCompletionCallback callback; |
| 6777 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6778 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6779 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6780 | |
| 6781 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6782 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6783 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6784 | ASSERT_TRUE(response); |
| 6785 | EXPECT_TRUE(response->headers); |
| 6786 | std::string status_line = response->headers->GetStatusLine(); |
| 6787 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 6788 | |
| 6789 | // Make memory critical notification and ensure the transaction still has been |
| 6790 | // operating right. |
| 6791 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 6792 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 6793 | base::RunLoop().RunUntilIdle(); |
| 6794 | |
| 6795 | // Socket should not be flushed as long as it is not idle. |
| 6796 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 6797 | |
| 6798 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6799 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6800 | EXPECT_THAT(rv, IsOk()); |
| 6801 | EXPECT_EQ("hello world", response_data); |
| 6802 | |
| 6803 | // Empty the current queue. This is necessary because idle sockets are |
| 6804 | // added to the connection pool asynchronously with a PostTask. |
| 6805 | base::RunLoop().RunUntilIdle(); |
| 6806 | |
| 6807 | // We now check to make sure the socket was added back to the pool. |
| 6808 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 6809 | |
| 6810 | // Idle sockets should be flushed now. |
| 6811 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 6812 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 6813 | base::RunLoop().RunUntilIdle(); |
| 6814 | |
| 6815 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 6816 | } |
| 6817 | |
| 6818 | // Grab an SSL socket, use it, and put it back into the pool. Then, make |
| 6819 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6820 | TEST_F(HttpNetworkTransactionTest, FlushSSLSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6821 | HttpRequestInfo request; |
| 6822 | request.method = "GET"; |
| 6823 | request.url = GURL("https://www.example.org/"); |
| 6824 | request.load_flags = 0; |
| 6825 | |
| 6826 | MockWrite data_writes[] = { |
| 6827 | MockWrite("GET / HTTP/1.1\r\n" |
| 6828 | "Host: www.example.org\r\n" |
| 6829 | "Connection: keep-alive\r\n\r\n"), |
| 6830 | }; |
| 6831 | |
| 6832 | MockRead data_reads[] = { |
| 6833 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 6834 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
| 6835 | |
| 6836 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6837 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6838 | |
| 6839 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 6840 | arraysize(data_writes)); |
| 6841 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6842 | |
| 6843 | TestCompletionCallback callback; |
| 6844 | |
| 6845 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6846 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6847 | |
| 6848 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6849 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6850 | |
| 6851 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6852 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6853 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6854 | ASSERT_TRUE(response); |
| 6855 | ASSERT_TRUE(response->headers); |
| 6856 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6857 | |
| 6858 | // Make memory critical notification and ensure the transaction still has been |
| 6859 | // operating right. |
| 6860 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 6861 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 6862 | base::RunLoop().RunUntilIdle(); |
| 6863 | |
| 6864 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 6865 | |
| 6866 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6867 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6868 | EXPECT_THAT(rv, IsOk()); |
| 6869 | EXPECT_EQ("hello world", response_data); |
| 6870 | |
| 6871 | // Empty the current queue. This is necessary because idle sockets are |
| 6872 | // added to the connection pool asynchronously with a PostTask. |
| 6873 | base::RunLoop().RunUntilIdle(); |
| 6874 | |
| 6875 | // We now check to make sure the socket was added back to the pool. |
| 6876 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 6877 | |
| 6878 | // Make memory notification once again and ensure idle socket is closed. |
| 6879 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 6880 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 6881 | base::RunLoop().RunUntilIdle(); |
| 6882 | |
| 6883 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 6884 | } |
| 6885 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6886 | // Make sure that we recycle a socket after a zero-length response. |
| 6887 | // http://crbug.com/9880 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6888 | TEST_F(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6889 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6890 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6891 | request.url = GURL( |
| 6892 | "http://www.example.org/csi?v=3&s=web&action=&" |
| 6893 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 6894 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 6895 | "rt=prt.2642,ol.2649,xjs.2951"); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6896 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6897 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6898 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6899 | MockRead data_reads[] = { |
| 6900 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 6901 | "Content-Length: 0\r\n" |
| 6902 | "Content-Type: text/html\r\n\r\n"), |
| 6903 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6904 | MockRead(SYNCHRONOUS, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6905 | }; |
| 6906 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6907 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6908 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6909 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 6910 | // Transaction must be created after the MockReads, so it's destroyed before |
| 6911 | // them. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6912 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 6913 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6914 | TestCompletionCallback callback; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6915 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6916 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6917 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6918 | |
| 6919 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6920 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6921 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6922 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6923 | ASSERT_TRUE(response); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6924 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6925 | EXPECT_TRUE(response->headers); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6926 | std::string status_line = response->headers->GetStatusLine(); |
| 6927 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 6928 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6929 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6930 | |
| 6931 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6932 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6933 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6934 | EXPECT_EQ("", response_data); |
| 6935 | |
| 6936 | // Empty the current queue. This is necessary because idle sockets are |
| 6937 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6938 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6939 | |
| 6940 | // 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] | 6941 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6942 | } |
| 6943 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6944 | TEST_F(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6945 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 6946 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6947 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 6948 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 6949 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6950 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6951 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 6952 | // after use. |
| 6953 | request[0].method = "GET"; |
| 6954 | request[0].url = GURL("http://www.google.com/"); |
| 6955 | request[0].load_flags = 0; |
| 6956 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 6957 | // transaction 1. The first attempts fails when writing the POST data. |
| 6958 | // This causes the transaction to retry with a new socket. The second |
| 6959 | // attempt succeeds. |
| 6960 | request[1].method = "POST"; |
| 6961 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 6962 | request[1].upload_data_stream = &upload_data_stream; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6963 | request[1].load_flags = 0; |
| 6964 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6965 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6966 | |
| 6967 | // The first socket is used for transaction 1 and the first attempt of |
| 6968 | // transaction 2. |
| 6969 | |
| 6970 | // The response of transaction 1. |
| 6971 | MockRead data_reads1[] = { |
| 6972 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 6973 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6974 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6975 | }; |
| 6976 | // The mock write results of transaction 1 and the first attempt of |
| 6977 | // transaction 2. |
| 6978 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6979 | MockWrite(SYNCHRONOUS, 64), // GET |
| 6980 | MockWrite(SYNCHRONOUS, 93), // POST |
| 6981 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6982 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6983 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6984 | data_writes1, arraysize(data_writes1)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6985 | |
| 6986 | // The second socket is used for the second attempt of transaction 2. |
| 6987 | |
| 6988 | // The response of transaction 2. |
| 6989 | MockRead data_reads2[] = { |
| 6990 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 6991 | MockRead("welcome"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6992 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6993 | }; |
| 6994 | // The mock write results of the second attempt of transaction 2. |
| 6995 | MockWrite data_writes2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6996 | MockWrite(SYNCHRONOUS, 93), // POST |
| 6997 | MockWrite(SYNCHRONOUS, 3), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6998 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6999 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7000 | data_writes2, arraysize(data_writes2)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7001 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7002 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7003 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7004 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 7005 | const char* const kExpectedResponseData[] = { |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7006 | "hello world", "welcome" |
| 7007 | }; |
| 7008 | |
| 7009 | for (int i = 0; i < 2; ++i) { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7010 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7011 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7012 | TestCompletionCallback callback; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7013 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7014 | int rv = trans.Start(&request[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7015 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7016 | |
| 7017 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7018 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [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] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7022 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7023 | EXPECT_TRUE(response->headers); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7024 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 7025 | |
| 7026 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7027 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7028 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7029 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 7030 | } |
| 7031 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7032 | |
| 7033 | // Test the request-challenge-retry sequence for basic auth when there is |
| 7034 | // 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] | 7035 | // it fails the identity from the URL is used to answer the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7036 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7037 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7038 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7039 | request.url = GURL("http://foo:b@[email protected]/"); |
[email protected] | 7b08ba6 | 2012-02-10 20:19:41 | [diff] [blame] | 7040 | request.load_flags = LOAD_NORMAL; |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 7041 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7042 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7043 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7044 | |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 7045 | // The password contains an escaped character -- for this test to pass it |
| 7046 | // will need to be unescaped by HttpNetworkTransaction. |
| 7047 | EXPECT_EQ("b%40r", request.url.password()); |
| 7048 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7049 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7050 | MockWrite( |
| 7051 | "GET / HTTP/1.1\r\n" |
| 7052 | "Host: www.example.org\r\n" |
| 7053 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7054 | }; |
| 7055 | |
| 7056 | MockRead data_reads1[] = { |
| 7057 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7058 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7059 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7060 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7061 | }; |
| 7062 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7063 | // After the challenge above, the transaction will be restarted using the |
| 7064 | // identity from the url (foo, b@r) to answer the challenge. |
| 7065 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7066 | MockWrite( |
| 7067 | "GET / HTTP/1.1\r\n" |
| 7068 | "Host: www.example.org\r\n" |
| 7069 | "Connection: keep-alive\r\n" |
| 7070 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7071 | }; |
| 7072 | |
| 7073 | MockRead data_reads2[] = { |
| 7074 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7075 | MockRead("Content-Length: 100\r\n\r\n"), |
| 7076 | MockRead(SYNCHRONOUS, OK), |
| 7077 | }; |
| 7078 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7079 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7080 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7081 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7082 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7083 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7084 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7085 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7086 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7087 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7088 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7089 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7090 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7091 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7092 | |
| 7093 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7094 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7095 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7096 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7097 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7098 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7099 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7100 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7101 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7102 | |
| 7103 | // There is no challenge info, since the identity in URL worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7104 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7105 | |
| 7106 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7107 | |
| 7108 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7109 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7110 | } |
| 7111 | |
| 7112 | // Test the request-challenge-retry sequence for basic auth when there is an |
| 7113 | // incorrect identity in the URL. The identity from the URL should be used only |
| 7114 | // once. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7115 | TEST_F(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7116 | HttpRequestInfo request; |
| 7117 | request.method = "GET"; |
| 7118 | // Note: the URL has a username:password in it. The password "baz" is |
| 7119 | // wrong (should be "bar"). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7120 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7121 | |
| 7122 | request.load_flags = LOAD_NORMAL; |
| 7123 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7124 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7125 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7126 | |
| 7127 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7128 | MockWrite( |
| 7129 | "GET / HTTP/1.1\r\n" |
| 7130 | "Host: www.example.org\r\n" |
| 7131 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7132 | }; |
| 7133 | |
| 7134 | MockRead data_reads1[] = { |
| 7135 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7136 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7137 | MockRead("Content-Length: 10\r\n\r\n"), |
| 7138 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 7139 | }; |
| 7140 | |
| 7141 | // After the challenge above, the transaction will be restarted using the |
| 7142 | // identity from the url (foo, baz) to answer the challenge. |
| 7143 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7144 | MockWrite( |
| 7145 | "GET / HTTP/1.1\r\n" |
| 7146 | "Host: www.example.org\r\n" |
| 7147 | "Connection: keep-alive\r\n" |
| 7148 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7149 | }; |
| 7150 | |
| 7151 | MockRead data_reads2[] = { |
| 7152 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7153 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7154 | MockRead("Content-Length: 10\r\n\r\n"), |
| 7155 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 7156 | }; |
| 7157 | |
| 7158 | // After the challenge above, the transaction will be restarted using the |
| 7159 | // identity supplied by the user (foo, bar) to answer the challenge. |
| 7160 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7161 | MockWrite( |
| 7162 | "GET / HTTP/1.1\r\n" |
| 7163 | "Host: www.example.org\r\n" |
| 7164 | "Connection: keep-alive\r\n" |
| 7165 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7166 | }; |
| 7167 | |
| 7168 | MockRead data_reads3[] = { |
| 7169 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7170 | MockRead("Content-Length: 100\r\n\r\n"), |
| 7171 | MockRead(SYNCHRONOUS, OK), |
| 7172 | }; |
| 7173 | |
| 7174 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7175 | data_writes1, arraysize(data_writes1)); |
| 7176 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7177 | data_writes2, arraysize(data_writes2)); |
| 7178 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 7179 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7180 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7181 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7182 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7183 | |
| 7184 | TestCompletionCallback callback1; |
| 7185 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7186 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7187 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7188 | |
| 7189 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7190 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7191 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7192 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7193 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7194 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7195 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7196 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7197 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7198 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7199 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7200 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7201 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7202 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 7203 | |
| 7204 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7205 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7206 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7207 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7208 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7209 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7210 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7211 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7212 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7213 | |
| 7214 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7215 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7216 | |
| 7217 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7218 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 7219 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7220 | base::RunLoop().RunUntilIdle(); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 7221 | } |
| 7222 | |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7223 | |
| 7224 | // Test the request-challenge-retry sequence for basic auth when there is a |
| 7225 | // correct identity in the URL, but its use is being suppressed. The identity |
| 7226 | // from the URL should never be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7227 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURLSuppressed) { |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7228 | HttpRequestInfo request; |
| 7229 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7230 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7231 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
| 7232 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7233 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7234 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7235 | |
| 7236 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7237 | MockWrite( |
| 7238 | "GET / HTTP/1.1\r\n" |
| 7239 | "Host: www.example.org\r\n" |
| 7240 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7241 | }; |
| 7242 | |
| 7243 | MockRead data_reads1[] = { |
| 7244 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7245 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7246 | MockRead("Content-Length: 10\r\n\r\n"), |
| 7247 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 7248 | }; |
| 7249 | |
| 7250 | // After the challenge above, the transaction will be restarted using the |
| 7251 | // identity supplied by the user, not the one in the URL, to answer the |
| 7252 | // challenge. |
| 7253 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7254 | MockWrite( |
| 7255 | "GET / HTTP/1.1\r\n" |
| 7256 | "Host: www.example.org\r\n" |
| 7257 | "Connection: keep-alive\r\n" |
| 7258 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7259 | }; |
| 7260 | |
| 7261 | MockRead data_reads3[] = { |
| 7262 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7263 | MockRead("Content-Length: 100\r\n\r\n"), |
| 7264 | MockRead(SYNCHRONOUS, OK), |
| 7265 | }; |
| 7266 | |
| 7267 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7268 | data_writes1, arraysize(data_writes1)); |
| 7269 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 7270 | data_writes3, arraysize(data_writes3)); |
| 7271 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7272 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 7273 | |
| 7274 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7275 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7276 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7277 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7278 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7279 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7280 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7281 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7282 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7283 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 7284 | |
| 7285 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7286 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7287 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7288 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7289 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7290 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7291 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7292 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7293 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7294 | |
| 7295 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7296 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7297 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7298 | |
| 7299 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7300 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7301 | } |
| 7302 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7303 | // Test that previously tried username/passwords for a realm get re-used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7304 | TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7305 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7306 | |
| 7307 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 7308 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7309 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7310 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7311 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7312 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7313 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7314 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7315 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7316 | MockWrite( |
| 7317 | "GET /x/y/z HTTP/1.1\r\n" |
| 7318 | "Host: www.example.org\r\n" |
| 7319 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7320 | }; |
| 7321 | |
| 7322 | MockRead data_reads1[] = { |
| 7323 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7324 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7325 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7326 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7327 | }; |
| 7328 | |
| 7329 | // Resend with authorization (username=foo, password=bar) |
| 7330 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7331 | MockWrite( |
| 7332 | "GET /x/y/z HTTP/1.1\r\n" |
| 7333 | "Host: www.example.org\r\n" |
| 7334 | "Connection: keep-alive\r\n" |
| 7335 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7336 | }; |
| 7337 | |
| 7338 | // Sever accepts the authorization. |
| 7339 | MockRead data_reads2[] = { |
| 7340 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7341 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7342 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7343 | }; |
| 7344 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7345 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7346 | data_writes1, arraysize(data_writes1)); |
| 7347 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7348 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7349 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7350 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7351 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7352 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7353 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7354 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7355 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7356 | |
| 7357 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7358 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7359 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7360 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7361 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7362 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7363 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7364 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7365 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7366 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 7367 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7368 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7369 | |
| 7370 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7371 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7372 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7373 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7374 | ASSERT_TRUE(response); |
| 7375 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7376 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7377 | } |
| 7378 | |
| 7379 | // ------------------------------------------------------------------------ |
| 7380 | |
| 7381 | // Transaction 2: authenticate (foo2, bar2) on MyRealm2 |
| 7382 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7383 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7384 | request.method = "GET"; |
| 7385 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 7386 | // protection space as MyRealm1. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7387 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7388 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7389 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7390 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7391 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7392 | MockWrite( |
| 7393 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 7394 | "Host: www.example.org\r\n" |
| 7395 | "Connection: keep-alive\r\n" |
| 7396 | // Send preemptive authorization for MyRealm1 |
| 7397 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7398 | }; |
| 7399 | |
| 7400 | // The server didn't like the preemptive authorization, and |
| 7401 | // challenges us for a different realm (MyRealm2). |
| 7402 | MockRead data_reads1[] = { |
| 7403 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7404 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 7405 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7406 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7407 | }; |
| 7408 | |
| 7409 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 7410 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7411 | MockWrite( |
| 7412 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 7413 | "Host: www.example.org\r\n" |
| 7414 | "Connection: keep-alive\r\n" |
| 7415 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7416 | }; |
| 7417 | |
| 7418 | // Sever accepts the authorization. |
| 7419 | MockRead data_reads2[] = { |
| 7420 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7421 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7422 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7423 | }; |
| 7424 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7425 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7426 | data_writes1, arraysize(data_writes1)); |
| 7427 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7428 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7429 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7430 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7431 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7432 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7433 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7434 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7435 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7436 | |
| 7437 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7438 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7439 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7440 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7441 | ASSERT_TRUE(response); |
| 7442 | ASSERT_TRUE(response->auth_challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7443 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 7444 | EXPECT_EQ("http://www.example.org", |
| 7445 | response->auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7446 | EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 7447 | EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7448 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7449 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7450 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7451 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 7452 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7453 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7454 | |
| 7455 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7456 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7457 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7458 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7459 | ASSERT_TRUE(response); |
| 7460 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7461 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7462 | } |
| 7463 | |
| 7464 | // ------------------------------------------------------------------------ |
| 7465 | |
| 7466 | // Transaction 3: Resend a request in MyRealm's protection space -- |
| 7467 | // succeed with preemptive authorization. |
| 7468 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7469 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7470 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7471 | request.url = GURL("http://www.example.org/x/y/z2"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7472 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7473 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7474 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7475 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7476 | MockWrite( |
| 7477 | "GET /x/y/z2 HTTP/1.1\r\n" |
| 7478 | "Host: www.example.org\r\n" |
| 7479 | "Connection: keep-alive\r\n" |
| 7480 | // The authorization for MyRealm1 gets sent preemptively |
| 7481 | // (since the url is in the same protection space) |
| 7482 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7483 | }; |
| 7484 | |
| 7485 | // Sever accepts the preemptive authorization |
| 7486 | MockRead data_reads1[] = { |
| 7487 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7488 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7489 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7490 | }; |
| 7491 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7492 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7493 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7494 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7495 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7496 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7497 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7498 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7499 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7500 | |
| 7501 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7502 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7503 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7504 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7505 | ASSERT_TRUE(response); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7506 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7507 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7508 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7509 | } |
| 7510 | |
| 7511 | // ------------------------------------------------------------------------ |
| 7512 | |
| 7513 | // Transaction 4: request another URL in MyRealm (however the |
| 7514 | // url is not known to belong to the protection space, so no pre-auth). |
| 7515 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7516 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7517 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7518 | request.url = GURL("http://www.example.org/x/1"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7519 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7520 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7521 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7522 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7523 | MockWrite( |
| 7524 | "GET /x/1 HTTP/1.1\r\n" |
| 7525 | "Host: www.example.org\r\n" |
| 7526 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7527 | }; |
| 7528 | |
| 7529 | MockRead data_reads1[] = { |
| 7530 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7531 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7532 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7533 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7534 | }; |
| 7535 | |
| 7536 | // Resend with authorization from MyRealm's cache. |
| 7537 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7538 | MockWrite( |
| 7539 | "GET /x/1 HTTP/1.1\r\n" |
| 7540 | "Host: www.example.org\r\n" |
| 7541 | "Connection: keep-alive\r\n" |
| 7542 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7543 | }; |
| 7544 | |
| 7545 | // Sever accepts the authorization. |
| 7546 | MockRead data_reads2[] = { |
| 7547 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7548 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7549 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7550 | }; |
| 7551 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7552 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7553 | data_writes1, arraysize(data_writes1)); |
| 7554 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7555 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7556 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7557 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7558 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7559 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7560 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7561 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7562 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7563 | |
| 7564 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7565 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7566 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7567 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7568 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7569 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7570 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7571 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7572 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7573 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7574 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7575 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7576 | ASSERT_TRUE(response); |
| 7577 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7578 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7579 | } |
| 7580 | |
| 7581 | // ------------------------------------------------------------------------ |
| 7582 | |
| 7583 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 7584 | // cached identity. Should invalidate and re-prompt. |
| 7585 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7586 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7587 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7588 | request.url = GURL("http://www.example.org/p/q/t"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7589 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7590 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7591 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7592 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7593 | MockWrite( |
| 7594 | "GET /p/q/t HTTP/1.1\r\n" |
| 7595 | "Host: www.example.org\r\n" |
| 7596 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7597 | }; |
| 7598 | |
| 7599 | MockRead data_reads1[] = { |
| 7600 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7601 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7602 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7603 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7604 | }; |
| 7605 | |
| 7606 | // Resend with authorization from cache for MyRealm. |
| 7607 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7608 | MockWrite( |
| 7609 | "GET /p/q/t HTTP/1.1\r\n" |
| 7610 | "Host: www.example.org\r\n" |
| 7611 | "Connection: keep-alive\r\n" |
| 7612 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7613 | }; |
| 7614 | |
| 7615 | // Sever rejects the authorization. |
| 7616 | MockRead data_reads2[] = { |
| 7617 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7618 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7619 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7620 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7621 | }; |
| 7622 | |
| 7623 | // At this point we should prompt for new credentials for MyRealm. |
| 7624 | // Restart with username=foo3, password=foo4. |
| 7625 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7626 | MockWrite( |
| 7627 | "GET /p/q/t HTTP/1.1\r\n" |
| 7628 | "Host: www.example.org\r\n" |
| 7629 | "Connection: keep-alive\r\n" |
| 7630 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7631 | }; |
| 7632 | |
| 7633 | // Sever accepts the authorization. |
| 7634 | MockRead data_reads3[] = { |
| 7635 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7636 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7637 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7638 | }; |
| 7639 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7640 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7641 | data_writes1, arraysize(data_writes1)); |
| 7642 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7643 | data_writes2, arraysize(data_writes2)); |
| 7644 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 7645 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7646 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7647 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7648 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7649 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7650 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7651 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7652 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7653 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7654 | |
| 7655 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7656 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7657 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7658 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7659 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7660 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7661 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7662 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7663 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7664 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7665 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7666 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7667 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7668 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7669 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7670 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7671 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7672 | rv = trans.RestartWithAuth(AuthCredentials(kFoo3, kBar3), |
| 7673 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7674 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7675 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7676 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7677 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7678 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7679 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7680 | ASSERT_TRUE(response); |
| 7681 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7682 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7683 | } |
| 7684 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7685 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7686 | // Tests that nonce count increments when multiple auth attempts |
| 7687 | // are started with the same nonce. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7688 | TEST_F(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { |
[email protected] | 54fea256 | 2010-11-17 14:40:44 | [diff] [blame] | 7689 | HttpAuthHandlerDigest::Factory* digest_factory = |
| 7690 | new HttpAuthHandlerDigest::Factory(); |
| 7691 | HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = |
| 7692 | new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); |
| 7693 | digest_factory->set_nonce_generator(nonce_generator); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7694 | session_deps_.http_auth_handler_factory.reset(digest_factory); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7695 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7696 | |
| 7697 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 7698 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7699 | HttpRequestInfo request; |
| 7700 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7701 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7702 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7703 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7704 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7705 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7706 | MockWrite( |
| 7707 | "GET /x/y/z HTTP/1.1\r\n" |
| 7708 | "Host: www.example.org\r\n" |
| 7709 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7710 | }; |
| 7711 | |
| 7712 | MockRead data_reads1[] = { |
| 7713 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7714 | MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " |
| 7715 | "algorithm=MD5, qop=\"auth\"\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7716 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7717 | }; |
| 7718 | |
| 7719 | // Resend with authorization (username=foo, password=bar) |
| 7720 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7721 | MockWrite( |
| 7722 | "GET /x/y/z HTTP/1.1\r\n" |
| 7723 | "Host: www.example.org\r\n" |
| 7724 | "Connection: keep-alive\r\n" |
| 7725 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 7726 | "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " |
| 7727 | "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " |
| 7728 | "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7729 | }; |
| 7730 | |
| 7731 | // Sever accepts the authorization. |
| 7732 | MockRead data_reads2[] = { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 7733 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7734 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7735 | }; |
| 7736 | |
| 7737 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7738 | data_writes1, arraysize(data_writes1)); |
| 7739 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7740 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7741 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7742 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7743 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7744 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7745 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7746 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7747 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7748 | |
| 7749 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7750 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7751 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7752 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7753 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7754 | EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge.get())); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7755 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7756 | TestCompletionCallback callback2; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7757 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7758 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 7759 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7760 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7761 | |
| 7762 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7763 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7764 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7765 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7766 | ASSERT_TRUE(response); |
| 7767 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7768 | } |
| 7769 | |
| 7770 | // ------------------------------------------------------------------------ |
| 7771 | |
| 7772 | // Transaction 2: Request another resource in digestive's protection space. |
| 7773 | // This will preemptively add an Authorization header which should have an |
| 7774 | // "nc" value of 2 (as compared to 1 in the first use. |
| 7775 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7776 | HttpRequestInfo request; |
| 7777 | request.method = "GET"; |
| 7778 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 7779 | // protection space as digest. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7780 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7781 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7782 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7783 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7784 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7785 | MockWrite( |
| 7786 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 7787 | "Host: www.example.org\r\n" |
| 7788 | "Connection: keep-alive\r\n" |
| 7789 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 7790 | "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " |
| 7791 | "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " |
| 7792 | "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7793 | }; |
| 7794 | |
| 7795 | // Sever accepts the authorization. |
| 7796 | MockRead data_reads1[] = { |
| 7797 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7798 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7799 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7800 | }; |
| 7801 | |
| 7802 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7803 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7804 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7805 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7806 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7807 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7808 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7809 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7810 | |
| 7811 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7812 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7813 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7814 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7815 | ASSERT_TRUE(response); |
| 7816 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7817 | } |
| 7818 | } |
| 7819 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7820 | // Test the ResetStateForRestart() private method. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7821 | TEST_F(HttpNetworkTransactionTest, ResetStateForRestart) { |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7822 | // Create a transaction (the dependencies aren't important). |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7823 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7824 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7825 | |
| 7826 | // Setup some state (which we expect ResetStateForRestart() will clear). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7827 | trans.read_buf_ = new IOBuffer(15); |
| 7828 | trans.read_buf_len_ = 15; |
| 7829 | trans.request_headers_.SetHeader("Authorization", "NTLM"); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7830 | |
| 7831 | // Setup state in response_ |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7832 | HttpResponseInfo* response = &trans.response_; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7833 | response->auth_challenge = new AuthChallengeInfo(); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 7834 | response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7835 | response->response_time = base::Time::Now(); |
| 7836 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7837 | |
| 7838 | { // Setup state for response_.vary_data |
| 7839 | HttpRequestInfo request; |
| 7840 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 7841 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 7842 | scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 7843 | request.extra_headers.SetHeader("Foo", "1"); |
| 7844 | request.extra_headers.SetHeader("bar", "23"); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7845 | EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7846 | } |
| 7847 | |
| 7848 | // Cause the above state to be reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7849 | trans.ResetStateForRestart(); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7850 | |
| 7851 | // Verify that the state that needed to be reset, has been reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7852 | EXPECT_FALSE(trans.read_buf_); |
| 7853 | EXPECT_EQ(0, trans.read_buf_len_); |
| 7854 | EXPECT_TRUE(trans.request_headers_.IsEmpty()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7855 | EXPECT_FALSE(response->auth_challenge); |
| 7856 | EXPECT_FALSE(response->headers); |
[email protected] | 34f4094 | 2010-10-04 00:34:04 | [diff] [blame] | 7857 | EXPECT_FALSE(response->was_cached); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 7858 | EXPECT_EQ(0U, response->ssl_info.cert_status); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7859 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7860 | } |
| 7861 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7862 | // Test HTTPS connections to a site with a bad certificate |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7863 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7864 | HttpRequestInfo request; |
| 7865 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7866 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7867 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7868 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7869 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7870 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7871 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7872 | MockWrite( |
| 7873 | "GET / HTTP/1.1\r\n" |
| 7874 | "Host: www.example.org\r\n" |
| 7875 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7876 | }; |
| 7877 | |
| 7878 | MockRead data_reads[] = { |
| 7879 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7880 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7881 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7882 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7883 | }; |
| 7884 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 7885 | StaticSocketDataProvider ssl_bad_certificate; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7886 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7887 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7888 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 7889 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7890 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7891 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 7892 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7893 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 7894 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7895 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7896 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7897 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7898 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7899 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7900 | |
| 7901 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7902 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7903 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7904 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7905 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7906 | |
| 7907 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7908 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7909 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7910 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7911 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7912 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7913 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7914 | } |
| 7915 | |
| 7916 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 7917 | // proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7918 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7919 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7920 | |
| 7921 | HttpRequestInfo request; |
| 7922 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7923 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7924 | |
| 7925 | MockWrite proxy_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7926 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7927 | "Host: www.example.org:443\r\n" |
| 7928 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7929 | }; |
| 7930 | |
| 7931 | MockRead proxy_reads[] = { |
| 7932 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7933 | MockRead(SYNCHRONOUS, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7934 | }; |
| 7935 | |
| 7936 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7937 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7938 | "Host: www.example.org:443\r\n" |
| 7939 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7940 | MockWrite("GET / HTTP/1.1\r\n" |
| 7941 | "Host: www.example.org\r\n" |
| 7942 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7943 | }; |
| 7944 | |
| 7945 | MockRead data_reads[] = { |
| 7946 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 7947 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7948 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7949 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7950 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7951 | }; |
| 7952 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7953 | StaticSocketDataProvider ssl_bad_certificate( |
| 7954 | proxy_reads, arraysize(proxy_reads), |
| 7955 | proxy_writes, arraysize(proxy_writes)); |
| 7956 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7957 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7958 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 7959 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7960 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7961 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 7962 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7963 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 7964 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7965 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7966 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7967 | |
| 7968 | for (int i = 0; i < 2; i++) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7969 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7970 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7971 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7972 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7973 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7974 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7975 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7976 | |
| 7977 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7978 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7979 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7980 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7981 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7982 | |
| 7983 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7984 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7985 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7986 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7987 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7988 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7989 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7990 | } |
| 7991 | } |
| 7992 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7993 | |
| 7994 | // Test HTTPS connections to a site, going through an HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7995 | TEST_F(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7996 | session_deps_.proxy_service = |
| 7997 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7998 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7999 | session_deps_.net_log = &net_log; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8000 | |
| 8001 | HttpRequestInfo request; |
| 8002 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8003 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8004 | |
| 8005 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8006 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8007 | "Host: www.example.org:443\r\n" |
| 8008 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 8009 | MockWrite("GET / HTTP/1.1\r\n" |
| 8010 | "Host: www.example.org\r\n" |
| 8011 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8012 | }; |
| 8013 | |
| 8014 | MockRead data_reads[] = { |
| 8015 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 8016 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 8017 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8018 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8019 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8020 | }; |
| 8021 | |
| 8022 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8023 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8024 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 8025 | SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8026 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8027 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8028 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 8029 | session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8030 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8031 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8032 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8033 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8034 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8035 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8036 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8037 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8038 | |
| 8039 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8040 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8041 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8042 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8043 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8044 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 8045 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8046 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8047 | EXPECT_EQ(200, response->headers->response_code()); |
| 8048 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8049 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8050 | |
| 8051 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8052 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8053 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8054 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8055 | } |
| 8056 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8057 | // Test an HTTPS Proxy's ability to redirect a CONNECT request |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8058 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8059 | session_deps_.proxy_service = |
| 8060 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8061 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8062 | session_deps_.net_log = &net_log; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8063 | |
| 8064 | HttpRequestInfo request; |
| 8065 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8066 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8067 | |
| 8068 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8069 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8070 | "Host: www.example.org:443\r\n" |
| 8071 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8072 | }; |
| 8073 | |
| 8074 | MockRead data_reads[] = { |
| 8075 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 8076 | MockRead("Location: http://login.example.com/\r\n"), |
| 8077 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8078 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8079 | }; |
| 8080 | |
| 8081 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8082 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8083 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8084 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8085 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8086 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8087 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8088 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8089 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8090 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8091 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8092 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8093 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8094 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8095 | |
| 8096 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8097 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8098 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8099 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8100 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8101 | |
| 8102 | EXPECT_EQ(302, response->headers->response_code()); |
| 8103 | std::string url; |
| 8104 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 8105 | EXPECT_EQ("http://login.example.com/", url); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8106 | |
| 8107 | // In the case of redirects from proxies, HttpNetworkTransaction returns |
| 8108 | // timing for the proxy connection instead of the connection to the host, |
| 8109 | // and no send / receive times. |
| 8110 | // See HttpNetworkTransaction::OnHttpsProxyTunnelResponse. |
| 8111 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8112 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8113 | |
| 8114 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 8115 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8116 | |
| 8117 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 8118 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 8119 | load_timing_info.proxy_resolve_end); |
| 8120 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 8121 | load_timing_info.connect_timing.connect_start); |
| 8122 | ExpectConnectTimingHasTimes( |
| 8123 | load_timing_info.connect_timing, |
| 8124 | CONNECT_TIMING_HAS_DNS_TIMES | CONNECT_TIMING_HAS_SSL_TIMES); |
| 8125 | |
| 8126 | EXPECT_TRUE(load_timing_info.send_start.is_null()); |
| 8127 | EXPECT_TRUE(load_timing_info.send_end.is_null()); |
| 8128 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8129 | } |
| 8130 | |
| 8131 | // Test an HTTPS (SPDY) Proxy's ability to redirect a CONNECT request |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8132 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8133 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8134 | |
| 8135 | HttpRequestInfo request; |
| 8136 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8137 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8138 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8139 | SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8140 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8141 | SpdySerializedFrame goaway( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 8142 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8143 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8144 | CreateMockWrite(conn, 0, SYNCHRONOUS), |
| 8145 | CreateMockWrite(goaway, 2, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8146 | }; |
| 8147 | |
| 8148 | static const char* const kExtraHeaders[] = { |
| 8149 | "location", |
| 8150 | "http://login.example.com/", |
| 8151 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8152 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
bnc | c9f762a | 2016-12-06 20:38:23 | [diff] [blame] | 8153 | "302", kExtraHeaders, arraysize(kExtraHeaders) / 2, 1)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8154 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8155 | CreateMockRead(resp, 1), MockRead(ASYNC, 0, 3), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8156 | }; |
| 8157 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8158 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 8159 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8160 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8161 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8162 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8163 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8164 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8165 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8166 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8167 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8168 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8169 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8170 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8171 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8172 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8173 | |
| 8174 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8175 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8176 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8177 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8178 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8179 | |
| 8180 | EXPECT_EQ(302, response->headers->response_code()); |
| 8181 | std::string url; |
| 8182 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 8183 | EXPECT_EQ("http://login.example.com/", url); |
| 8184 | } |
| 8185 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 8186 | // Test that an HTTPS proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8187 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8188 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8189 | |
| 8190 | HttpRequestInfo request; |
| 8191 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8192 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8193 | |
| 8194 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8195 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8196 | "Host: www.example.org:443\r\n" |
| 8197 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8198 | }; |
| 8199 | |
| 8200 | MockRead data_reads[] = { |
| 8201 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 8202 | MockRead("Content-Length: 23\r\n\r\n"), |
| 8203 | MockRead("The host does not exist"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8204 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8205 | }; |
| 8206 | |
| 8207 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8208 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8209 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8210 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8211 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8212 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8213 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8214 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8215 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8216 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8217 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8218 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8219 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8220 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8221 | |
| 8222 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8223 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8224 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 8225 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8226 | } |
| 8227 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 8228 | // Test that a SPDY proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8229 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaSpdyProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8230 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8231 | |
| 8232 | HttpRequestInfo request; |
| 8233 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8234 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8235 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8236 | SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8237 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8238 | SpdySerializedFrame rst( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 8239 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8240 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8241 | CreateMockWrite(conn, 0), CreateMockWrite(rst, 3), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8242 | }; |
| 8243 | |
| 8244 | static const char* const kExtraHeaders[] = { |
| 8245 | "location", |
| 8246 | "http://login.example.com/", |
| 8247 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8248 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
bnc | c9f762a | 2016-12-06 20:38:23 | [diff] [blame] | 8249 | "404", kExtraHeaders, arraysize(kExtraHeaders) / 2, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8250 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 8251 | 1, "The host does not exist", 23, true)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8252 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8253 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8254 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8255 | }; |
| 8256 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8257 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 8258 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8259 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8260 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8261 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8262 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8263 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8264 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8265 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8266 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8267 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8268 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8269 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8270 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8271 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8272 | |
| 8273 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8274 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8275 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 8276 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8277 | } |
| 8278 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8279 | // Test the request-challenge-retry sequence for basic auth, through |
| 8280 | // a SPDY proxy over a single SPDY session. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8281 | TEST_F(HttpNetworkTransactionTest, BasicAuthSpdyProxy) { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8282 | HttpRequestInfo request; |
| 8283 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8284 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8285 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 8286 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8287 | |
| 8288 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8289 | session_deps_.proxy_service = |
| 8290 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8291 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8292 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8293 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8294 | |
| 8295 | // Since we have proxy, should try to establish tunnel. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8296 | SpdySerializedFrame req(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8297 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8298 | SpdySerializedFrame rst( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 8299 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 8300 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8301 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8302 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8303 | // be issuing -- the final header line contains the credentials. |
| 8304 | const char* const kAuthCredentials[] = { |
| 8305 | "proxy-authorization", "Basic Zm9vOmJhcg==", |
| 8306 | }; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8307 | SpdySerializedFrame connect2(spdy_util_.ConstructSpdyConnect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 8308 | kAuthCredentials, arraysize(kAuthCredentials) / 2, 3, LOWEST, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8309 | HostPortPair("www.example.org", 443))); |
| 8310 | // fetch https://www.example.org/ via HTTP |
| 8311 | const char get[] = |
| 8312 | "GET / HTTP/1.1\r\n" |
| 8313 | "Host: www.example.org\r\n" |
| 8314 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8315 | SpdySerializedFrame wrapped_get( |
| 8316 | spdy_util_.ConstructSpdyDataFrame(3, get, strlen(get), false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8317 | |
| 8318 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8319 | CreateMockWrite(req, 0, ASYNC), CreateMockWrite(rst, 2, ASYNC), |
| 8320 | CreateMockWrite(connect2, 3), CreateMockWrite(wrapped_get, 5), |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8321 | }; |
| 8322 | |
| 8323 | // The proxy responds to the connect with a 407, using a persistent |
| 8324 | // connection. |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 8325 | const char kAuthStatus[] = "407"; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8326 | const char* const kAuthChallenge[] = { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8327 | "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 8328 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8329 | SpdySerializedFrame conn_auth_resp(spdy_util_.ConstructSpdyReplyError( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8330 | kAuthStatus, kAuthChallenge, arraysize(kAuthChallenge) / 2, 1)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8331 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8332 | SpdySerializedFrame conn_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8333 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 8334 | "Content-Length: 5\r\n\r\n"; |
| 8335 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8336 | SpdySerializedFrame wrapped_get_resp( |
| 8337 | spdy_util_.ConstructSpdyDataFrame(3, resp, strlen(resp), false)); |
| 8338 | SpdySerializedFrame wrapped_body( |
| 8339 | spdy_util_.ConstructSpdyDataFrame(3, "hello", 5, false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8340 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8341 | CreateMockRead(conn_auth_resp, 1, ASYNC), |
| 8342 | CreateMockRead(conn_resp, 4, ASYNC), |
| 8343 | CreateMockRead(wrapped_get_resp, 6, ASYNC), |
| 8344 | CreateMockRead(wrapped_body, 7, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8345 | MockRead(ASYNC, OK, 8), // EOF. May or may not be read. |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8346 | }; |
| 8347 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8348 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8349 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8350 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8351 | // Negotiate SPDY to the proxy |
| 8352 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8353 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8354 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8355 | // Vanilla SSL to the server |
| 8356 | SSLSocketDataProvider server(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8357 | session_deps_.socket_factory->AddSSLSocketDataProvider(&server); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8358 | |
| 8359 | TestCompletionCallback callback1; |
| 8360 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8361 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8362 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8363 | |
| 8364 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8365 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8366 | |
| 8367 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8368 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 8369 | TestNetLogEntry::List entries; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8370 | log.GetEntries(&entries); |
| 8371 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 8372 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 8373 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8374 | ExpectLogContainsSomewhere( |
| 8375 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 8376 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 8377 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8378 | |
| 8379 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8380 | ASSERT_TRUE(response); |
| 8381 | ASSERT_TRUE(response->headers); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8382 | EXPECT_EQ(407, response->headers->response_code()); |
| 8383 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8384 | EXPECT_TRUE(response->auth_challenge); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 8385 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8386 | |
| 8387 | TestCompletionCallback callback2; |
| 8388 | |
| 8389 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 8390 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8391 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8392 | |
| 8393 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8394 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8395 | |
| 8396 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8397 | ASSERT_TRUE(response); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8398 | |
| 8399 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8400 | EXPECT_EQ(200, response->headers->response_code()); |
| 8401 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 8402 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8403 | |
| 8404 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8405 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8406 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8407 | LoadTimingInfo load_timing_info; |
| 8408 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8409 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8410 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 8411 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8412 | trans.reset(); |
| 8413 | session->CloseAllConnections(); |
| 8414 | } |
| 8415 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8416 | // Test that an explicitly trusted SPDY proxy can push a resource from an |
| 8417 | // origin that is different from that of its associated resource. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8418 | TEST_F(HttpNetworkTransactionTest, CrossOriginSPDYProxyPush) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8419 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8420 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8421 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 8422 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8423 | HttpRequestInfo request; |
| 8424 | HttpRequestInfo push_request; |
| 8425 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8426 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8427 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8428 | push_request.method = "GET"; |
| 8429 | push_request.url = GURL("http://www.another-origin.com/foo.dat"); |
| 8430 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8431 | // Configure against https proxy server "myproxy:443". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8432 | session_deps_.proxy_service = |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8433 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:443"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8434 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8435 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8436 | |
inlinechan | 894515af | 2016-12-09 02:40:10 | [diff] [blame] | 8437 | session_deps_.proxy_delegate = std::move(proxy_delegate); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8438 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8439 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8440 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8441 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 8442 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8443 | SpdySerializedFrame stream2_priority( |
| 8444 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8445 | |
| 8446 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8447 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8448 | CreateMockWrite(stream2_priority, 3, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8449 | }; |
| 8450 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8451 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8452 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8453 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8454 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8455 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8456 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 8457 | NULL, 0, 2, 1, "http://www.another-origin.com/foo.dat")); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8458 | const char kPushedData[] = "pushed"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8459 | SpdySerializedFrame stream2_body(spdy_util_.ConstructSpdyDataFrame( |
| 8460 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8461 | |
| 8462 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8463 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 8464 | CreateMockRead(stream2_syn, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8465 | CreateMockRead(stream1_body, 4, ASYNC), |
| 8466 | CreateMockRead(stream2_body, 5, ASYNC), |
| 8467 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8468 | }; |
| 8469 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8470 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8471 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8472 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8473 | // Negotiate SPDY to the proxy |
| 8474 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8475 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8476 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8477 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8478 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8479 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8480 | TestCompletionCallback callback; |
| 8481 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8482 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8483 | |
| 8484 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8485 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8486 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8487 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8488 | auto push_trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8489 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8490 | rv = push_trans->Start(&push_request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8491 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8492 | |
| 8493 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8494 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8495 | const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); |
| 8496 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8497 | ASSERT_TRUE(response); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8498 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8499 | |
| 8500 | EXPECT_EQ(200, response->headers->response_code()); |
| 8501 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8502 | |
| 8503 | std::string response_data; |
| 8504 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8505 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8506 | EXPECT_EQ("hello!", response_data); |
| 8507 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8508 | LoadTimingInfo load_timing_info; |
| 8509 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8510 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8511 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 8512 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8513 | // Verify the pushed stream. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8514 | EXPECT_TRUE(push_response->headers); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8515 | EXPECT_EQ(200, push_response->headers->response_code()); |
| 8516 | |
| 8517 | rv = ReadTransaction(push_trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8518 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8519 | EXPECT_EQ("pushed", response_data); |
| 8520 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8521 | LoadTimingInfo push_load_timing_info; |
| 8522 | EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); |
| 8523 | TestLoadTimingReusedWithPac(push_load_timing_info); |
| 8524 | // The transactions should share a socket ID, despite being for different |
| 8525 | // origins. |
| 8526 | EXPECT_EQ(load_timing_info.socket_log_id, |
| 8527 | push_load_timing_info.socket_log_id); |
| 8528 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8529 | trans.reset(); |
| 8530 | push_trans.reset(); |
| 8531 | session->CloseAllConnections(); |
| 8532 | } |
| 8533 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8534 | // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8535 | TEST_F(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8536 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8537 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8538 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 8539 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8540 | HttpRequestInfo request; |
| 8541 | |
| 8542 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8543 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8544 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8545 | session_deps_.proxy_service = |
| 8546 | ProxyService::CreateFixed("https://myproxy:443"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8547 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8548 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8549 | |
| 8550 | // Enable cross-origin push. |
inlinechan | 894515af | 2016-12-09 02:40:10 | [diff] [blame] | 8551 | session_deps_.proxy_delegate = std::move(proxy_delegate); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8552 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8553 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8554 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8555 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 8556 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8557 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8558 | SpdySerializedFrame push_rst( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 8559 | spdy_util_.ConstructSpdyRstStream(2, ERROR_CODE_REFUSED_STREAM)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8560 | |
| 8561 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8562 | CreateMockWrite(stream1_syn, 0, ASYNC), CreateMockWrite(push_rst, 3), |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8563 | }; |
| 8564 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8565 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8566 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8567 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8568 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8569 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8570 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 8571 | NULL, 0, 2, 1, "https://www.another-origin.com/foo.dat")); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8572 | |
| 8573 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8574 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 8575 | CreateMockRead(stream2_syn, 2, ASYNC), |
| 8576 | CreateMockRead(stream1_body, 4, ASYNC), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 8577 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a hang |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8578 | }; |
| 8579 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8580 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8581 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8582 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8583 | // Negotiate SPDY to the proxy |
| 8584 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8585 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8586 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8587 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8588 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8589 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8590 | TestCompletionCallback callback; |
| 8591 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8592 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8593 | |
| 8594 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8595 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8596 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8597 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8598 | ASSERT_TRUE(response); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8599 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8600 | |
| 8601 | EXPECT_EQ(200, response->headers->response_code()); |
| 8602 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8603 | |
| 8604 | std::string response_data; |
| 8605 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8606 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8607 | EXPECT_EQ("hello!", response_data); |
| 8608 | |
| 8609 | trans.reset(); |
| 8610 | session->CloseAllConnections(); |
| 8611 | } |
| 8612 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8613 | // Test that an explicitly trusted SPDY proxy can push same-origin HTTPS |
| 8614 | // resources. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8615 | TEST_F(HttpNetworkTransactionTest, SameOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8616 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8617 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8618 | proxy_delegate->set_trusted_spdy_proxy( |
| 8619 | net::ProxyServer::FromURI("myproxy:70", net::ProxyServer::SCHEME_HTTP)); |
| 8620 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8621 | HttpRequestInfo request; |
| 8622 | |
| 8623 | request.method = "GET"; |
| 8624 | request.url = GURL("http://www.example.org/"); |
| 8625 | |
| 8626 | // Configure against https proxy server "myproxy:70". |
| 8627 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
| 8628 | BoundTestNetLog log; |
| 8629 | session_deps_.net_log = log.bound().net_log(); |
| 8630 | |
| 8631 | // Enable cross-origin push. |
inlinechan | 894515af | 2016-12-09 02:40:10 | [diff] [blame] | 8632 | session_deps_.proxy_delegate = std::move(proxy_delegate); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8633 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8634 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8635 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8636 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 8637 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8638 | SpdySerializedFrame stream2_priority( |
| 8639 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8640 | |
| 8641 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8642 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8643 | CreateMockWrite(stream2_priority, 3, ASYNC), |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8644 | }; |
| 8645 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8646 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8647 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8648 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8649 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
Bence Béky | 096cf05 | 2017-08-08 23:55:33 | [diff] [blame] | 8650 | nullptr, 0, 2, 1, "http://www.example.org/foo.dat")); |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 8651 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8652 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8653 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8654 | SpdySerializedFrame stream2_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8655 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8656 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8657 | SpdySerializedFrame stream2_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8658 | |
| 8659 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8660 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 8661 | CreateMockRead(stream2_syn, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8662 | CreateMockRead(stream1_body, 4, ASYNC), |
| 8663 | CreateMockRead(stream2_body, 5, ASYNC), |
| 8664 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8665 | }; |
| 8666 | |
| 8667 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8668 | arraysize(spdy_writes)); |
| 8669 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 8670 | // Negotiate SPDY to the proxy |
| 8671 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8672 | proxy.next_proto = kProtoHTTP2; |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8673 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
| 8674 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8675 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8676 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8677 | TestCompletionCallback callback; |
| 8678 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8679 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8680 | |
| 8681 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8682 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8683 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8684 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8685 | ASSERT_TRUE(response); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8686 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8687 | |
| 8688 | EXPECT_EQ(200, response->headers->response_code()); |
| 8689 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8690 | |
| 8691 | std::string response_data; |
| 8692 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8693 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8694 | EXPECT_EQ("hello!", response_data); |
| 8695 | |
| 8696 | trans.reset(); |
| 8697 | session->CloseAllConnections(); |
| 8698 | } |
| 8699 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8700 | // Test HTTPS connections to a site with a bad certificate, going through an |
| 8701 | // HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8702 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8703 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8704 | |
| 8705 | HttpRequestInfo request; |
| 8706 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8707 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8708 | |
| 8709 | // Attempt to fetch the URL from a server with a bad cert |
| 8710 | MockWrite bad_cert_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8711 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8712 | "Host: www.example.org:443\r\n" |
| 8713 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8714 | }; |
| 8715 | |
| 8716 | MockRead bad_cert_reads[] = { |
| 8717 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8718 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8719 | }; |
| 8720 | |
| 8721 | // Attempt to fetch the URL with a good cert |
| 8722 | MockWrite good_data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8723 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8724 | "Host: www.example.org:443\r\n" |
| 8725 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 8726 | MockWrite("GET / HTTP/1.1\r\n" |
| 8727 | "Host: www.example.org\r\n" |
| 8728 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8729 | }; |
| 8730 | |
| 8731 | MockRead good_cert_reads[] = { |
| 8732 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 8733 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8734 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8735 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8736 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8737 | }; |
| 8738 | |
| 8739 | StaticSocketDataProvider ssl_bad_certificate( |
| 8740 | bad_cert_reads, arraysize(bad_cert_reads), |
| 8741 | bad_cert_writes, arraysize(bad_cert_writes)); |
| 8742 | StaticSocketDataProvider data(good_cert_reads, arraysize(good_cert_reads), |
| 8743 | good_data_writes, arraysize(good_data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8744 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 8745 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8746 | |
| 8747 | // SSL to the proxy, then CONNECT request, then SSL with bad certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8748 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 8749 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 8750 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8751 | |
| 8752 | // SSL to the proxy, then CONNECT request, then valid SSL certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8753 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 8754 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8755 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8756 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8757 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8758 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8759 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8760 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8761 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8762 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8763 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8764 | |
| 8765 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8766 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8767 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8768 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8769 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8770 | |
| 8771 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8772 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8773 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8774 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8775 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8776 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8777 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8778 | } |
| 8779 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8780 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8781 | HttpRequestInfo request; |
| 8782 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8783 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8784 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 8785 | "Chromium Ultra Awesome X Edition"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8786 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8787 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8788 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8789 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8790 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8791 | MockWrite( |
| 8792 | "GET / HTTP/1.1\r\n" |
| 8793 | "Host: www.example.org\r\n" |
| 8794 | "Connection: keep-alive\r\n" |
| 8795 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8796 | }; |
| 8797 | |
| 8798 | // Lastly, the server responds with the actual content. |
| 8799 | MockRead data_reads[] = { |
| 8800 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8801 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8802 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8803 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8804 | }; |
| 8805 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8806 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8807 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8808 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8809 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8810 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8811 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8812 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8813 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8814 | |
| 8815 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8816 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8817 | } |
| 8818 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8819 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8820 | HttpRequestInfo request; |
| 8821 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8822 | request.url = GURL("https://www.example.org/"); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8823 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 8824 | "Chromium Ultra Awesome X Edition"); |
| 8825 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8826 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8827 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8828 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8829 | |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8830 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8831 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8832 | "Host: www.example.org:443\r\n" |
| 8833 | "Proxy-Connection: keep-alive\r\n" |
| 8834 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8835 | }; |
| 8836 | MockRead data_reads[] = { |
| 8837 | // Return an error, so the transaction stops here (this test isn't |
| 8838 | // interested in the rest). |
| 8839 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 8840 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8841 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 8842 | }; |
| 8843 | |
| 8844 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8845 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8846 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8847 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8848 | TestCompletionCallback callback; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8849 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8850 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8851 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8852 | |
| 8853 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8854 | EXPECT_THAT(rv, IsOk()); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8855 | } |
| 8856 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8857 | TEST_F(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8858 | HttpRequestInfo request; |
| 8859 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8860 | request.url = GURL("http://www.example.org/"); |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 8861 | request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 8862 | "http://the.previous.site.com/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8863 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8864 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8865 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8866 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8867 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8868 | MockWrite( |
| 8869 | "GET / HTTP/1.1\r\n" |
| 8870 | "Host: www.example.org\r\n" |
| 8871 | "Connection: keep-alive\r\n" |
| 8872 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8873 | }; |
| 8874 | |
| 8875 | // Lastly, the server responds with the actual content. |
| 8876 | MockRead data_reads[] = { |
| 8877 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8878 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8879 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8880 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8881 | }; |
| 8882 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8883 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8884 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8885 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8886 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8887 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8888 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8889 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8890 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8891 | |
| 8892 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8893 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8894 | } |
| 8895 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8896 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8897 | HttpRequestInfo request; |
| 8898 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8899 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8900 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8901 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8902 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8903 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8904 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8905 | MockWrite( |
| 8906 | "POST / HTTP/1.1\r\n" |
| 8907 | "Host: www.example.org\r\n" |
| 8908 | "Connection: keep-alive\r\n" |
| 8909 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8910 | }; |
| 8911 | |
| 8912 | // Lastly, the server responds with the actual content. |
| 8913 | MockRead data_reads[] = { |
| 8914 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8915 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8916 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8917 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8918 | }; |
| 8919 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8920 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8921 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8922 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8923 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8924 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8925 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8926 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8927 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8928 | |
| 8929 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8930 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8931 | } |
| 8932 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8933 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8934 | HttpRequestInfo request; |
| 8935 | request.method = "PUT"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8936 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8937 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8938 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8939 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8940 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8941 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8942 | MockWrite( |
| 8943 | "PUT / HTTP/1.1\r\n" |
| 8944 | "Host: www.example.org\r\n" |
| 8945 | "Connection: keep-alive\r\n" |
| 8946 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8947 | }; |
| 8948 | |
| 8949 | // Lastly, the server responds with the actual content. |
| 8950 | MockRead data_reads[] = { |
| 8951 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8952 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8953 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8954 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8955 | }; |
| 8956 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8957 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8958 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8959 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8960 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8961 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8962 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8963 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8964 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8965 | |
| 8966 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8967 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8968 | } |
| 8969 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8970 | TEST_F(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8971 | HttpRequestInfo request; |
| 8972 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8973 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8974 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8975 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8976 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8977 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8978 | MockWrite data_writes[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 8979 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 8980 | "Host: www.example.org\r\n" |
| 8981 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8982 | }; |
| 8983 | |
| 8984 | // Lastly, the server responds with the actual content. |
| 8985 | MockRead data_reads[] = { |
| 8986 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8987 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8988 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8989 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8990 | }; |
| 8991 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8992 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8993 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8994 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8995 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8996 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8997 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8998 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8999 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9000 | |
| 9001 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9002 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9003 | } |
| 9004 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9005 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9006 | HttpRequestInfo request; |
| 9007 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9008 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9009 | request.load_flags = LOAD_BYPASS_CACHE; |
| 9010 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9011 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9012 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9013 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9014 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9015 | MockWrite( |
| 9016 | "GET / HTTP/1.1\r\n" |
| 9017 | "Host: www.example.org\r\n" |
| 9018 | "Connection: keep-alive\r\n" |
| 9019 | "Pragma: no-cache\r\n" |
| 9020 | "Cache-Control: no-cache\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9021 | }; |
| 9022 | |
| 9023 | // Lastly, the server responds with the actual content. |
| 9024 | MockRead data_reads[] = { |
| 9025 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9026 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9027 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9028 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9029 | }; |
| 9030 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9031 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9032 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9033 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9034 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9035 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9036 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9037 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9038 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9039 | |
| 9040 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9041 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9042 | } |
| 9043 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9044 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlValidateCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9045 | HttpRequestInfo request; |
| 9046 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9047 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9048 | request.load_flags = LOAD_VALIDATE_CACHE; |
| 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] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9052 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9053 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9054 | MockWrite( |
| 9055 | "GET / HTTP/1.1\r\n" |
| 9056 | "Host: www.example.org\r\n" |
| 9057 | "Connection: keep-alive\r\n" |
| 9058 | "Cache-Control: max-age=0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9059 | }; |
| 9060 | |
| 9061 | // Lastly, the server responds with the actual content. |
| 9062 | MockRead data_reads[] = { |
| 9063 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9064 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9065 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9066 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9067 | }; |
| 9068 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9069 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9070 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9071 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9072 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9073 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9074 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9075 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9076 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9077 | |
| 9078 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9079 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9080 | } |
| 9081 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9082 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9083 | HttpRequestInfo request; |
| 9084 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9085 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 9086 | request.extra_headers.SetHeader("FooHeader", "Bar"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9087 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9088 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9089 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9090 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9091 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9092 | MockWrite( |
| 9093 | "GET / HTTP/1.1\r\n" |
| 9094 | "Host: www.example.org\r\n" |
| 9095 | "Connection: keep-alive\r\n" |
| 9096 | "FooHeader: Bar\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9097 | }; |
| 9098 | |
| 9099 | // Lastly, the server responds with the actual content. |
| 9100 | MockRead data_reads[] = { |
| 9101 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9102 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9103 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9104 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9105 | }; |
| 9106 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9107 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9108 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9109 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9110 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9111 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9112 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9113 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9114 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9115 | |
| 9116 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9117 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9118 | } |
| 9119 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9120 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9121 | HttpRequestInfo request; |
| 9122 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9123 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 9124 | request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 9125 | request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 9126 | request.extra_headers.SetHeader("FoO", "bar"); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9127 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9128 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9129 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9130 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9131 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9132 | MockWrite( |
| 9133 | "GET / HTTP/1.1\r\n" |
| 9134 | "Host: www.example.org\r\n" |
| 9135 | "Connection: keep-alive\r\n" |
| 9136 | "referer: www.foo.com\r\n" |
| 9137 | "hEllo: Kitty\r\n" |
| 9138 | "FoO: bar\r\n\r\n"), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9139 | }; |
| 9140 | |
| 9141 | // Lastly, the server responds with the actual content. |
| 9142 | MockRead data_reads[] = { |
| 9143 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9144 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9145 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9146 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9147 | }; |
| 9148 | |
| 9149 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9150 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9151 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9152 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9153 | TestCompletionCallback callback; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9154 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9155 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9156 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9157 | |
| 9158 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9159 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9160 | } |
| 9161 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9162 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9163 | HttpRequestInfo request; |
| 9164 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9165 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9166 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9167 | session_deps_.proxy_service = |
| 9168 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9169 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9170 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9171 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9172 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9173 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9174 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9175 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 9176 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 9177 | |
| 9178 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9179 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 9180 | MockWrite( |
| 9181 | "GET / HTTP/1.1\r\n" |
| 9182 | "Host: www.example.org\r\n" |
| 9183 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9184 | |
| 9185 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9186 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9187 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9188 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9189 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9190 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9191 | }; |
| 9192 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9193 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9194 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9195 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9196 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9197 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9198 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9199 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9200 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9201 | |
| 9202 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9203 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9204 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9205 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9206 | ASSERT_TRUE(response); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9207 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9208 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9209 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9210 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9211 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9212 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 9213 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9214 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9215 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9216 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9217 | EXPECT_EQ("Payload", response_text); |
| 9218 | } |
| 9219 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9220 | TEST_F(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9221 | HttpRequestInfo request; |
| 9222 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9223 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9224 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9225 | session_deps_.proxy_service = |
| 9226 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9227 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9228 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9229 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9230 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9231 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9232 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9233 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 9234 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 9235 | |
| 9236 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9237 | MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), |
| 9238 | arraysize(write_buffer)), |
| 9239 | MockWrite( |
| 9240 | "GET / HTTP/1.1\r\n" |
| 9241 | "Host: www.example.org\r\n" |
| 9242 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9243 | |
| 9244 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 9245 | MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), |
| 9246 | arraysize(read_buffer)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9247 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9248 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9249 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9250 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9251 | }; |
| 9252 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9253 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9254 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9255 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9256 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9257 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9258 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9259 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9260 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9261 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9262 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9263 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9264 | |
| 9265 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9266 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9267 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9268 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9269 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9270 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9271 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 9272 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9273 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9274 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9275 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9276 | |
| 9277 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9278 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9279 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9280 | EXPECT_EQ("Payload", response_text); |
| 9281 | } |
| 9282 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9283 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9284 | HttpRequestInfo request; |
| 9285 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9286 | request.url = GURL("http://www.example.org/"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9287 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9288 | session_deps_.proxy_service = |
| 9289 | ProxyService::CreateFixed("socks4://myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9290 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9291 | session_deps_.net_log = &net_log; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9292 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9293 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9294 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9295 | |
| 9296 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 9297 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 9298 | |
| 9299 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9300 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 9301 | MockWrite( |
| 9302 | "GET / HTTP/1.1\r\n" |
| 9303 | "Host: www.example.org\r\n" |
| 9304 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9305 | |
| 9306 | MockRead data_reads[] = { |
| 9307 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
| 9308 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9309 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9310 | MockRead("Payload"), |
| 9311 | MockRead(SYNCHRONOUS, OK) |
| 9312 | }; |
| 9313 | |
| 9314 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9315 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9316 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9317 | |
| 9318 | TestCompletionCallback callback; |
| 9319 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9320 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9321 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9322 | |
| 9323 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9324 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9325 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9326 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9327 | ASSERT_TRUE(response); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9328 | |
| 9329 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9330 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9331 | TestLoadTimingNotReused(load_timing_info, |
| 9332 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 9333 | |
| 9334 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9335 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9336 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9337 | EXPECT_EQ("Payload", response_text); |
| 9338 | } |
| 9339 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9340 | TEST_F(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9341 | HttpRequestInfo request; |
| 9342 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9343 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9344 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9345 | session_deps_.proxy_service = |
| 9346 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9347 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9348 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9349 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9350 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9351 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9352 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9353 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 9354 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9355 | const char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9356 | 0x05, // Version |
| 9357 | 0x01, // Command (CONNECT) |
| 9358 | 0x00, // Reserved. |
| 9359 | 0x03, // Address type (DOMAINNAME). |
| 9360 | 0x0F, // Length of domain (15) |
| 9361 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 9362 | '.', 'o', 'r', 'g', 0x00, 0x50, // 16-bit port (80) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9363 | }; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9364 | const char kSOCKS5OkResponse[] = |
| 9365 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 9366 | |
| 9367 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9368 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 9369 | MockWrite(ASYNC, kSOCKS5OkRequest, arraysize(kSOCKS5OkRequest)), |
| 9370 | MockWrite( |
| 9371 | "GET / HTTP/1.1\r\n" |
| 9372 | "Host: www.example.org\r\n" |
| 9373 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9374 | |
| 9375 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 9376 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 9377 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9378 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9379 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9380 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9381 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9382 | }; |
| 9383 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9384 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9385 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9386 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9387 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9388 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9389 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9390 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9391 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9392 | |
| 9393 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9394 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9395 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9396 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9397 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9398 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9399 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9400 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9401 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9402 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9403 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 9404 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9405 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9406 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9407 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9408 | EXPECT_EQ("Payload", response_text); |
| 9409 | } |
| 9410 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9411 | TEST_F(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9412 | HttpRequestInfo request; |
| 9413 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9414 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9415 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9416 | session_deps_.proxy_service = |
| 9417 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9418 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9419 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9420 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9421 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9422 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9423 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9424 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 9425 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9426 | const unsigned char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9427 | 0x05, // Version |
| 9428 | 0x01, // Command (CONNECT) |
| 9429 | 0x00, // Reserved. |
| 9430 | 0x03, // Address type (DOMAINNAME). |
| 9431 | 0x0F, // Length of domain (15) |
| 9432 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 9433 | '.', 'o', 'r', 'g', 0x01, 0xBB, // 16-bit port (443) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9434 | }; |
| 9435 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9436 | const char kSOCKS5OkResponse[] = |
| 9437 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 9438 | |
| 9439 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9440 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 9441 | MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
| 9442 | arraysize(kSOCKS5OkRequest)), |
| 9443 | MockWrite( |
| 9444 | "GET / HTTP/1.1\r\n" |
| 9445 | "Host: www.example.org\r\n" |
| 9446 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9447 | |
| 9448 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 9449 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 9450 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9451 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9452 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9453 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9454 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9455 | }; |
| 9456 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9457 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9458 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9459 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9460 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9461 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9462 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9463 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9464 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9465 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9466 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9467 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9468 | |
| 9469 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9470 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9471 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9472 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9473 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9474 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9475 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9476 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9477 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9478 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9479 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 9480 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9481 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9482 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9483 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9484 | EXPECT_EQ("Payload", response_text); |
| 9485 | } |
| 9486 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9487 | namespace { |
| 9488 | |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9489 | // Tests that for connection endpoints the group names are correctly set. |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9490 | |
| 9491 | struct GroupNameTest { |
| 9492 | std::string proxy_server; |
| 9493 | std::string url; |
| 9494 | std::string expected_group_name; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9495 | bool ssl; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9496 | }; |
| 9497 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9498 | std::unique_ptr<HttpNetworkSession> SetupSessionForGroupNameTests( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9499 | SpdySessionDependencies* session_deps_) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9500 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9501 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 9502 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9503 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 9504 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9505 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 9506 | http_server_properties->SetHttp2AlternativeService( |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9507 | url::SchemeHostPort("https", "host.with.alternate", 443), |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 9508 | alternative_service, expiration); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9509 | |
| 9510 | return session; |
| 9511 | } |
| 9512 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9513 | int GroupNameTransactionHelper(const std::string& url, |
| 9514 | HttpNetworkSession* session) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9515 | HttpRequestInfo request; |
| 9516 | request.method = "GET"; |
| 9517 | request.url = GURL(url); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9518 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9519 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9520 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9521 | TestCompletionCallback callback; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9522 | |
| 9523 | // We do not complete this request, the dtor will clean the transaction up. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9524 | return trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9525 | } |
| 9526 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9527 | } // namespace |
| 9528 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9529 | TEST_F(HttpNetworkTransactionTest, GroupNameForDirectConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9530 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9531 | { |
| 9532 | "", // unused |
| 9533 | "http://www.example.org/direct", |
| 9534 | "www.example.org:80", |
| 9535 | false, |
| 9536 | }, |
| 9537 | { |
| 9538 | "", // unused |
| 9539 | "http://[2001:1418:13:1::25]/direct", |
| 9540 | "[2001:1418:13:1::25]:80", |
| 9541 | false, |
| 9542 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9543 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9544 | // SSL Tests |
| 9545 | { |
| 9546 | "", // unused |
| 9547 | "https://www.example.org/direct_ssl", |
| 9548 | "ssl/www.example.org:443", |
| 9549 | true, |
| 9550 | }, |
| 9551 | { |
| 9552 | "", // unused |
| 9553 | "https://[2001:1418:13:1::25]/direct", |
| 9554 | "ssl/[2001:1418:13:1::25]:443", |
| 9555 | true, |
| 9556 | }, |
| 9557 | { |
| 9558 | "", // unused |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9559 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9560 | "ssl/host.with.alternate:443", |
| 9561 | true, |
| 9562 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9563 | }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9564 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 9565 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9566 | session_deps_.proxy_service = |
| 9567 | ProxyService::CreateFixed(tests[i].proxy_server); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9568 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 9569 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9570 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9571 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9572 | CaptureGroupNameTransportSocketPool* transport_conn_pool = |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9573 | new CaptureGroupNameTransportSocketPool(nullptr, nullptr); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9574 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9575 | new CaptureGroupNameSSLSocketPool(nullptr, nullptr); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9576 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 9577 | mock_pool_manager->SetTransportSocketPool(transport_conn_pool); |
| 9578 | mock_pool_manager->SetSSLSocketPool(ssl_conn_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 9579 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9580 | |
| 9581 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9582 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9583 | if (tests[i].ssl) |
| 9584 | EXPECT_EQ(tests[i].expected_group_name, |
| 9585 | ssl_conn_pool->last_group_name_received()); |
| 9586 | else |
| 9587 | EXPECT_EQ(tests[i].expected_group_name, |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9588 | transport_conn_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9589 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9590 | } |
| 9591 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9592 | TEST_F(HttpNetworkTransactionTest, GroupNameForHTTPProxyConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9593 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9594 | { |
| 9595 | "http_proxy", |
| 9596 | "http://www.example.org/http_proxy_normal", |
| 9597 | "www.example.org:80", |
| 9598 | false, |
| 9599 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9600 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9601 | // SSL Tests |
| 9602 | { |
| 9603 | "http_proxy", |
| 9604 | "https://www.example.org/http_connect_ssl", |
| 9605 | "ssl/www.example.org:443", |
| 9606 | true, |
| 9607 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 9608 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9609 | { |
| 9610 | "http_proxy", |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9611 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9612 | "ssl/host.with.alternate:443", |
| 9613 | true, |
| 9614 | }, |
[email protected] | 4549925 | 2013-01-23 17:12:56 | [diff] [blame] | 9615 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9616 | { |
| 9617 | "http_proxy", |
| 9618 | "ftp://ftp.google.com/http_proxy_normal", |
| 9619 | "ftp/ftp.google.com:21", |
| 9620 | false, |
| 9621 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9622 | }; |
| 9623 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 9624 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9625 | session_deps_.proxy_service = |
| 9626 | ProxyService::CreateFixed(tests[i].proxy_server); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9627 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 9628 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9629 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9630 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9631 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9632 | HostPortPair proxy_host("http_proxy", 80); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9633 | CaptureGroupNameHttpProxySocketPool* http_proxy_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9634 | new CaptureGroupNameHttpProxySocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9635 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9636 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9637 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
avi | adef344 | 2016-10-03 18:50:39 | [diff] [blame] | 9638 | mock_pool_manager->SetSocketPoolForHTTPProxy( |
| 9639 | proxy_host, base::WrapUnique(http_proxy_pool)); |
| 9640 | mock_pool_manager->SetSocketPoolForSSLWithProxy( |
| 9641 | proxy_host, base::WrapUnique(ssl_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 9642 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9643 | |
| 9644 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9645 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9646 | if (tests[i].ssl) |
| 9647 | EXPECT_EQ(tests[i].expected_group_name, |
| 9648 | ssl_conn_pool->last_group_name_received()); |
| 9649 | else |
| 9650 | EXPECT_EQ(tests[i].expected_group_name, |
| 9651 | http_proxy_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9652 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9653 | } |
| 9654 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9655 | TEST_F(HttpNetworkTransactionTest, GroupNameForSOCKSConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9656 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9657 | { |
| 9658 | "socks4://socks_proxy:1080", |
| 9659 | "http://www.example.org/socks4_direct", |
| 9660 | "socks4/www.example.org:80", |
| 9661 | false, |
| 9662 | }, |
| 9663 | { |
| 9664 | "socks5://socks_proxy:1080", |
| 9665 | "http://www.example.org/socks5_direct", |
| 9666 | "socks5/www.example.org:80", |
| 9667 | false, |
| 9668 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9669 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9670 | // SSL Tests |
| 9671 | { |
| 9672 | "socks4://socks_proxy:1080", |
| 9673 | "https://www.example.org/socks4_ssl", |
| 9674 | "socks4/ssl/www.example.org:443", |
| 9675 | true, |
| 9676 | }, |
| 9677 | { |
| 9678 | "socks5://socks_proxy:1080", |
| 9679 | "https://www.example.org/socks5_ssl", |
| 9680 | "socks5/ssl/www.example.org:443", |
| 9681 | true, |
| 9682 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 9683 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9684 | { |
| 9685 | "socks4://socks_proxy:1080", |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9686 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9687 | "socks4/ssl/host.with.alternate:443", |
| 9688 | true, |
| 9689 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9690 | }; |
| 9691 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 9692 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9693 | session_deps_.proxy_service = |
| 9694 | ProxyService::CreateFixed(tests[i].proxy_server); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9695 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 9696 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 9697 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9698 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9699 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9700 | HostPortPair proxy_host("socks_proxy", 1080); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9701 | CaptureGroupNameSOCKSSocketPool* socks_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9702 | new CaptureGroupNameSOCKSSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9703 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9704 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9705 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
avi | adef344 | 2016-10-03 18:50:39 | [diff] [blame] | 9706 | mock_pool_manager->SetSocketPoolForSOCKSProxy( |
| 9707 | proxy_host, base::WrapUnique(socks_conn_pool)); |
| 9708 | mock_pool_manager->SetSocketPoolForSSLWithProxy( |
| 9709 | proxy_host, base::WrapUnique(ssl_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 9710 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9711 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9712 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9713 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9714 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9715 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9716 | if (tests[i].ssl) |
| 9717 | EXPECT_EQ(tests[i].expected_group_name, |
| 9718 | ssl_conn_pool->last_group_name_received()); |
| 9719 | else |
| 9720 | EXPECT_EQ(tests[i].expected_group_name, |
| 9721 | socks_conn_pool->last_group_name_received()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9722 | } |
| 9723 | } |
| 9724 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9725 | TEST_F(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9726 | HttpRequestInfo request; |
| 9727 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9728 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9729 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9730 | session_deps_.proxy_service = |
| 9731 | ProxyService::CreateFixed("myproxy:70;foobar:80"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 9732 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 9733 | // This simulates failure resolving all hostnames; that means we will fail |
| 9734 | // connecting to both proxies (myproxy:70 and foobar:80). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9735 | session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 9736 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9737 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9738 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9739 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9740 | TestCompletionCallback callback; |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9741 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9742 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9743 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9744 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9745 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9746 | EXPECT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9747 | } |
| 9748 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9749 | // Base test to make sure that when the load flags for a request specify to |
| 9750 | // bypass the cache, the DNS cache is not used. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9751 | void HttpNetworkTransactionTest::BypassHostCacheOnRefreshHelper( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9752 | int load_flags) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9753 | // Issue a request, asking to bypass the cache(s). |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9754 | HttpRequestInfo request_info; |
| 9755 | request_info.method = "GET"; |
| 9756 | request_info.load_flags = load_flags; |
| 9757 | request_info.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9758 | |
[email protected] | a2c2fb9 | 2009-07-18 07:31:04 | [diff] [blame] | 9759 | // Select a host resolver that does caching. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9760 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 9761 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9762 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9763 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9764 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9765 | // 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] | 9766 | AddressList addrlist; |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 9767 | TestCompletionCallback callback; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9768 | std::unique_ptr<HostResolver::Request> request1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9769 | int rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9770 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9771 | DEFAULT_PRIORITY, &addrlist, callback.callback(), &request1, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9772 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9773 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 9774 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9775 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9776 | |
| 9777 | // Verify that it was added to host cache, by doing a subsequent async lookup |
| 9778 | // and confirming it completes synchronously. |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9779 | std::unique_ptr<HostResolver::Request> request2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9780 | rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9781 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9782 | DEFAULT_PRIORITY, &addrlist, callback.callback(), &request2, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9783 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9784 | ASSERT_THAT(rv, IsOk()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9785 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9786 | // 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] | 9787 | // we can tell if the next lookup hit the cache, or the "network". |
| 9788 | // (cache --> success, "network" --> failure). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9789 | session_deps_.host_resolver->rules()->AddSimulatedFailure("www.example.org"); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9790 | |
| 9791 | // Connect up a mock socket which will fail with ERR_UNEXPECTED during the |
| 9792 | // 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] | 9793 | MockRead data_reads[] = { MockRead(SYNCHRONOUS, ERR_UNEXPECTED) }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9794 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9795 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9796 | |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9797 | // Run the request. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9798 | rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9799 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9800 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9801 | |
| 9802 | // If we bypassed the cache, we would have gotten a failure while resolving |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9803 | // "www.example.org". |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9804 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9805 | } |
| 9806 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9807 | // There are multiple load flags that should trigger the host cache bypass. |
| 9808 | // Test each in isolation: |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9809 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh1) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9810 | BypassHostCacheOnRefreshHelper(LOAD_BYPASS_CACHE); |
| 9811 | } |
| 9812 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9813 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh2) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9814 | BypassHostCacheOnRefreshHelper(LOAD_VALIDATE_CACHE); |
| 9815 | } |
| 9816 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9817 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh3) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9818 | BypassHostCacheOnRefreshHelper(LOAD_DISABLE_CACHE); |
| 9819 | } |
| 9820 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9821 | // Make sure we can handle an error when writing the request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9822 | TEST_F(HttpNetworkTransactionTest, RequestWriteError) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9823 | HttpRequestInfo request; |
| 9824 | request.method = "GET"; |
| 9825 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9826 | |
| 9827 | MockWrite write_failure[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9828 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9829 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9830 | StaticSocketDataProvider data(NULL, 0, |
| 9831 | write_failure, arraysize(write_failure)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9832 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9833 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9834 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9835 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9836 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9837 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9838 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9839 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9840 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9841 | |
| 9842 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9843 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9844 | |
| 9845 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9846 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9847 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9848 | } |
| 9849 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9850 | // Check that a connection closed after the start of the headers finishes ok. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9851 | TEST_F(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9852 | HttpRequestInfo request; |
| 9853 | request.method = "GET"; |
| 9854 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9855 | |
| 9856 | MockRead data_reads[] = { |
| 9857 | MockRead("HTTP/1."), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9858 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9859 | }; |
| 9860 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9861 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9862 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9863 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9864 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9865 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9866 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9867 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9868 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9869 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9870 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9871 | |
| 9872 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9873 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9874 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9875 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9876 | ASSERT_TRUE(response); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9877 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9878 | EXPECT_TRUE(response->headers); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9879 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 9880 | |
| 9881 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9882 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9883 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9884 | EXPECT_EQ("", response_data); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9885 | |
| 9886 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9887 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9888 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9889 | } |
| 9890 | |
| 9891 | // Make sure that a dropped connection while draining the body for auth |
| 9892 | // restart does the right thing. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9893 | TEST_F(HttpNetworkTransactionTest, DrainResetOK) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9894 | HttpRequestInfo request; |
| 9895 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9896 | request.url = GURL("http://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9897 | |
| 9898 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9899 | MockWrite( |
| 9900 | "GET / HTTP/1.1\r\n" |
| 9901 | "Host: www.example.org\r\n" |
| 9902 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9903 | }; |
| 9904 | |
| 9905 | MockRead data_reads1[] = { |
| 9906 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 9907 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9908 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9909 | MockRead("Content-Length: 14\r\n\r\n"), |
| 9910 | MockRead("Unauth"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9911 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9912 | }; |
| 9913 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9914 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 9915 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9916 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9917 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9918 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9919 | // be issuing -- the final header line contains the credentials. |
| 9920 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9921 | MockWrite( |
| 9922 | "GET / HTTP/1.1\r\n" |
| 9923 | "Host: www.example.org\r\n" |
| 9924 | "Connection: keep-alive\r\n" |
| 9925 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9926 | }; |
| 9927 | |
| 9928 | // Lastly, the server responds with the actual content. |
| 9929 | MockRead data_reads2[] = { |
| 9930 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9931 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9932 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9933 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9934 | }; |
| 9935 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9936 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 9937 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9938 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9939 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9940 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9941 | TestCompletionCallback callback1; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9942 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9943 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9944 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9945 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9946 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9947 | |
| 9948 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9949 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9950 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9951 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9952 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9953 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9954 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9955 | TestCompletionCallback callback2; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9956 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9957 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9958 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9959 | |
| 9960 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9961 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9962 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9963 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9964 | ASSERT_TRUE(response); |
| 9965 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9966 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9967 | } |
| 9968 | |
| 9969 | // Test HTTPS connections going through a proxy that sends extra data. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9970 | TEST_F(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9971 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9972 | |
| 9973 | HttpRequestInfo request; |
| 9974 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9975 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9976 | |
| 9977 | MockRead proxy_reads[] = { |
| 9978 | MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9979 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9980 | }; |
| 9981 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9982 | StaticSocketDataProvider data(proxy_reads, arraysize(proxy_reads), NULL, 0); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9983 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9984 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9985 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9986 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9987 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9988 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9989 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9990 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9991 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9992 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9993 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9994 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9995 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9996 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9997 | |
| 9998 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9999 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10000 | } |
| 10001 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10002 | TEST_F(HttpNetworkTransactionTest, LargeContentLengthThenClose) { |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10003 | HttpRequestInfo request; |
| 10004 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10005 | request.url = GURL("http://www.example.org/"); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10006 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10007 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10008 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10009 | |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 10010 | MockRead data_reads[] = { |
| 10011 | 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] | 10012 | MockRead(SYNCHRONOUS, OK), |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 10013 | }; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10014 | |
| 10015 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10016 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10017 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10018 | TestCompletionCallback callback; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10019 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10020 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10021 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10022 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10023 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10024 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10025 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10026 | ASSERT_TRUE(response); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10027 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10028 | EXPECT_TRUE(response->headers); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10029 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 10030 | |
| 10031 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10032 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10033 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 10034 | } |
| 10035 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10036 | TEST_F(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 10037 | base::FilePath temp_file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 10038 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path)); |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 10039 | const uint64_t kFakeSize = 100000; // file is actually blank |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 10040 | UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 10041 | overriding_content_length(kFakeSize); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10042 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10043 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10044 | element_readers.push_back(std::make_unique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 10045 | base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 10046 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 10047 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10048 | |
| 10049 | HttpRequestInfo request; |
| 10050 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10051 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10052 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10053 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10054 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10055 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10056 | |
| 10057 | MockRead data_reads[] = { |
| 10058 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 10059 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10060 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10061 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10062 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10063 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10064 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10065 | TestCompletionCallback callback; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10066 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10067 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10068 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10069 | |
| 10070 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10071 | EXPECT_THAT(rv, IsError(ERR_UPLOAD_FILE_CHANGED)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10072 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10073 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10074 | ASSERT_TRUE(response); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10075 | |
maksim.sisov | e869bf5 | 2016-06-23 17:11:52 | [diff] [blame] | 10076 | EXPECT_FALSE(response->headers); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10077 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 10078 | base::DeleteFile(temp_file_path, false); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10079 | } |
| 10080 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10081 | TEST_F(HttpNetworkTransactionTest, UploadUnreadableFile) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 10082 | base::FilePath temp_file; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 10083 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10084 | std::string temp_file_content("Unreadable file."); |
lazyboy | 8df84fc | 2017-04-12 02:12:48 | [diff] [blame] | 10085 | ASSERT_EQ(static_cast<int>(temp_file_content.length()), |
| 10086 | base::WriteFile(temp_file, temp_file_content.c_str(), |
| 10087 | temp_file_content.length())); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 10088 | ASSERT_TRUE(base::MakeFileUnreadable(temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10089 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10090 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10091 | element_readers.push_back(std::make_unique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 10092 | base::ThreadTaskRunnerHandle::Get().get(), temp_file, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 10093 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 10094 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10095 | |
| 10096 | HttpRequestInfo request; |
| 10097 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10098 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10099 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10100 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 10101 | // If we try to upload an unreadable file, the transaction should fail. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10102 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10103 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10104 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 10105 | StaticSocketDataProvider data(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10106 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10107 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10108 | TestCompletionCallback callback; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10109 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10110 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10111 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10112 | |
| 10113 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10114 | EXPECT_THAT(rv, IsError(ERR_ACCESS_DENIED)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10115 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 10116 | base::DeleteFile(temp_file, false); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10117 | } |
| 10118 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10119 | TEST_F(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10120 | class FakeUploadElementReader : public UploadElementReader { |
| 10121 | public: |
| 10122 | FakeUploadElementReader() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10123 | ~FakeUploadElementReader() override {} |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10124 | |
| 10125 | const CompletionCallback& callback() const { return callback_; } |
| 10126 | |
| 10127 | // UploadElementReader overrides: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10128 | int Init(const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10129 | callback_ = callback; |
| 10130 | return ERR_IO_PENDING; |
| 10131 | } |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 10132 | uint64_t GetContentLength() const override { return 0; } |
| 10133 | uint64_t BytesRemaining() const override { return 0; } |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10134 | int Read(IOBuffer* buf, |
| 10135 | int buf_length, |
| 10136 | const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10137 | return ERR_FAILED; |
| 10138 | } |
| 10139 | |
| 10140 | private: |
| 10141 | CompletionCallback callback_; |
| 10142 | }; |
| 10143 | |
| 10144 | FakeUploadElementReader* fake_reader = new FakeUploadElementReader; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10145 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
| 10146 | element_readers.push_back(base::WrapUnique(fake_reader)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 10147 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10148 | |
| 10149 | HttpRequestInfo request; |
| 10150 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10151 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10152 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10153 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10154 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10155 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10156 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10157 | |
| 10158 | StaticSocketDataProvider data; |
| 10159 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10160 | |
| 10161 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10162 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10163 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 10164 | base::RunLoop().RunUntilIdle(); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10165 | |
| 10166 | // Transaction is pending on request body initialization. |
| 10167 | ASSERT_FALSE(fake_reader->callback().is_null()); |
| 10168 | |
| 10169 | // Return Init()'s result after the transaction gets destroyed. |
| 10170 | trans.reset(); |
| 10171 | fake_reader->callback().Run(OK); // Should not crash. |
| 10172 | } |
| 10173 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10174 | // Tests that changes to Auth realms are treated like auth rejections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10175 | TEST_F(HttpNetworkTransactionTest, ChangeAuthRealms) { |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10176 | HttpRequestInfo request; |
| 10177 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10178 | request.url = GURL("http://www.example.org/"); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10179 | |
| 10180 | // First transaction will request a resource and receive a Basic challenge |
| 10181 | // with realm="first_realm". |
| 10182 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10183 | MockWrite( |
| 10184 | "GET / HTTP/1.1\r\n" |
| 10185 | "Host: www.example.org\r\n" |
| 10186 | "Connection: keep-alive\r\n" |
| 10187 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10188 | }; |
| 10189 | MockRead data_reads1[] = { |
| 10190 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 10191 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 10192 | "\r\n"), |
| 10193 | }; |
| 10194 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10195 | // After calling trans.RestartWithAuth(), provide an Authentication header |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10196 | // for first_realm. The server will reject and provide a challenge with |
| 10197 | // second_realm. |
| 10198 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10199 | MockWrite( |
| 10200 | "GET / HTTP/1.1\r\n" |
| 10201 | "Host: www.example.org\r\n" |
| 10202 | "Connection: keep-alive\r\n" |
| 10203 | "Authorization: Basic Zmlyc3Q6YmF6\r\n" |
| 10204 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10205 | }; |
| 10206 | MockRead data_reads2[] = { |
| 10207 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 10208 | "WWW-Authenticate: Basic realm=\"second_realm\"\r\n" |
| 10209 | "\r\n"), |
| 10210 | }; |
| 10211 | |
| 10212 | // This again fails, and goes back to first_realm. Make sure that the |
| 10213 | // entry is removed from cache. |
| 10214 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10215 | MockWrite( |
| 10216 | "GET / HTTP/1.1\r\n" |
| 10217 | "Host: www.example.org\r\n" |
| 10218 | "Connection: keep-alive\r\n" |
| 10219 | "Authorization: Basic c2Vjb25kOmZvdQ==\r\n" |
| 10220 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10221 | }; |
| 10222 | MockRead data_reads3[] = { |
| 10223 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 10224 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 10225 | "\r\n"), |
| 10226 | }; |
| 10227 | |
| 10228 | // Try one last time (with the correct password) and get the resource. |
| 10229 | MockWrite data_writes4[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10230 | MockWrite( |
| 10231 | "GET / HTTP/1.1\r\n" |
| 10232 | "Host: www.example.org\r\n" |
| 10233 | "Connection: keep-alive\r\n" |
| 10234 | "Authorization: Basic Zmlyc3Q6YmFy\r\n" |
| 10235 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10236 | }; |
| 10237 | MockRead data_reads4[] = { |
| 10238 | MockRead("HTTP/1.1 200 OK\r\n" |
| 10239 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10240 | "Content-Length: 5\r\n" |
| 10241 | "\r\n" |
| 10242 | "hello"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10243 | }; |
| 10244 | |
| 10245 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 10246 | data_writes1, arraysize(data_writes1)); |
| 10247 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 10248 | data_writes2, arraysize(data_writes2)); |
| 10249 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 10250 | data_writes3, arraysize(data_writes3)); |
| 10251 | StaticSocketDataProvider data4(data_reads4, arraysize(data_reads4), |
| 10252 | data_writes4, arraysize(data_writes4)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10253 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 10254 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 10255 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 10256 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10257 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10258 | TestCompletionCallback callback1; |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10259 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10260 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10261 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10262 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10263 | // Issue the first request with Authorize headers. There should be a |
| 10264 | // password prompt for first_realm waiting to be filled in after the |
| 10265 | // transaction completes. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10266 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10267 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10268 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10269 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10270 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10271 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10272 | const AuthChallengeInfo* challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10273 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10274 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10275 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10276 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 10277 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10278 | |
| 10279 | // Issue the second request with an incorrect password. There should be a |
| 10280 | // password prompt for second_realm waiting to be filled in after the |
| 10281 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10282 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10283 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBaz), |
| 10284 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10285 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10286 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10287 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10288 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10289 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10290 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10291 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10292 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10293 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10294 | EXPECT_EQ("second_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 10295 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10296 | |
| 10297 | // Issue the third request with another incorrect password. There should be |
| 10298 | // a password prompt for first_realm waiting to be filled in. If the password |
| 10299 | // prompt is not present, it indicates that the HttpAuthCacheEntry for |
| 10300 | // first_realm was not correctly removed. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10301 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10302 | rv = trans.RestartWithAuth(AuthCredentials(kSecond, kFou), |
| 10303 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10304 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10305 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10306 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10307 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10308 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10309 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10310 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10311 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10312 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10313 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 10314 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10315 | |
| 10316 | // Issue the fourth request with the correct password and username. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10317 | TestCompletionCallback callback4; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10318 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBar), |
| 10319 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10320 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10321 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10322 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10323 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10324 | ASSERT_TRUE(response); |
| 10325 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10326 | } |
| 10327 | |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 10328 | // Regression test for https://crbug.com/754395. |
| 10329 | TEST_F(HttpNetworkTransactionTest, IgnoreAltSvcWithInvalidCert) { |
| 10330 | MockRead data_reads[] = { |
| 10331 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10332 | MockRead(kAlternativeServiceHttpHeader), |
| 10333 | MockRead("\r\n"), |
| 10334 | MockRead("hello world"), |
| 10335 | MockRead(SYNCHRONOUS, OK), |
| 10336 | }; |
| 10337 | |
| 10338 | HttpRequestInfo request; |
| 10339 | request.method = "GET"; |
| 10340 | request.url = GURL("https://www.example.org/"); |
| 10341 | |
| 10342 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 10343 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10344 | |
| 10345 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10346 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 10347 | ASSERT_TRUE(ssl.cert); |
| 10348 | ssl.cert_status = CERT_STATUS_COMMON_NAME_INVALID; |
| 10349 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10350 | |
| 10351 | TestCompletionCallback callback; |
| 10352 | |
| 10353 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10354 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 10355 | |
| 10356 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 10357 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10358 | |
| 10359 | url::SchemeHostPort test_server(request.url); |
| 10360 | HttpServerProperties* http_server_properties = |
| 10361 | session->http_server_properties(); |
| 10362 | EXPECT_TRUE( |
| 10363 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
| 10364 | |
| 10365 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 10366 | |
| 10367 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 10368 | ASSERT_TRUE(response); |
| 10369 | ASSERT_TRUE(response->headers); |
| 10370 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10371 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 10372 | EXPECT_FALSE(response->was_alpn_negotiated); |
| 10373 | |
| 10374 | std::string response_data; |
| 10375 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 10376 | EXPECT_EQ("hello world", response_data); |
| 10377 | |
| 10378 | EXPECT_TRUE( |
| 10379 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
| 10380 | } |
| 10381 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10382 | TEST_F(HttpNetworkTransactionTest, HonorAlternativeServiceHeader) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10383 | MockRead data_reads[] = { |
| 10384 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10385 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10386 | MockRead("\r\n"), |
| 10387 | MockRead("hello world"), |
| 10388 | MockRead(SYNCHRONOUS, OK), |
| 10389 | }; |
| 10390 | |
| 10391 | HttpRequestInfo request; |
| 10392 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10393 | request.url = GURL("https://www.example.org/"); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10394 | |
| 10395 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10396 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10397 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10398 | SSLSocketDataProvider ssl(ASYNC, OK); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 10399 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 10400 | ASSERT_TRUE(ssl.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10401 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10402 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10403 | TestCompletionCallback callback; |
| 10404 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10405 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10406 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10407 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10408 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10409 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10410 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10411 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10412 | HttpServerProperties* http_server_properties = |
| 10413 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10414 | EXPECT_TRUE( |
| 10415 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10416 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10417 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10418 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10419 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10420 | ASSERT_TRUE(response); |
| 10421 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10422 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10423 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10424 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10425 | |
| 10426 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10427 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10428 | EXPECT_EQ("hello world", response_data); |
| 10429 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10430 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 10431 | http_server_properties->GetAlternativeServiceInfos(test_server); |
| 10432 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 10433 | AlternativeService alternative_service(kProtoHTTP2, "mail.example.org", 443); |
| 10434 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 10435 | alternative_service_info_vector[0].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10436 | } |
| 10437 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10438 | // Regression test for https://crbug.com/615497. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10439 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10440 | DoNotParseAlternativeServiceHeaderOnInsecureRequest) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10441 | MockRead data_reads[] = { |
| 10442 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10443 | MockRead(kAlternativeServiceHttpHeader), |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10444 | MockRead("\r\n"), |
| 10445 | MockRead("hello world"), |
| 10446 | MockRead(SYNCHRONOUS, OK), |
| 10447 | }; |
| 10448 | |
| 10449 | HttpRequestInfo request; |
| 10450 | request.method = "GET"; |
| 10451 | request.url = GURL("http://www.example.org/"); |
| 10452 | request.load_flags = 0; |
| 10453 | |
| 10454 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 10455 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10456 | |
| 10457 | TestCompletionCallback callback; |
| 10458 | |
| 10459 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10460 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10461 | |
| 10462 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10463 | HttpServerProperties* http_server_properties = |
| 10464 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10465 | EXPECT_TRUE( |
| 10466 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10467 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10468 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10469 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10470 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10471 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10472 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10473 | ASSERT_TRUE(response); |
| 10474 | ASSERT_TRUE(response->headers); |
| 10475 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10476 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10477 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10478 | |
| 10479 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10480 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10481 | EXPECT_EQ("hello world", response_data); |
| 10482 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10483 | EXPECT_TRUE( |
| 10484 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10485 | } |
| 10486 | |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 10487 | // HTTP/2 Alternative Services should be disabled by default. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10488 | // TODO(bnc): Remove when https://crbug.com/615413 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10489 | TEST_F(HttpNetworkTransactionTest, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10490 | DisableHTTP2AlternativeServicesWithDifferentHost) { |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 10491 | session_deps_.enable_http2_alternative_service = false; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10492 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10493 | HttpRequestInfo request; |
| 10494 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10495 | request.url = GURL("https://www.example.org/"); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10496 | request.load_flags = 0; |
| 10497 | |
| 10498 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10499 | StaticSocketDataProvider first_data; |
| 10500 | first_data.set_connect_data(mock_connect); |
| 10501 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10502 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10503 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10504 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10505 | |
| 10506 | MockRead data_reads[] = { |
| 10507 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 10508 | MockRead(ASYNC, OK), |
| 10509 | }; |
| 10510 | StaticSocketDataProvider second_data(data_reads, arraysize(data_reads), NULL, |
| 10511 | 0); |
| 10512 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 10513 | |
| 10514 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10515 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10516 | HttpServerProperties* http_server_properties = |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10517 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10518 | AlternativeService alternative_service(kProtoHTTP2, "different.example.org", |
| 10519 | 444); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10520 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10521 | http_server_properties->SetHttp2AlternativeService( |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10522 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 10523 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10524 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10525 | TestCompletionCallback callback; |
| 10526 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10527 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10528 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10529 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10530 | } |
| 10531 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10532 | // Regression test for https://crbug.com/615497: |
| 10533 | // Alternative Services should be disabled for http origin. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10534 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10535 | DisableAlternativeServicesForInsecureOrigin) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10536 | HttpRequestInfo request; |
| 10537 | request.method = "GET"; |
| 10538 | request.url = GURL("http://www.example.org/"); |
| 10539 | request.load_flags = 0; |
| 10540 | |
| 10541 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10542 | StaticSocketDataProvider first_data; |
| 10543 | first_data.set_connect_data(mock_connect); |
| 10544 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
| 10545 | |
| 10546 | MockRead data_reads[] = { |
| 10547 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 10548 | MockRead(ASYNC, OK), |
| 10549 | }; |
| 10550 | StaticSocketDataProvider second_data(data_reads, arraysize(data_reads), NULL, |
| 10551 | 0); |
| 10552 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 10553 | |
| 10554 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10555 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10556 | HttpServerProperties* http_server_properties = |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10557 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10558 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10559 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10560 | http_server_properties->SetHttp2AlternativeService( |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10561 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 10562 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10563 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10564 | TestCompletionCallback callback; |
| 10565 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10566 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10567 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10568 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10569 | } |
| 10570 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10571 | TEST_F(HttpNetworkTransactionTest, ClearAlternativeServices) { |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10572 | // Set an alternative service for origin. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10573 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10574 | HttpServerProperties* http_server_properties = |
| 10575 | session->http_server_properties(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10576 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10577 | AlternativeService alternative_service(kProtoQUIC, "", 80); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10578 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10579 | http_server_properties->SetQuicAlternativeService( |
| 10580 | test_server, alternative_service, expiration, |
| 10581 | session->params().quic_supported_versions); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10582 | EXPECT_EQ( |
| 10583 | 1u, |
| 10584 | http_server_properties->GetAlternativeServiceInfos(test_server).size()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10585 | |
| 10586 | // Send a clear header. |
| 10587 | MockRead data_reads[] = { |
| 10588 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10589 | MockRead("Alt-Svc: clear\r\n"), |
| 10590 | MockRead("\r\n"), |
| 10591 | MockRead("hello world"), |
| 10592 | MockRead(SYNCHRONOUS, OK), |
| 10593 | }; |
| 10594 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 10595 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10596 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10597 | SSLSocketDataProvider ssl(ASYNC, OK); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 10598 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 10599 | ASSERT_TRUE(ssl.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10600 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10601 | |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10602 | HttpRequestInfo request; |
| 10603 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10604 | request.url = GURL("https://www.example.org/"); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10605 | |
| 10606 | TestCompletionCallback callback; |
| 10607 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10608 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10609 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10610 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10611 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10612 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10613 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10614 | ASSERT_TRUE(response); |
| 10615 | ASSERT_TRUE(response->headers); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10616 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10617 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10618 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10619 | |
| 10620 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10621 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10622 | EXPECT_EQ("hello world", response_data); |
| 10623 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10624 | EXPECT_TRUE( |
| 10625 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10626 | } |
| 10627 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10628 | TEST_F(HttpNetworkTransactionTest, HonorMultipleAlternativeServiceHeaders) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10629 | MockRead data_reads[] = { |
| 10630 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10631 | MockRead("Alt-Svc: h2=\"www.example.com:443\","), |
| 10632 | MockRead("h2=\":1234\"\r\n\r\n"), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10633 | MockRead("hello world"), |
| 10634 | MockRead(SYNCHRONOUS, OK), |
| 10635 | }; |
| 10636 | |
| 10637 | HttpRequestInfo request; |
| 10638 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10639 | request.url = GURL("https://www.example.org/"); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10640 | |
| 10641 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10642 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10643 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10644 | SSLSocketDataProvider ssl(ASYNC, OK); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 10645 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 10646 | ASSERT_TRUE(ssl.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10647 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10648 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10649 | TestCompletionCallback callback; |
| 10650 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10651 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10652 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10653 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10654 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10655 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10656 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10657 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10658 | HttpServerProperties* http_server_properties = |
| 10659 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10660 | EXPECT_TRUE( |
| 10661 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10662 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10663 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10664 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10665 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10666 | ASSERT_TRUE(response); |
| 10667 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10668 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10669 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10670 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10671 | |
| 10672 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10673 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10674 | EXPECT_EQ("hello world", response_data); |
| 10675 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10676 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 10677 | http_server_properties->GetAlternativeServiceInfos(test_server); |
| 10678 | ASSERT_EQ(2u, alternative_service_info_vector.size()); |
| 10679 | |
| 10680 | AlternativeService alternative_service(kProtoHTTP2, "www.example.com", 443); |
| 10681 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 10682 | alternative_service_info_vector[0].alternative_service()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10683 | AlternativeService alternative_service_2(kProtoHTTP2, "www.example.org", |
| 10684 | 1234); |
| 10685 | EXPECT_EQ(alternative_service_2, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 10686 | alternative_service_info_vector[1].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10687 | } |
| 10688 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10689 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10690 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10691 | HostPortPair alternative("alternative.example.org", 443); |
| 10692 | std::string origin_url = "https://origin.example.org:443"; |
| 10693 | std::string alternative_url = "https://alternative.example.org:443"; |
| 10694 | |
| 10695 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 10696 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10697 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10698 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10699 | |
| 10700 | // HTTP/1.1 data for request. |
| 10701 | MockWrite http_writes[] = { |
| 10702 | MockWrite("GET / HTTP/1.1\r\n" |
| 10703 | "Host: alternative.example.org\r\n" |
| 10704 | "Connection: keep-alive\r\n\r\n"), |
| 10705 | }; |
| 10706 | |
| 10707 | MockRead http_reads[] = { |
| 10708 | MockRead("HTTP/1.1 200 OK\r\n" |
| 10709 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10710 | "Content-Length: 40\r\n\r\n" |
| 10711 | "first HTTP/1.1 response from alternative"), |
| 10712 | }; |
| 10713 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 10714 | http_writes, arraysize(http_writes)); |
| 10715 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 10716 | |
| 10717 | StaticSocketDataProvider data_refused; |
| 10718 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 10719 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 10720 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10721 | // Set up a QUIC alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10722 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10723 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10724 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10725 | AlternativeService alternative_service(kProtoQUIC, alternative); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10726 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10727 | http_server_properties->SetQuicAlternativeService( |
| 10728 | server, alternative_service, expiration, |
| 10729 | HttpNetworkSession::Params().quic_supported_versions); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10730 | // Mark the QUIC alternative service as broken. |
| 10731 | http_server_properties->MarkAlternativeServiceBroken(alternative_service); |
| 10732 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10733 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 10734 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10735 | request.method = "GET"; |
| 10736 | request.url = GURL(origin_url); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10737 | TestCompletionCallback callback; |
| 10738 | NetErrorDetails details; |
| 10739 | EXPECT_FALSE(details.quic_broken); |
| 10740 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10741 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10742 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10743 | EXPECT_TRUE(details.quic_broken); |
| 10744 | } |
| 10745 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10746 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicNotBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10747 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10748 | HostPortPair alternative1("alternative1.example.org", 443); |
| 10749 | HostPortPair alternative2("alternative2.example.org", 443); |
| 10750 | std::string origin_url = "https://origin.example.org:443"; |
| 10751 | std::string alternative_url1 = "https://alternative1.example.org:443"; |
| 10752 | std::string alternative_url2 = "https://alternative2.example.org:443"; |
| 10753 | |
| 10754 | // Negotiate HTTP/1.1 with alternative1.example.org. |
| 10755 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10756 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10757 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10758 | |
| 10759 | // HTTP/1.1 data for request. |
| 10760 | MockWrite http_writes[] = { |
| 10761 | MockWrite("GET / HTTP/1.1\r\n" |
| 10762 | "Host: alternative1.example.org\r\n" |
| 10763 | "Connection: keep-alive\r\n\r\n"), |
| 10764 | }; |
| 10765 | |
| 10766 | MockRead http_reads[] = { |
| 10767 | MockRead("HTTP/1.1 200 OK\r\n" |
| 10768 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10769 | "Content-Length: 40\r\n\r\n" |
| 10770 | "first HTTP/1.1 response from alternative1"), |
| 10771 | }; |
| 10772 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 10773 | http_writes, arraysize(http_writes)); |
| 10774 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 10775 | |
| 10776 | StaticSocketDataProvider data_refused; |
| 10777 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 10778 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 10779 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10780 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10781 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10782 | session->http_server_properties(); |
| 10783 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10784 | // Set up two QUIC alternative services for server. |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10785 | AlternativeServiceInfoVector alternative_service_info_vector; |
| 10786 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 10787 | |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10788 | AlternativeService alternative_service1(kProtoQUIC, alternative1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10789 | alternative_service_info_vector.push_back( |
| 10790 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 10791 | alternative_service1, expiration, |
| 10792 | session->params().quic_supported_versions)); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10793 | AlternativeService alternative_service2(kProtoQUIC, alternative2); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10794 | alternative_service_info_vector.push_back( |
| 10795 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 10796 | alternative_service2, expiration, |
| 10797 | session->params().quic_supported_versions)); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10798 | |
| 10799 | http_server_properties->SetAlternativeServices( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10800 | server, alternative_service_info_vector); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10801 | |
| 10802 | // Mark one of the QUIC alternative service as broken. |
| 10803 | http_server_properties->MarkAlternativeServiceBroken(alternative_service1); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10804 | EXPECT_EQ(2u, |
| 10805 | http_server_properties->GetAlternativeServiceInfos(server).size()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10806 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10807 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 10808 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10809 | request.method = "GET"; |
| 10810 | request.url = GURL(origin_url); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10811 | TestCompletionCallback callback; |
| 10812 | NetErrorDetails details; |
| 10813 | EXPECT_FALSE(details.quic_broken); |
| 10814 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10815 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10816 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10817 | EXPECT_FALSE(details.quic_broken); |
| 10818 | } |
| 10819 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10820 | TEST_F(HttpNetworkTransactionTest, MarkBrokenAlternateProtocolAndFallback) { |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10821 | HttpRequestInfo request; |
| 10822 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10823 | request.url = GURL("https://www.example.org/"); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10824 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10825 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10826 | StaticSocketDataProvider first_data; |
| 10827 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10828 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10829 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10830 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10831 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10832 | |
| 10833 | MockRead data_reads[] = { |
| 10834 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10835 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10836 | MockRead(ASYNC, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10837 | }; |
| 10838 | StaticSocketDataProvider second_data( |
| 10839 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10840 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10841 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10842 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10843 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10844 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10845 | session->http_server_properties(); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10846 | const url::SchemeHostPort server(request.url); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10847 | // Port must be < 1024, or the header will be ignored (since initial port was |
| 10848 | // port 80 (another restricted port). |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10849 | // Port is ignored by MockConnect anyway. |
| 10850 | const AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 10851 | 666); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10852 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10853 | http_server_properties->SetHttp2AlternativeService( |
| 10854 | server, alternative_service, expiration); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10855 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10856 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10857 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10858 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10859 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10860 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10861 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10862 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10863 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10864 | ASSERT_TRUE(response); |
| 10865 | ASSERT_TRUE(response->headers); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10866 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10867 | |
| 10868 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10869 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10870 | EXPECT_EQ("hello world", response_data); |
| 10871 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10872 | const AlternativeServiceInfoVector alternative_service_info_vector = |
| 10873 | http_server_properties->GetAlternativeServiceInfos(server); |
| 10874 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 10875 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 10876 | alternative_service_info_vector[0].alternative_service()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10877 | EXPECT_TRUE( |
| 10878 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10879 | } |
| 10880 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10881 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10882 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10883 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10884 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10885 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedBlocked) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10886 | HttpRequestInfo restricted_port_request; |
| 10887 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10888 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10889 | restricted_port_request.load_flags = 0; |
| 10890 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10891 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10892 | StaticSocketDataProvider first_data; |
| 10893 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10894 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10895 | |
| 10896 | MockRead data_reads[] = { |
| 10897 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10898 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10899 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10900 | }; |
| 10901 | StaticSocketDataProvider second_data( |
| 10902 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10903 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10904 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10905 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10906 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10907 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10908 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10909 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10910 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10911 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10912 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10913 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 10914 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10915 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10916 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10917 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10918 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10919 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10920 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10921 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10922 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10923 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 10924 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10925 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10926 | // Invalid change to unrestricted port should fail. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10927 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_REFUSED)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10928 | } |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10929 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10930 | // Ensure that we are allowed to redirect traffic via an alternate protocol to |
| 10931 | // an unrestricted (port >= 1024) when the original traffic was on a restricted |
| 10932 | // port (port < 1024) if we set |enable_user_alternate_protocol_ports|. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10933 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedPermitted) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10934 | session_deps_.enable_user_alternate_protocol_ports = true; |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10935 | |
| 10936 | HttpRequestInfo restricted_port_request; |
| 10937 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10938 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10939 | restricted_port_request.load_flags = 0; |
| 10940 | |
| 10941 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10942 | StaticSocketDataProvider first_data; |
| 10943 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10944 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10945 | |
| 10946 | MockRead data_reads[] = { |
| 10947 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10948 | MockRead("hello world"), |
| 10949 | MockRead(ASYNC, OK), |
| 10950 | }; |
| 10951 | StaticSocketDataProvider second_data( |
| 10952 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10953 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10954 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10955 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10956 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10957 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10958 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10959 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10960 | HttpServerProperties* http_server_properties = |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10961 | session->http_server_properties(); |
| 10962 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10963 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 10964 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10965 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10966 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10967 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10968 | expiration); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10969 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10970 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10971 | TestCompletionCallback callback; |
| 10972 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10973 | EXPECT_EQ(ERR_IO_PENDING, |
| 10974 | trans.Start(&restricted_port_request, callback.callback(), |
| 10975 | NetLogWithSource())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10976 | // Change to unrestricted port should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10977 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10978 | } |
| 10979 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10980 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10981 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10982 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10983 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10984 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedAllowed) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10985 | HttpRequestInfo restricted_port_request; |
| 10986 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10987 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10988 | restricted_port_request.load_flags = 0; |
| 10989 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10990 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10991 | StaticSocketDataProvider first_data; |
| 10992 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10993 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10994 | |
| 10995 | MockRead data_reads[] = { |
| 10996 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10997 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10998 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10999 | }; |
| 11000 | StaticSocketDataProvider second_data( |
| 11001 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11002 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11003 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11004 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 11005 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11006 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11007 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11008 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11009 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11010 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11011 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11012 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11013 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11014 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11015 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11016 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11017 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11018 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11019 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11020 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11021 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11022 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 11023 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11024 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11025 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11026 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11027 | } |
| 11028 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11029 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 11030 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 11031 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 11032 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11033 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed1) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11034 | HttpRequestInfo unrestricted_port_request; |
| 11035 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11036 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11037 | unrestricted_port_request.load_flags = 0; |
| 11038 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11039 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11040 | StaticSocketDataProvider first_data; |
| 11041 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11042 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11043 | |
| 11044 | MockRead data_reads[] = { |
| 11045 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11046 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11047 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11048 | }; |
| 11049 | StaticSocketDataProvider second_data( |
| 11050 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11051 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11052 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11053 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11054 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11055 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11056 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11057 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11058 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11059 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11060 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11061 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11062 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11063 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11064 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11065 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11066 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11067 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11068 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11069 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11070 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11071 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11072 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11073 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11074 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11075 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11076 | } |
| 11077 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11078 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 11079 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 11080 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 11081 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11082 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed2) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11083 | HttpRequestInfo unrestricted_port_request; |
| 11084 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11085 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11086 | unrestricted_port_request.load_flags = 0; |
| 11087 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11088 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11089 | StaticSocketDataProvider first_data; |
| 11090 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11091 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11092 | |
| 11093 | MockRead data_reads[] = { |
| 11094 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11095 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11096 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11097 | }; |
| 11098 | StaticSocketDataProvider second_data( |
| 11099 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11100 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11101 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11102 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 11103 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11104 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11105 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11106 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11107 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11108 | session->http_server_properties(); |
bnc | 0bbb0262 | 2015-07-23 10:06:22 | [diff] [blame] | 11109 | const int kUnrestrictedAlternatePort = 1025; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11110 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11111 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11112 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11113 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11114 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11115 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11116 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11117 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11118 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11119 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11120 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11121 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11122 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11123 | // Valid change to an unrestricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11124 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11125 | } |
| 11126 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11127 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 11128 | // to an unsafe port, and that we resume the second HttpStreamFactoryImpl::Job |
| 11129 | // once the alternate protocol request fails. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11130 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) { |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11131 | HttpRequestInfo request; |
| 11132 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11133 | request.url = GURL("http://www.example.org/"); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11134 | |
| 11135 | // The alternate protocol request will error out before we attempt to connect, |
| 11136 | // so only the standard HTTP request will try to connect. |
| 11137 | MockRead data_reads[] = { |
| 11138 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11139 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11140 | MockRead(ASYNC, OK), |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11141 | }; |
| 11142 | StaticSocketDataProvider data( |
| 11143 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11144 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11145 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11146 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11147 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11148 | HttpServerProperties* http_server_properties = |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11149 | session->http_server_properties(); |
| 11150 | const int kUnsafePort = 7; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11151 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11152 | kUnsafePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11153 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11154 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11155 | url::SchemeHostPort(request.url), alternative_service, expiration); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11156 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11157 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11158 | TestCompletionCallback callback; |
| 11159 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11160 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11161 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11162 | // The HTTP request should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11163 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11164 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11165 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11166 | ASSERT_TRUE(response); |
| 11167 | ASSERT_TRUE(response->headers); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11168 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11169 | |
| 11170 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11171 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11172 | EXPECT_EQ("hello world", response_data); |
| 11173 | } |
| 11174 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11175 | TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11176 | HttpRequestInfo request; |
| 11177 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11178 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11179 | |
| 11180 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11181 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11182 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11183 | MockRead("\r\n"), |
| 11184 | MockRead("hello world"), |
| 11185 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11186 | MockRead(ASYNC, OK)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11187 | |
| 11188 | StaticSocketDataProvider first_transaction( |
| 11189 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11190 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11191 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11192 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11193 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11194 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11195 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11196 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11197 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11198 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11199 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11200 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 11201 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11202 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11203 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11204 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11205 | }; |
| 11206 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11207 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11208 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11209 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11210 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11211 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11212 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 11213 | NULL, 0, NULL, 0); |
| 11214 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 11215 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11216 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11217 | &hanging_non_alternate_protocol_socket); |
| 11218 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11219 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11220 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11221 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11222 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11223 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11224 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11225 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11226 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11227 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11228 | |
| 11229 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11230 | ASSERT_TRUE(response); |
| 11231 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11232 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11233 | |
| 11234 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11235 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11236 | EXPECT_EQ("hello world", response_data); |
| 11237 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11238 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11239 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11240 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11241 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11242 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11243 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11244 | |
| 11245 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11246 | ASSERT_TRUE(response); |
| 11247 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11248 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11249 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11250 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11251 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11252 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11253 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11254 | } |
| 11255 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11256 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11257 | HttpRequestInfo request; |
| 11258 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11259 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11260 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11261 | // First transaction receives Alt-Svc header over HTTP/1.1. |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11262 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11263 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11264 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11265 | MockRead("\r\n"), |
| 11266 | MockRead("hello world"), |
| 11267 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11268 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11269 | }; |
| 11270 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11271 | StaticSocketDataProvider http11_data(data_reads, arraysize(data_reads), NULL, |
| 11272 | 0); |
| 11273 | session_deps_.socket_factory->AddSocketDataProvider(&http11_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11274 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11275 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 11276 | ssl_http11.cert = ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11277 | ASSERT_TRUE(ssl_http11.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11278 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
| 11279 | |
| 11280 | // Second transaction starts an alternative and a non-alternative Job. |
| 11281 | // Both sockets hang. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11282 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 11283 | StaticSocketDataProvider hanging_socket1(NULL, 0, NULL, 0); |
| 11284 | hanging_socket1.set_connect_data(never_finishing_connect); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 11285 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket1); |
| 11286 | |
| 11287 | StaticSocketDataProvider hanging_socket2(NULL, 0, NULL, 0); |
| 11288 | hanging_socket2.set_connect_data(never_finishing_connect); |
| 11289 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket2); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11290 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11291 | // Third transaction starts an alternative and a non-alternative job. |
| 11292 | // The non-alternative job hangs, but the alternative one succeeds. |
| 11293 | // The second transaction, still pending, binds to this socket. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11294 | SpdySerializedFrame req1( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11295 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11296 | SpdySerializedFrame req2( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11297 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 3, LOWEST)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11298 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11299 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 1), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11300 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 11301 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11302 | SpdySerializedFrame data1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 11303 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11304 | SpdySerializedFrame data2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11305 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11306 | CreateMockRead(resp1, 2), CreateMockRead(data1, 3), |
| 11307 | CreateMockRead(resp2, 4), CreateMockRead(data2, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11308 | MockRead(ASYNC, 0, 6), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11309 | }; |
| 11310 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11311 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11312 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11313 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11314 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11315 | AddSSLSocketData(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11316 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 11317 | StaticSocketDataProvider hanging_socket3(NULL, 0, NULL, 0); |
| 11318 | hanging_socket3.set_connect_data(never_finishing_connect); |
| 11319 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket3); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11320 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11321 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11322 | TestCompletionCallback callback1; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11323 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11324 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11325 | int rv = trans1.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11326 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11327 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11328 | |
| 11329 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11330 | ASSERT_TRUE(response); |
| 11331 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11332 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11333 | |
| 11334 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11335 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11336 | EXPECT_EQ("hello world", response_data); |
| 11337 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11338 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11339 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11340 | rv = trans2.Start(&request, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11341 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11342 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11343 | TestCompletionCallback callback3; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11344 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11345 | rv = trans3.Start(&request, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11346 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11347 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11348 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
| 11349 | EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11350 | |
| 11351 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11352 | ASSERT_TRUE(response); |
| 11353 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11354 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11355 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11356 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11357 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11358 | EXPECT_EQ("hello!", response_data); |
| 11359 | |
| 11360 | response = trans3.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11361 | ASSERT_TRUE(response); |
| 11362 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11363 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11364 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11365 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11366 | ASSERT_THAT(ReadTransaction(&trans3, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11367 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11368 | } |
| 11369 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11370 | TEST_F(HttpNetworkTransactionTest, StallAlternativeServiceForNpnSpdy) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11371 | HttpRequestInfo request; |
| 11372 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11373 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11374 | |
| 11375 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11376 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11377 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11378 | MockRead("\r\n"), |
| 11379 | MockRead("hello world"), |
| 11380 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11381 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11382 | }; |
| 11383 | |
| 11384 | StaticSocketDataProvider first_transaction( |
| 11385 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11386 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11387 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11388 | SSLSocketDataProvider ssl(ASYNC, OK); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 11389 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11390 | ASSERT_TRUE(ssl.cert); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11391 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11392 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11393 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11394 | StaticSocketDataProvider hanging_alternate_protocol_socket( |
| 11395 | NULL, 0, NULL, 0); |
| 11396 | hanging_alternate_protocol_socket.set_connect_data( |
| 11397 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11398 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11399 | &hanging_alternate_protocol_socket); |
| 11400 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11401 | // 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] | 11402 | StaticSocketDataProvider second_transaction(data_reads, arraysize(data_reads), |
| 11403 | NULL, 0); |
| 11404 | session_deps_.socket_factory->AddSocketDataProvider(&second_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11405 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11406 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11407 | TestCompletionCallback callback; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11408 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11409 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11410 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11411 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11412 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11413 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11414 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11415 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11416 | |
| 11417 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11418 | ASSERT_TRUE(response); |
| 11419 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11420 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11421 | |
| 11422 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11423 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11424 | EXPECT_EQ("hello world", response_data); |
| 11425 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11426 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11427 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11428 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11429 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11430 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11431 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11432 | |
| 11433 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11434 | ASSERT_TRUE(response); |
| 11435 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11436 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11437 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11438 | EXPECT_FALSE(response->was_alpn_negotiated); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11439 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11440 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11441 | EXPECT_EQ("hello world", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11442 | } |
| 11443 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11444 | class CapturingProxyResolver : public ProxyResolver { |
| 11445 | public: |
sammc | e90c921 | 2015-05-27 23:43:35 | [diff] [blame] | 11446 | CapturingProxyResolver() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11447 | ~CapturingProxyResolver() override {} |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11448 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11449 | int GetProxyForURL(const GURL& url, |
| 11450 | ProxyInfo* results, |
| 11451 | const CompletionCallback& callback, |
maksim.sisov | 7e15726 | 2016-10-20 11:19:55 | [diff] [blame] | 11452 | std::unique_ptr<Request>* request, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11453 | const NetLogWithSource& net_log) override { |
[email protected] | fae7669f | 2010-08-02 21:49:40 | [diff] [blame] | 11454 | ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, |
| 11455 | HostPortPair("myproxy", 80)); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11456 | results->UseProxyServer(proxy_server); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11457 | resolved_.push_back(url); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11458 | return OK; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11459 | } |
| 11460 | |
[email protected] | 2447640 | 2010-07-20 20:55:17 | [diff] [blame] | 11461 | const std::vector<GURL>& resolved() const { return resolved_; } |
| 11462 | |
| 11463 | private: |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11464 | std::vector<GURL> resolved_; |
| 11465 | |
| 11466 | DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); |
| 11467 | }; |
| 11468 | |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 11469 | class CapturingProxyResolverFactory : public ProxyResolverFactory { |
| 11470 | public: |
| 11471 | explicit CapturingProxyResolverFactory(CapturingProxyResolver* resolver) |
| 11472 | : ProxyResolverFactory(false), resolver_(resolver) {} |
| 11473 | |
| 11474 | int CreateProxyResolver( |
| 11475 | const scoped_refptr<ProxyResolverScriptData>& pac_script, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11476 | std::unique_ptr<ProxyResolver>* resolver, |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 11477 | const net::CompletionCallback& callback, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11478 | std::unique_ptr<Request>* request) override { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11479 | *resolver = std::make_unique<ForwardingProxyResolver>(resolver_); |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 11480 | return OK; |
| 11481 | } |
| 11482 | |
| 11483 | private: |
| 11484 | ProxyResolver* resolver_; |
| 11485 | }; |
| 11486 | |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11487 | // Test that proxy is resolved using the origin url, |
| 11488 | // regardless of the alternative server. |
| 11489 | TEST_F(HttpNetworkTransactionTest, UseOriginNotAlternativeForProxy) { |
| 11490 | // Configure proxy to bypass www.example.org, which is the origin URL. |
| 11491 | ProxyConfig proxy_config; |
| 11492 | proxy_config.proxy_rules().ParseFromString("myproxy:70"); |
| 11493 | proxy_config.proxy_rules().bypass_rules.AddRuleFromString("www.example.org"); |
| 11494 | auto proxy_config_service = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11495 | std::make_unique<ProxyConfigServiceFixed>(proxy_config); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11496 | |
| 11497 | CapturingProxyResolver capturing_proxy_resolver; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11498 | auto proxy_resolver_factory = std::make_unique<CapturingProxyResolverFactory>( |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11499 | &capturing_proxy_resolver); |
| 11500 | |
| 11501 | TestNetLog net_log; |
| 11502 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11503 | session_deps_.proxy_service = std::make_unique<ProxyService>( |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11504 | std::move(proxy_config_service), std::move(proxy_resolver_factory), |
| 11505 | &net_log); |
| 11506 | |
| 11507 | session_deps_.net_log = &net_log; |
| 11508 | |
| 11509 | // Configure alternative service with a hostname that is not bypassed by the |
| 11510 | // proxy. |
| 11511 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11512 | HttpServerProperties* http_server_properties = |
| 11513 | session->http_server_properties(); |
| 11514 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 11515 | HostPortPair alternative("www.example.com", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11516 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11517 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11518 | http_server_properties->SetHttp2AlternativeService( |
| 11519 | server, alternative_service, expiration); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11520 | |
| 11521 | // Non-alternative job should hang. |
| 11522 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
| 11523 | StaticSocketDataProvider hanging_alternate_protocol_socket(nullptr, 0, |
| 11524 | nullptr, 0); |
| 11525 | hanging_alternate_protocol_socket.set_connect_data(never_finishing_connect); |
| 11526 | session_deps_.socket_factory->AddSocketDataProvider( |
| 11527 | &hanging_alternate_protocol_socket); |
| 11528 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11529 | AddSSLSocketData(); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11530 | |
| 11531 | HttpRequestInfo request; |
| 11532 | request.method = "GET"; |
| 11533 | request.url = GURL("https://www.example.org/"); |
| 11534 | request.load_flags = 0; |
| 11535 | |
| 11536 | SpdySerializedFrame req( |
| 11537 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
| 11538 | |
| 11539 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
| 11540 | |
| 11541 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 11542 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 11543 | MockRead spdy_reads[] = { |
| 11544 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
| 11545 | }; |
| 11546 | |
| 11547 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11548 | arraysize(spdy_writes)); |
| 11549 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 11550 | |
| 11551 | TestCompletionCallback callback; |
| 11552 | |
| 11553 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 11554 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11555 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11556 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 11557 | |
| 11558 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 11559 | ASSERT_TRUE(response); |
| 11560 | ASSERT_TRUE(response->headers); |
| 11561 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 11562 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11563 | EXPECT_TRUE(response->was_alpn_negotiated); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11564 | |
| 11565 | std::string response_data; |
| 11566 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 11567 | EXPECT_EQ("hello!", response_data); |
| 11568 | |
| 11569 | // Origin host bypasses proxy, no resolution should have happened. |
| 11570 | ASSERT_TRUE(capturing_proxy_resolver.resolved().empty()); |
| 11571 | } |
| 11572 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11573 | TEST_F(HttpNetworkTransactionTest, UseAlternativeServiceForTunneledNpnSpdy) { |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11574 | ProxyConfig proxy_config; |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11575 | proxy_config.set_auto_detect(true); |
| 11576 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 11577 | |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11578 | CapturingProxyResolver capturing_proxy_resolver; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11579 | session_deps_.proxy_service = std::make_unique<ProxyService>( |
| 11580 | std::make_unique<ProxyConfigServiceFixed>(proxy_config), |
| 11581 | std::make_unique<CapturingProxyResolverFactory>( |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11582 | &capturing_proxy_resolver), |
| 11583 | nullptr); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11584 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11585 | session_deps_.net_log = &net_log; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11586 | |
| 11587 | HttpRequestInfo request; |
| 11588 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11589 | request.url = GURL("https://www.example.org/"); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11590 | |
| 11591 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11592 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11593 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11594 | MockRead("\r\n"), |
| 11595 | MockRead("hello world"), |
| 11596 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11597 | MockRead(ASYNC, OK), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11598 | }; |
| 11599 | |
| 11600 | StaticSocketDataProvider first_transaction( |
| 11601 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11602 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11603 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11604 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11605 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11606 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11607 | AddSSLSocketData(); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11608 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11609 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11610 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11611 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11612 | MockWrite(ASYNC, 0, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11613 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 11614 | "Host: www.example.org:443\r\n" |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11615 | "Proxy-Connection: keep-alive\r\n\r\n"), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11616 | CreateMockWrite(req, 2), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11617 | }; |
| 11618 | |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11619 | const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 11620 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 11621 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11622 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11623 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11624 | MockRead(ASYNC, 1, kCONNECTResponse), CreateMockRead(resp, 3), |
| 11625 | CreateMockRead(data, 4), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11626 | }; |
| 11627 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11628 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11629 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11630 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11631 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11632 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11633 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 11634 | NULL, 0, NULL, 0); |
| 11635 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 11636 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11637 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11638 | &hanging_non_alternate_protocol_socket); |
| 11639 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11640 | TestCompletionCallback callback; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11641 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11642 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11643 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11644 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11645 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11646 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 11647 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11648 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 11649 | |
| 11650 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 11651 | ASSERT_TRUE(response); |
| 11652 | ASSERT_TRUE(response->headers); |
| 11653 | EXPECT_EQ("HTTP/0.9 200 OK", response->headers->GetStatusLine()); |
| 11654 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11655 | EXPECT_TRUE(response->was_alpn_negotiated); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 11656 | |
| 11657 | std::string response_data; |
| 11658 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 11659 | EXPECT_EQ("hello world", response_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11660 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11661 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11662 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11663 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11664 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11665 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11666 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11667 | |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 11668 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11669 | ASSERT_TRUE(response); |
| 11670 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11671 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11672 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11673 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11674 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11675 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11676 | EXPECT_EQ("hello!", response_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11677 | ASSERT_EQ(2u, capturing_proxy_resolver.resolved().size()); |
| 11678 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11679 | capturing_proxy_resolver.resolved()[0].spec()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11680 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11681 | capturing_proxy_resolver.resolved()[1].spec()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11682 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11683 | LoadTimingInfo load_timing_info; |
| 11684 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 11685 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11686 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11687 | } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11688 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11689 | TEST_F(HttpNetworkTransactionTest, |
bnc | 1c196c6e | 2016-05-28 13:51:48 | [diff] [blame] | 11690 | UseAlternativeServiceForNpnSpdyWithExistingSpdySession) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11691 | HttpRequestInfo request; |
| 11692 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11693 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11694 | |
| 11695 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11696 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11697 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11698 | MockRead("\r\n"), |
| 11699 | MockRead("hello world"), |
| 11700 | MockRead(ASYNC, OK), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11701 | }; |
| 11702 | |
| 11703 | StaticSocketDataProvider first_transaction( |
| 11704 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11705 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11706 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11707 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11708 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11709 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11710 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11711 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11712 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11713 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11714 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11715 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 11716 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11717 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11718 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11719 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11720 | }; |
| 11721 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11722 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11723 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11724 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11725 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 11726 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11727 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11728 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11729 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11730 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11731 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11732 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11733 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11734 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11735 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11736 | |
| 11737 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11738 | ASSERT_TRUE(response); |
| 11739 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11740 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11741 | |
| 11742 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11743 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11744 | EXPECT_EQ("hello world", response_data); |
| 11745 | |
| 11746 | // Set up an initial SpdySession in the pool to reuse. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11747 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 11748 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 11749 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 11750 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 11751 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 11752 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11753 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11754 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11755 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11756 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11757 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11758 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11759 | |
| 11760 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11761 | ASSERT_TRUE(response); |
| 11762 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11763 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11764 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11765 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11766 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11767 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11768 | EXPECT_EQ("hello!", response_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11769 | } |
| 11770 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11771 | // GenerateAuthToken is a mighty big test. |
| 11772 | // It tests all permutation of GenerateAuthToken behavior: |
| 11773 | // - Synchronous and Asynchronous completion. |
| 11774 | // - OK or error on completion. |
| 11775 | // - Direct connection, non-authenticating proxy, and authenticating proxy. |
| 11776 | // - HTTP or HTTPS backend (to include proxy tunneling). |
| 11777 | // - Non-authenticating and authenticating backend. |
| 11778 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 11779 | // In all, there are 44 reasonable permuations (for example, if there are |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11780 | // problems generating an auth token for an authenticating proxy, we don't |
| 11781 | // need to test all permutations of the backend server). |
| 11782 | // |
| 11783 | // The test proceeds by going over each of the configuration cases, and |
| 11784 | // potentially running up to three rounds in each of the tests. The TestConfig |
| 11785 | // specifies both the configuration for the test as well as the expectations |
| 11786 | // for the results. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11787 | TEST_F(HttpNetworkTransactionTest, GenerateAuthToken) { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11788 | static const char kServer[] = "http://www.example.com"; |
| 11789 | static const char kSecureServer[] = "https://www.example.com"; |
| 11790 | static const char kProxy[] = "myproxy:70"; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11791 | |
| 11792 | enum AuthTiming { |
| 11793 | AUTH_NONE, |
| 11794 | AUTH_SYNC, |
| 11795 | AUTH_ASYNC, |
| 11796 | }; |
| 11797 | |
| 11798 | const MockWrite kGet( |
| 11799 | "GET / HTTP/1.1\r\n" |
| 11800 | "Host: www.example.com\r\n" |
| 11801 | "Connection: keep-alive\r\n\r\n"); |
| 11802 | const MockWrite kGetProxy( |
| 11803 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11804 | "Host: www.example.com\r\n" |
| 11805 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 11806 | const MockWrite kGetAuth( |
| 11807 | "GET / HTTP/1.1\r\n" |
| 11808 | "Host: www.example.com\r\n" |
| 11809 | "Connection: keep-alive\r\n" |
| 11810 | "Authorization: auth_token\r\n\r\n"); |
| 11811 | const MockWrite kGetProxyAuth( |
| 11812 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11813 | "Host: www.example.com\r\n" |
| 11814 | "Proxy-Connection: keep-alive\r\n" |
| 11815 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 11816 | const MockWrite kGetAuthThroughProxy( |
| 11817 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11818 | "Host: www.example.com\r\n" |
| 11819 | "Proxy-Connection: keep-alive\r\n" |
| 11820 | "Authorization: auth_token\r\n\r\n"); |
| 11821 | const MockWrite kGetAuthWithProxyAuth( |
| 11822 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11823 | "Host: www.example.com\r\n" |
| 11824 | "Proxy-Connection: keep-alive\r\n" |
| 11825 | "Proxy-Authorization: auth_token\r\n" |
| 11826 | "Authorization: auth_token\r\n\r\n"); |
| 11827 | const MockWrite kConnect( |
| 11828 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 11829 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11830 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 11831 | const MockWrite kConnectProxyAuth( |
| 11832 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 11833 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11834 | "Proxy-Connection: keep-alive\r\n" |
| 11835 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 11836 | |
| 11837 | const MockRead kSuccess( |
| 11838 | "HTTP/1.1 200 OK\r\n" |
| 11839 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11840 | "Content-Length: 3\r\n\r\n" |
| 11841 | "Yes"); |
| 11842 | const MockRead kFailure( |
| 11843 | "Should not be called."); |
| 11844 | const MockRead kServerChallenge( |
| 11845 | "HTTP/1.1 401 Unauthorized\r\n" |
| 11846 | "WWW-Authenticate: Mock realm=server\r\n" |
| 11847 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11848 | "Content-Length: 14\r\n\r\n" |
| 11849 | "Unauthorized\r\n"); |
| 11850 | const MockRead kProxyChallenge( |
| 11851 | "HTTP/1.1 407 Unauthorized\r\n" |
| 11852 | "Proxy-Authenticate: Mock realm=proxy\r\n" |
| 11853 | "Proxy-Connection: close\r\n" |
| 11854 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11855 | "Content-Length: 14\r\n\r\n" |
| 11856 | "Unauthorized\r\n"); |
| 11857 | const MockRead kProxyConnected( |
| 11858 | "HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 11859 | |
| 11860 | // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with |
| 11861 | // no constructors, but the C++ compiler on Windows warns about |
| 11862 | // unspecified data in compound literals. So, moved to using constructors, |
| 11863 | // and TestRound's created with the default constructor should not be used. |
| 11864 | struct TestRound { |
| 11865 | TestRound() |
| 11866 | : expected_rv(ERR_UNEXPECTED), |
| 11867 | extra_write(NULL), |
| 11868 | extra_read(NULL) { |
| 11869 | } |
| 11870 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 11871 | int expected_rv_arg) |
| 11872 | : write(write_arg), |
| 11873 | read(read_arg), |
| 11874 | expected_rv(expected_rv_arg), |
| 11875 | extra_write(NULL), |
| 11876 | extra_read(NULL) { |
| 11877 | } |
| 11878 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 11879 | int expected_rv_arg, const MockWrite* extra_write_arg, |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 11880 | const MockRead* extra_read_arg) |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11881 | : write(write_arg), |
| 11882 | read(read_arg), |
| 11883 | expected_rv(expected_rv_arg), |
| 11884 | extra_write(extra_write_arg), |
| 11885 | extra_read(extra_read_arg) { |
| 11886 | } |
| 11887 | MockWrite write; |
| 11888 | MockRead read; |
| 11889 | int expected_rv; |
| 11890 | const MockWrite* extra_write; |
| 11891 | const MockRead* extra_read; |
| 11892 | }; |
| 11893 | |
| 11894 | static const int kNoSSL = 500; |
| 11895 | |
| 11896 | struct TestConfig { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11897 | int line_number; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 11898 | const char* const proxy_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11899 | AuthTiming proxy_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11900 | int first_generate_proxy_token_rv; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 11901 | const char* const server_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11902 | AuthTiming server_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11903 | int first_generate_server_token_rv; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11904 | int num_auth_rounds; |
| 11905 | int first_ssl_round; |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11906 | TestRound rounds[4]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11907 | } test_configs[] = { |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11908 | // Non-authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11909 | {__LINE__, |
| 11910 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11911 | AUTH_NONE, |
| 11912 | OK, |
| 11913 | kServer, |
| 11914 | AUTH_NONE, |
| 11915 | OK, |
| 11916 | 1, |
| 11917 | kNoSSL, |
| 11918 | {TestRound(kGet, kSuccess, OK)}}, |
| 11919 | // Authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11920 | {__LINE__, |
| 11921 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11922 | AUTH_NONE, |
| 11923 | OK, |
| 11924 | kServer, |
| 11925 | AUTH_SYNC, |
| 11926 | OK, |
| 11927 | 2, |
| 11928 | kNoSSL, |
| 11929 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11930 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11931 | {__LINE__, |
| 11932 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11933 | AUTH_NONE, |
| 11934 | OK, |
| 11935 | kServer, |
| 11936 | AUTH_SYNC, |
| 11937 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11938 | 3, |
| 11939 | kNoSSL, |
| 11940 | {TestRound(kGet, kServerChallenge, OK), |
| 11941 | TestRound(kGet, kServerChallenge, OK), |
| 11942 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11943 | {__LINE__, |
| 11944 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11945 | AUTH_NONE, |
| 11946 | OK, |
| 11947 | kServer, |
| 11948 | AUTH_SYNC, |
| 11949 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 11950 | 2, |
| 11951 | kNoSSL, |
| 11952 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11953 | {__LINE__, |
| 11954 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11955 | AUTH_NONE, |
| 11956 | OK, |
| 11957 | kServer, |
| 11958 | AUTH_SYNC, |
| 11959 | ERR_UNDOCUMENTED_SECURITY_LIBRARY_STATUS, |
| 11960 | 2, |
| 11961 | kNoSSL, |
| 11962 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11963 | {__LINE__, |
| 11964 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11965 | AUTH_SYNC, |
| 11966 | ERR_FAILED, |
| 11967 | kServer, |
| 11968 | AUTH_NONE, |
| 11969 | OK, |
| 11970 | 2, |
| 11971 | kNoSSL, |
| 11972 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 11973 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11974 | {__LINE__, |
| 11975 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11976 | AUTH_ASYNC, |
| 11977 | ERR_FAILED, |
| 11978 | kServer, |
| 11979 | AUTH_NONE, |
| 11980 | OK, |
| 11981 | 2, |
| 11982 | kNoSSL, |
| 11983 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 11984 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11985 | {__LINE__, |
| 11986 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11987 | AUTH_NONE, |
| 11988 | OK, |
| 11989 | kServer, |
| 11990 | AUTH_SYNC, |
| 11991 | ERR_FAILED, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11992 | 2, |
| 11993 | kNoSSL, |
| 11994 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11995 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11996 | {__LINE__, |
| 11997 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11998 | AUTH_NONE, |
| 11999 | OK, |
| 12000 | kServer, |
| 12001 | AUTH_ASYNC, |
| 12002 | ERR_FAILED, |
| 12003 | 2, |
| 12004 | kNoSSL, |
| 12005 | {TestRound(kGet, kServerChallenge, OK), |
| 12006 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12007 | {__LINE__, |
| 12008 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12009 | AUTH_NONE, |
| 12010 | OK, |
| 12011 | kServer, |
| 12012 | AUTH_ASYNC, |
| 12013 | OK, |
| 12014 | 2, |
| 12015 | kNoSSL, |
| 12016 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12017 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12018 | {__LINE__, |
| 12019 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12020 | AUTH_NONE, |
| 12021 | OK, |
| 12022 | kServer, |
| 12023 | AUTH_ASYNC, |
| 12024 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12025 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12026 | kNoSSL, |
| 12027 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12028 | // The second round uses a HttpAuthHandlerMock that always succeeds. |
| 12029 | TestRound(kGet, kServerChallenge, OK), |
| 12030 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12031 | // Non-authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12032 | {__LINE__, |
| 12033 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12034 | AUTH_NONE, |
| 12035 | OK, |
| 12036 | kServer, |
| 12037 | AUTH_NONE, |
| 12038 | OK, |
| 12039 | 1, |
| 12040 | kNoSSL, |
| 12041 | {TestRound(kGetProxy, kSuccess, OK)}}, |
| 12042 | // Authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12043 | {__LINE__, |
| 12044 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12045 | AUTH_NONE, |
| 12046 | OK, |
| 12047 | kServer, |
| 12048 | AUTH_SYNC, |
| 12049 | OK, |
| 12050 | 2, |
| 12051 | kNoSSL, |
| 12052 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12053 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12054 | {__LINE__, |
| 12055 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12056 | AUTH_NONE, |
| 12057 | OK, |
| 12058 | kServer, |
| 12059 | AUTH_SYNC, |
| 12060 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12061 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12062 | kNoSSL, |
| 12063 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12064 | TestRound(kGetProxy, kServerChallenge, OK), |
| 12065 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12066 | {__LINE__, |
| 12067 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12068 | AUTH_NONE, |
| 12069 | OK, |
| 12070 | kServer, |
| 12071 | AUTH_ASYNC, |
| 12072 | OK, |
| 12073 | 2, |
| 12074 | kNoSSL, |
| 12075 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12076 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12077 | {__LINE__, |
| 12078 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12079 | AUTH_NONE, |
| 12080 | OK, |
| 12081 | kServer, |
| 12082 | AUTH_ASYNC, |
| 12083 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12084 | 2, |
| 12085 | kNoSSL, |
| 12086 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12087 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12088 | // Non-authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12089 | {__LINE__, |
| 12090 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12091 | AUTH_SYNC, |
| 12092 | OK, |
| 12093 | kServer, |
| 12094 | AUTH_NONE, |
| 12095 | OK, |
| 12096 | 2, |
| 12097 | kNoSSL, |
| 12098 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12099 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12100 | {__LINE__, |
| 12101 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12102 | AUTH_SYNC, |
| 12103 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12104 | kServer, |
| 12105 | AUTH_NONE, |
| 12106 | OK, |
| 12107 | 2, |
| 12108 | kNoSSL, |
| 12109 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12110 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12111 | {__LINE__, |
| 12112 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12113 | AUTH_ASYNC, |
| 12114 | OK, |
| 12115 | kServer, |
| 12116 | AUTH_NONE, |
| 12117 | OK, |
| 12118 | 2, |
| 12119 | kNoSSL, |
| 12120 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12121 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12122 | {__LINE__, |
| 12123 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12124 | AUTH_ASYNC, |
| 12125 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12126 | kServer, |
| 12127 | AUTH_NONE, |
| 12128 | OK, |
| 12129 | 2, |
| 12130 | kNoSSL, |
| 12131 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12132 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12133 | {__LINE__, |
| 12134 | kProxy, |
| 12135 | AUTH_ASYNC, |
| 12136 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12137 | kServer, |
| 12138 | AUTH_NONE, |
| 12139 | OK, |
| 12140 | 3, |
| 12141 | kNoSSL, |
| 12142 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12143 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 12144 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12145 | // Authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12146 | {__LINE__, |
| 12147 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12148 | AUTH_SYNC, |
| 12149 | OK, |
| 12150 | kServer, |
| 12151 | AUTH_SYNC, |
| 12152 | OK, |
| 12153 | 3, |
| 12154 | kNoSSL, |
| 12155 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12156 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12157 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12158 | {__LINE__, |
| 12159 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12160 | AUTH_SYNC, |
| 12161 | OK, |
| 12162 | kServer, |
| 12163 | AUTH_SYNC, |
| 12164 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12165 | 3, |
| 12166 | kNoSSL, |
| 12167 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12168 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12169 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12170 | {__LINE__, |
| 12171 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12172 | AUTH_ASYNC, |
| 12173 | OK, |
| 12174 | kServer, |
| 12175 | AUTH_SYNC, |
| 12176 | OK, |
| 12177 | 3, |
| 12178 | kNoSSL, |
| 12179 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12180 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12181 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12182 | {__LINE__, |
| 12183 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12184 | AUTH_ASYNC, |
| 12185 | OK, |
| 12186 | kServer, |
| 12187 | AUTH_SYNC, |
| 12188 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12189 | 3, |
| 12190 | kNoSSL, |
| 12191 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12192 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12193 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12194 | {__LINE__, |
| 12195 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12196 | AUTH_SYNC, |
| 12197 | OK, |
| 12198 | kServer, |
| 12199 | AUTH_ASYNC, |
| 12200 | OK, |
| 12201 | 3, |
| 12202 | kNoSSL, |
| 12203 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12204 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12205 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12206 | {__LINE__, |
| 12207 | kProxy, |
| 12208 | AUTH_SYNC, |
| 12209 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12210 | kServer, |
| 12211 | AUTH_ASYNC, |
| 12212 | OK, |
| 12213 | 4, |
| 12214 | kNoSSL, |
| 12215 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12216 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 12217 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12218 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 12219 | {__LINE__, |
| 12220 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12221 | AUTH_SYNC, |
| 12222 | OK, |
| 12223 | kServer, |
| 12224 | AUTH_ASYNC, |
| 12225 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12226 | 3, |
| 12227 | kNoSSL, |
| 12228 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12229 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12230 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12231 | {__LINE__, |
| 12232 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12233 | AUTH_ASYNC, |
| 12234 | OK, |
| 12235 | kServer, |
| 12236 | AUTH_ASYNC, |
| 12237 | OK, |
| 12238 | 3, |
| 12239 | kNoSSL, |
| 12240 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12241 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12242 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
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 | kServer, |
| 12248 | AUTH_ASYNC, |
| 12249 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12250 | 3, |
| 12251 | kNoSSL, |
| 12252 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12253 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12254 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12255 | {__LINE__, |
| 12256 | kProxy, |
| 12257 | AUTH_ASYNC, |
| 12258 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12259 | kServer, |
| 12260 | AUTH_ASYNC, |
| 12261 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12262 | 4, |
| 12263 | kNoSSL, |
| 12264 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12265 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 12266 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12267 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12268 | // Non-authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12269 | {__LINE__, |
| 12270 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12271 | AUTH_NONE, |
| 12272 | OK, |
| 12273 | kSecureServer, |
| 12274 | AUTH_NONE, |
| 12275 | OK, |
| 12276 | 1, |
| 12277 | 0, |
| 12278 | {TestRound(kGet, kSuccess, OK)}}, |
| 12279 | // Authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12280 | {__LINE__, |
| 12281 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12282 | AUTH_NONE, |
| 12283 | OK, |
| 12284 | kSecureServer, |
| 12285 | AUTH_SYNC, |
| 12286 | OK, |
| 12287 | 2, |
| 12288 | 0, |
| 12289 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12290 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12291 | {__LINE__, |
| 12292 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12293 | AUTH_NONE, |
| 12294 | OK, |
| 12295 | kSecureServer, |
| 12296 | AUTH_SYNC, |
| 12297 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12298 | 2, |
| 12299 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12300 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12301 | {__LINE__, |
| 12302 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12303 | AUTH_NONE, |
| 12304 | OK, |
| 12305 | kSecureServer, |
| 12306 | AUTH_ASYNC, |
| 12307 | OK, |
| 12308 | 2, |
| 12309 | 0, |
| 12310 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12311 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12312 | {__LINE__, |
| 12313 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12314 | AUTH_NONE, |
| 12315 | OK, |
| 12316 | kSecureServer, |
| 12317 | AUTH_ASYNC, |
| 12318 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12319 | 2, |
| 12320 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12321 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12322 | // Non-authenticating HTTPS server with a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12323 | {__LINE__, |
| 12324 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12325 | AUTH_NONE, |
| 12326 | OK, |
| 12327 | kSecureServer, |
| 12328 | AUTH_NONE, |
| 12329 | OK, |
| 12330 | 1, |
| 12331 | 0, |
| 12332 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 12333 | // Authenticating HTTPS server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12334 | {__LINE__, |
| 12335 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12336 | AUTH_NONE, |
| 12337 | OK, |
| 12338 | kSecureServer, |
| 12339 | AUTH_SYNC, |
| 12340 | OK, |
| 12341 | 2, |
| 12342 | 0, |
| 12343 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12344 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12345 | {__LINE__, |
| 12346 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12347 | AUTH_NONE, |
| 12348 | OK, |
| 12349 | kSecureServer, |
| 12350 | AUTH_SYNC, |
| 12351 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12352 | 2, |
| 12353 | 0, |
| 12354 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12355 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12356 | {__LINE__, |
| 12357 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12358 | AUTH_NONE, |
| 12359 | OK, |
| 12360 | kSecureServer, |
| 12361 | AUTH_ASYNC, |
| 12362 | OK, |
| 12363 | 2, |
| 12364 | 0, |
| 12365 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12366 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12367 | {__LINE__, |
| 12368 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12369 | AUTH_NONE, |
| 12370 | OK, |
| 12371 | kSecureServer, |
| 12372 | AUTH_ASYNC, |
| 12373 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12374 | 2, |
| 12375 | 0, |
| 12376 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12377 | TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12378 | // Non-Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12379 | {__LINE__, |
| 12380 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12381 | AUTH_SYNC, |
| 12382 | OK, |
| 12383 | kSecureServer, |
| 12384 | AUTH_NONE, |
| 12385 | OK, |
| 12386 | 2, |
| 12387 | 1, |
| 12388 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12389 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12390 | {__LINE__, |
| 12391 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12392 | AUTH_SYNC, |
| 12393 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12394 | kSecureServer, |
| 12395 | AUTH_NONE, |
| 12396 | OK, |
| 12397 | 2, |
| 12398 | kNoSSL, |
| 12399 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12400 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12401 | {__LINE__, |
| 12402 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12403 | AUTH_SYNC, |
| 12404 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 12405 | kSecureServer, |
| 12406 | AUTH_NONE, |
| 12407 | OK, |
| 12408 | 2, |
| 12409 | kNoSSL, |
| 12410 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12411 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12412 | {__LINE__, |
| 12413 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12414 | AUTH_SYNC, |
| 12415 | ERR_UNEXPECTED, |
| 12416 | kSecureServer, |
| 12417 | AUTH_NONE, |
| 12418 | OK, |
| 12419 | 2, |
| 12420 | kNoSSL, |
| 12421 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12422 | TestRound(kConnect, kProxyConnected, ERR_UNEXPECTED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12423 | {__LINE__, |
| 12424 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12425 | AUTH_ASYNC, |
| 12426 | OK, |
| 12427 | kSecureServer, |
| 12428 | AUTH_NONE, |
| 12429 | OK, |
| 12430 | 2, |
| 12431 | 1, |
| 12432 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12433 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12434 | {__LINE__, |
| 12435 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12436 | AUTH_ASYNC, |
| 12437 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12438 | kSecureServer, |
| 12439 | AUTH_NONE, |
| 12440 | OK, |
| 12441 | 2, |
| 12442 | kNoSSL, |
| 12443 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12444 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12445 | // Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12446 | {__LINE__, |
| 12447 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12448 | AUTH_SYNC, |
| 12449 | OK, |
| 12450 | kSecureServer, |
| 12451 | AUTH_SYNC, |
| 12452 | OK, |
| 12453 | 3, |
| 12454 | 1, |
| 12455 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12456 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12457 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12458 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12459 | {__LINE__, |
| 12460 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12461 | AUTH_SYNC, |
| 12462 | OK, |
| 12463 | kSecureServer, |
| 12464 | AUTH_SYNC, |
| 12465 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12466 | 3, |
| 12467 | 1, |
| 12468 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12469 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12470 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12471 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12472 | {__LINE__, |
| 12473 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12474 | AUTH_ASYNC, |
| 12475 | OK, |
| 12476 | kSecureServer, |
| 12477 | AUTH_SYNC, |
| 12478 | OK, |
| 12479 | 3, |
| 12480 | 1, |
| 12481 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12482 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12483 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12484 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12485 | {__LINE__, |
| 12486 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12487 | AUTH_ASYNC, |
| 12488 | OK, |
| 12489 | kSecureServer, |
| 12490 | AUTH_SYNC, |
| 12491 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12492 | 3, |
| 12493 | 1, |
| 12494 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12495 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12496 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12497 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12498 | {__LINE__, |
| 12499 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12500 | AUTH_SYNC, |
| 12501 | OK, |
| 12502 | kSecureServer, |
| 12503 | AUTH_ASYNC, |
| 12504 | OK, |
| 12505 | 3, |
| 12506 | 1, |
| 12507 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12508 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12509 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12510 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12511 | {__LINE__, |
| 12512 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12513 | AUTH_SYNC, |
| 12514 | OK, |
| 12515 | kSecureServer, |
| 12516 | AUTH_ASYNC, |
| 12517 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12518 | 3, |
| 12519 | 1, |
| 12520 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12521 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12522 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12523 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12524 | {__LINE__, |
| 12525 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12526 | AUTH_ASYNC, |
| 12527 | OK, |
| 12528 | kSecureServer, |
| 12529 | AUTH_ASYNC, |
| 12530 | OK, |
| 12531 | 3, |
| 12532 | 1, |
| 12533 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12534 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12535 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12536 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12537 | {__LINE__, |
| 12538 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12539 | AUTH_ASYNC, |
| 12540 | OK, |
| 12541 | kSecureServer, |
| 12542 | AUTH_ASYNC, |
| 12543 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12544 | 3, |
| 12545 | 1, |
| 12546 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12547 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12548 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12549 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12550 | {__LINE__, |
| 12551 | kProxy, |
| 12552 | AUTH_ASYNC, |
| 12553 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12554 | kSecureServer, |
| 12555 | AUTH_ASYNC, |
| 12556 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12557 | 4, |
| 12558 | 2, |
| 12559 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12560 | TestRound(kConnect, kProxyChallenge, OK), |
| 12561 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12562 | &kServerChallenge), |
| 12563 | TestRound(kGet, kSuccess, OK)}}, |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12564 | }; |
| 12565 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12566 | for (const auto& test_config : test_configs) { |
| 12567 | SCOPED_TRACE(::testing::Message() << "Test config at " |
| 12568 | << test_config.line_number); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12569 | HttpAuthHandlerMock::Factory* auth_factory( |
| 12570 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12571 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 12572 | SSLInfo empty_ssl_info; |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 12573 | |
| 12574 | // Set up authentication handlers as necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12575 | if (test_config.proxy_auth_timing != AUTH_NONE) { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12576 | for (int n = 0; n < 3; n++) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12577 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 12578 | std::string auth_challenge = "Mock realm=proxy"; |
| 12579 | GURL origin(test_config.proxy_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 12580 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 12581 | auth_challenge.end()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12582 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12583 | empty_ssl_info, origin, |
| 12584 | NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12585 | auth_handler->SetGenerateExpectation( |
| 12586 | test_config.proxy_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12587 | n == 0 ? test_config.first_generate_proxy_token_rv : OK); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12588 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 12589 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12590 | } |
| 12591 | if (test_config.server_auth_timing != AUTH_NONE) { |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 12592 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12593 | std::string auth_challenge = "Mock realm=server"; |
| 12594 | GURL origin(test_config.server_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 12595 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 12596 | auth_challenge.end()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12597 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12598 | empty_ssl_info, origin, |
| 12599 | NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12600 | auth_handler->SetGenerateExpectation( |
| 12601 | test_config.server_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12602 | test_config.first_generate_server_token_rv); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12603 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12604 | |
| 12605 | // The second handler always succeeds. It should only be used where there |
| 12606 | // are multiple auth sessions for server auth in the same network |
| 12607 | // transaction using the same auth scheme. |
| 12608 | std::unique_ptr<HttpAuthHandlerMock> second_handler = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12609 | std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12610 | second_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 12611 | empty_ssl_info, origin, |
| 12612 | NetLogWithSource()); |
| 12613 | second_handler->SetGenerateExpectation(true, OK); |
| 12614 | auth_factory->AddMockHandler(second_handler.release(), |
| 12615 | HttpAuth::AUTH_SERVER); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12616 | } |
| 12617 | if (test_config.proxy_url) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12618 | session_deps_.proxy_service = |
| 12619 | ProxyService::CreateFixed(test_config.proxy_url); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12620 | } else { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12621 | session_deps_.proxy_service = ProxyService::CreateDirect(); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12622 | } |
| 12623 | |
| 12624 | HttpRequestInfo request; |
| 12625 | request.method = "GET"; |
| 12626 | request.url = GURL(test_config.server_url); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12627 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12628 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12629 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12630 | SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
| 12631 | |
| 12632 | std::vector<std::vector<MockRead>> mock_reads(1); |
| 12633 | std::vector<std::vector<MockWrite>> mock_writes(1); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12634 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 12635 | SCOPED_TRACE(round); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12636 | const TestRound& read_write_round = test_config.rounds[round]; |
| 12637 | |
| 12638 | // Set up expected reads and writes. |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12639 | mock_reads.back().push_back(read_write_round.read); |
| 12640 | mock_writes.back().push_back(read_write_round.write); |
| 12641 | |
| 12642 | // kProxyChallenge uses Proxy-Connection: close which means that the |
| 12643 | // socket is closed and a new one will be created for the next request. |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 12644 | if (read_write_round.read.data == kProxyChallenge.data) { |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12645 | mock_reads.push_back(std::vector<MockRead>()); |
| 12646 | mock_writes.push_back(std::vector<MockWrite>()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12647 | } |
| 12648 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12649 | if (read_write_round.extra_read) { |
| 12650 | mock_reads.back().push_back(*read_write_round.extra_read); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12651 | } |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12652 | if (read_write_round.extra_write) { |
| 12653 | mock_writes.back().push_back(*read_write_round.extra_write); |
| 12654 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12655 | |
| 12656 | // Add an SSL sequence if necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12657 | if (round >= test_config.first_ssl_round) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12658 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12659 | &ssl_socket_data_provider); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12660 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12661 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12662 | std::vector<std::unique_ptr<StaticSocketDataProvider>> data_providers; |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12663 | for (size_t i = 0; i < mock_reads.size(); ++i) { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12664 | data_providers.push_back(std::make_unique<StaticSocketDataProvider>( |
davidben | 5f8b6bc | 2015-11-25 03:19:54 | [diff] [blame] | 12665 | mock_reads[i].data(), mock_reads[i].size(), mock_writes[i].data(), |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12666 | mock_writes[i].size())); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12667 | session_deps_.socket_factory->AddSocketDataProvider( |
olli.raula | 525048c | 2015-12-10 07:38:32 | [diff] [blame] | 12668 | data_providers.back().get()); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12669 | } |
| 12670 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12671 | // Transaction must be created after DataProviders, so it's destroyed before |
| 12672 | // they are as well. |
| 12673 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 12674 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12675 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 12676 | SCOPED_TRACE(round); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12677 | const TestRound& read_write_round = test_config.rounds[round]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12678 | // Start or restart the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12679 | TestCompletionCallback callback; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12680 | int rv; |
| 12681 | if (round == 0) { |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12682 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12683 | } else { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12684 | rv = trans.RestartWithAuth( |
| 12685 | AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12686 | } |
| 12687 | if (rv == ERR_IO_PENDING) |
| 12688 | rv = callback.WaitForResult(); |
| 12689 | |
| 12690 | // Compare results with expected data. |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12691 | EXPECT_THAT(rv, IsError(read_write_round.expected_rv)); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12692 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | c0c82849 | 2015-05-15 01:25:55 | [diff] [blame] | 12693 | if (read_write_round.expected_rv != OK) { |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12694 | EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
| 12695 | continue; |
| 12696 | } |
| 12697 | if (round + 1 < test_config.num_auth_rounds) { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12698 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12699 | } else { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12700 | EXPECT_FALSE(response->auth_challenge); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12701 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12702 | } |
| 12703 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 12704 | } |
| 12705 | } |
| 12706 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12707 | TEST_F(HttpNetworkTransactionTest, MultiRoundAuth) { |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12708 | // Do multi-round authentication and make sure it works correctly. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12709 | HttpAuthHandlerMock::Factory* auth_factory( |
| 12710 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12711 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12712 | session_deps_.proxy_service = ProxyService::CreateDirect(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12713 | session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
| 12714 | session_deps_.host_resolver->set_synchronous_mode(true); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12715 | |
| 12716 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 12717 | auth_handler->set_connection_based(true); |
| 12718 | std::string auth_challenge = "Mock realm=server"; |
| 12719 | GURL origin("http://www.example.com"); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 12720 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 12721 | auth_challenge.end()); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 12722 | SSLInfo empty_ssl_info; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12723 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12724 | empty_ssl_info, origin, NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12725 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12726 | |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12727 | int rv = OK; |
| 12728 | const HttpResponseInfo* response = NULL; |
| 12729 | HttpRequestInfo request; |
| 12730 | request.method = "GET"; |
| 12731 | request.url = origin; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12732 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12733 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12734 | |
| 12735 | // Use a TCP Socket Pool with only one connection per group. This is used |
| 12736 | // to validate that the TCP socket is not released to the pool between |
| 12737 | // each round of multi-round authentication. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12738 | HttpNetworkSessionPeer session_peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12739 | TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12740 | 50, // Max sockets for pool |
| 12741 | 1, // Max sockets per group |
tbansal | 7b403bcc | 2016-04-13 22:33:21 | [diff] [blame] | 12742 | session_deps_.host_resolver.get(), session_deps_.socket_factory.get(), |
| 12743 | NULL, session_deps_.net_log); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12744 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 12745 | mock_pool_manager->SetTransportSocketPool(transport_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 12746 | session_peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12747 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12748 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12749 | TestCompletionCallback callback; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12750 | |
| 12751 | const MockWrite kGet( |
| 12752 | "GET / HTTP/1.1\r\n" |
| 12753 | "Host: www.example.com\r\n" |
| 12754 | "Connection: keep-alive\r\n\r\n"); |
| 12755 | const MockWrite kGetAuth( |
| 12756 | "GET / HTTP/1.1\r\n" |
| 12757 | "Host: www.example.com\r\n" |
| 12758 | "Connection: keep-alive\r\n" |
| 12759 | "Authorization: auth_token\r\n\r\n"); |
| 12760 | |
| 12761 | const MockRead kServerChallenge( |
| 12762 | "HTTP/1.1 401 Unauthorized\r\n" |
| 12763 | "WWW-Authenticate: Mock realm=server\r\n" |
| 12764 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12765 | "Content-Length: 14\r\n\r\n" |
| 12766 | "Unauthorized\r\n"); |
| 12767 | const MockRead kSuccess( |
| 12768 | "HTTP/1.1 200 OK\r\n" |
| 12769 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12770 | "Content-Length: 3\r\n\r\n" |
| 12771 | "Yes"); |
| 12772 | |
| 12773 | MockWrite writes[] = { |
| 12774 | // First round |
| 12775 | kGet, |
| 12776 | // Second round |
| 12777 | kGetAuth, |
| 12778 | // Third round |
| 12779 | kGetAuth, |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 12780 | // Fourth round |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12781 | kGetAuth, |
| 12782 | // Competing request |
| 12783 | kGet, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12784 | }; |
| 12785 | MockRead reads[] = { |
| 12786 | // First round |
| 12787 | kServerChallenge, |
| 12788 | // Second round |
| 12789 | kServerChallenge, |
| 12790 | // Third round |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 12791 | kServerChallenge, |
| 12792 | // Fourth round |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12793 | kSuccess, |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12794 | // Competing response |
| 12795 | kSuccess, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12796 | }; |
| 12797 | StaticSocketDataProvider data_provider(reads, arraysize(reads), |
| 12798 | writes, arraysize(writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12799 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12800 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 12801 | const char kSocketGroup[] = "www.example.com:80"; |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12802 | |
| 12803 | // First round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12804 | auth_handler->SetGenerateExpectation(false, OK); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12805 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12806 | if (rv == ERR_IO_PENDING) |
| 12807 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12808 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12809 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12810 | ASSERT_TRUE(response); |
| 12811 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12812 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12813 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 12814 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12815 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12816 | // In between rounds, another request comes in for the same domain. |
| 12817 | // It should not be able to grab the TCP socket that trans has already |
| 12818 | // claimed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12819 | HttpNetworkTransaction trans_compete(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12820 | TestCompletionCallback callback_compete; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12821 | rv = trans_compete.Start(&request, callback_compete.callback(), |
| 12822 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12823 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12824 | // callback_compete.WaitForResult at this point would stall forever, |
| 12825 | // since the HttpNetworkTransaction does not release the request back to |
| 12826 | // the pool until after authentication completes. |
| 12827 | |
| 12828 | // Second round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12829 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12830 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12831 | if (rv == ERR_IO_PENDING) |
| 12832 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12833 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12834 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12835 | ASSERT_TRUE(response); |
| 12836 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12837 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12838 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 12839 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12840 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12841 | // Third round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12842 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12843 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12844 | if (rv == ERR_IO_PENDING) |
| 12845 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12846 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12847 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12848 | ASSERT_TRUE(response); |
| 12849 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12850 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12851 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 12852 | auth_handler->state()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 12853 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12854 | // Fourth round of authentication, which completes successfully. |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 12855 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12856 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 12857 | if (rv == ERR_IO_PENDING) |
| 12858 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12859 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12860 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12861 | ASSERT_TRUE(response); |
| 12862 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12863 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12864 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12865 | // In WAIT_FOR_CHALLENGE, although in reality the auth handler is done. A real |
| 12866 | // auth handler should transition to a DONE state in concert with the remote |
| 12867 | // server. But that's not something we can test here with a mock handler. |
| 12868 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_CHALLENGE, |
| 12869 | auth_handler->state()); |
| 12870 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12871 | // Read the body since the fourth round was successful. This will also |
| 12872 | // release the socket back to the pool. |
| 12873 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(50)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12874 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12875 | if (rv == ERR_IO_PENDING) |
| 12876 | rv = callback.WaitForResult(); |
| 12877 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12878 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12879 | EXPECT_EQ(0, rv); |
| 12880 | // There are still 0 idle sockets, since the trans_compete transaction |
| 12881 | // will be handed it immediately after trans releases it to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12882 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12883 | |
| 12884 | // The competing request can now finish. Wait for the headers and then |
| 12885 | // read the body. |
| 12886 | rv = callback_compete.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12887 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12888 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12889 | if (rv == ERR_IO_PENDING) |
| 12890 | rv = callback.WaitForResult(); |
| 12891 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12892 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12893 | EXPECT_EQ(0, rv); |
| 12894 | |
| 12895 | // Finally, the socket is released to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12896 | EXPECT_EQ(1, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12897 | } |
| 12898 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12899 | // This tests the case that a request is issued via http instead of spdy after |
| 12900 | // npn is negotiated. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12901 | TEST_F(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12902 | HttpRequestInfo request; |
| 12903 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12904 | request.url = GURL("https://www.example.org/"); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12905 | |
| 12906 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12907 | MockWrite( |
| 12908 | "GET / HTTP/1.1\r\n" |
| 12909 | "Host: www.example.org\r\n" |
| 12910 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12911 | }; |
| 12912 | |
| 12913 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12914 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12915 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12916 | MockRead("\r\n"), |
| 12917 | MockRead("hello world"), |
| 12918 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12919 | }; |
| 12920 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12921 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12922 | ssl.next_proto = kProtoHTTP11; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12923 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12924 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12925 | |
| 12926 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 12927 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12928 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12929 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12930 | TestCompletionCallback callback; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12931 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12932 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12933 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12934 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12935 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12936 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12937 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12938 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12939 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12940 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12941 | ASSERT_TRUE(response); |
| 12942 | ASSERT_TRUE(response->headers); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12943 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12944 | |
| 12945 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12946 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12947 | EXPECT_EQ("hello world", response_data); |
| 12948 | |
| 12949 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12950 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12951 | } |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12952 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12953 | // Simulate the SSL handshake completing with an NPN negotiation followed by an |
| 12954 | // immediate server closing of the socket. |
| 12955 | // Regression test for https://crbug.com/46369. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12956 | TEST_F(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12957 | HttpRequestInfo request; |
| 12958 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12959 | request.url = GURL("https://www.example.org/"); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12960 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12961 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12962 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12963 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12964 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12965 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 12966 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12967 | MockWrite spdy_writes[] = {CreateMockWrite(req, 1)}; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12968 | |
| 12969 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12970 | MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12971 | }; |
| 12972 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12973 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 12974 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12975 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12976 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12977 | TestCompletionCallback callback; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12978 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12979 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12980 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12981 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12982 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12983 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12984 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12985 | } |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 12986 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 12987 | // A subclass of HttpAuthHandlerMock that records the request URL when |
| 12988 | // it gets it. This is needed since the auth handler may get destroyed |
| 12989 | // before we get a chance to query it. |
| 12990 | class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock { |
| 12991 | public: |
| 12992 | explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {} |
| 12993 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12994 | ~UrlRecordingHttpAuthHandlerMock() override {} |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 12995 | |
| 12996 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12997 | int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 12998 | const HttpRequestInfo* request, |
| 12999 | const CompletionCallback& callback, |
| 13000 | std::string* auth_token) override { |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13001 | *url_ = request->url; |
| 13002 | return HttpAuthHandlerMock::GenerateAuthTokenImpl( |
| 13003 | credentials, request, callback, auth_token); |
| 13004 | } |
| 13005 | |
| 13006 | private: |
| 13007 | GURL* url_; |
| 13008 | }; |
| 13009 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13010 | // Test that if we cancel the transaction as the connection is completing, that |
| 13011 | // everything tears down correctly. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13012 | TEST_F(HttpNetworkTransactionTest, SimpleCancel) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13013 | // Setup everything about the connection to complete synchronously, so that |
| 13014 | // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
| 13015 | // for is the callback from the HttpStreamRequest. |
| 13016 | // Then cancel the transaction. |
| 13017 | // Verify that we don't crash. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 13018 | MockConnect mock_connect(SYNCHRONOUS, OK); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13019 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13020 | MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), |
| 13021 | MockRead(SYNCHRONOUS, "hello world"), |
| 13022 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13023 | }; |
| 13024 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13025 | HttpRequestInfo request; |
| 13026 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13027 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13028 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13029 | session_deps_.host_resolver->set_synchronous_mode(true); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13030 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13031 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13032 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13033 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13034 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 13035 | data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13036 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13037 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13038 | TestCompletionCallback callback; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13039 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13040 | BoundTestNetLog log; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13041 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13042 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13043 | trans.reset(); // Cancel the transaction here. |
| 13044 | |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 13045 | base::RunLoop().RunUntilIdle(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 13046 | } |
| 13047 | |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13048 | // Test that if a transaction is cancelled after receiving the headers, the |
| 13049 | // stream is drained properly and added back to the socket pool. The main |
| 13050 | // purpose of this test is to make sure that an HttpStreamParser can be read |
| 13051 | // from after the HttpNetworkTransaction and the objects it owns have been |
| 13052 | // deleted. |
| 13053 | // See http://crbug.com/368418 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13054 | TEST_F(HttpNetworkTransactionTest, CancelAfterHeaders) { |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13055 | MockRead data_reads[] = { |
| 13056 | MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"), |
| 13057 | MockRead(ASYNC, "Content-Length: 2\r\n"), |
| 13058 | MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"), |
| 13059 | MockRead(ASYNC, "1"), |
| 13060 | // 2 async reads are necessary to trigger a ReadResponseBody call after the |
| 13061 | // HttpNetworkTransaction has been deleted. |
| 13062 | MockRead(ASYNC, "2"), |
| 13063 | MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this. |
| 13064 | }; |
| 13065 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 13066 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13067 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13068 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13069 | |
| 13070 | { |
| 13071 | HttpRequestInfo request; |
| 13072 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13073 | request.url = GURL("http://www.example.org/"); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13074 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13075 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13076 | TestCompletionCallback callback; |
| 13077 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13078 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13079 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13080 | callback.WaitForResult(); |
| 13081 | |
| 13082 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13083 | ASSERT_TRUE(response); |
| 13084 | EXPECT_TRUE(response->headers); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13085 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13086 | |
| 13087 | // The transaction and HttpRequestInfo are deleted. |
| 13088 | } |
| 13089 | |
| 13090 | // Let the HttpResponseBodyDrainer drain the socket. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 13091 | base::RunLoop().RunUntilIdle(); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13092 | |
| 13093 | // Socket should now be idle, waiting to be reused. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13094 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13095 | } |
| 13096 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13097 | // Test a basic GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13098 | TEST_F(HttpNetworkTransactionTest, ProxyGet) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 13099 | session_deps_.proxy_service = |
| 13100 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13101 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13102 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13103 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13104 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13105 | HttpRequestInfo request; |
| 13106 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13107 | request.url = GURL("http://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13108 | |
| 13109 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13110 | MockWrite( |
| 13111 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 13112 | "Host: www.example.org\r\n" |
| 13113 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13114 | }; |
| 13115 | |
| 13116 | MockRead data_reads1[] = { |
| 13117 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13118 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 13119 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13120 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13121 | }; |
| 13122 | |
| 13123 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 13124 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13125 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13126 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13127 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13128 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13129 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13130 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13131 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13132 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 13133 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13134 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13135 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13136 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13137 | |
| 13138 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13139 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13140 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13141 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13142 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13143 | |
| 13144 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 13145 | EXPECT_EQ(200, response->headers->response_code()); |
| 13146 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 13147 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 13148 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 13149 | HostPortPair::FromString("myproxy:70")), |
| 13150 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13151 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 13152 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 13153 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13154 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13155 | |
| 13156 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13157 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13158 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 13159 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13160 | } |
| 13161 | |
| 13162 | // Test a basic HTTPS GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13163 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGet) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 13164 | session_deps_.proxy_service = |
| 13165 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13166 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13167 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13168 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13169 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13170 | HttpRequestInfo request; |
| 13171 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13172 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13173 | |
| 13174 | // Since we have proxy, should try to establish tunnel. |
| 13175 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13176 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 13177 | "Host: www.example.org:443\r\n" |
| 13178 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13179 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13180 | MockWrite("GET / HTTP/1.1\r\n" |
| 13181 | "Host: www.example.org\r\n" |
| 13182 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13183 | }; |
| 13184 | |
| 13185 | MockRead data_reads1[] = { |
| 13186 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 13187 | |
| 13188 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13189 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 13190 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13191 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13192 | }; |
| 13193 | |
| 13194 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 13195 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13196 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13197 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13198 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13199 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13200 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13201 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13202 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13203 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13204 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13205 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 13206 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13207 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13208 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13209 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13210 | |
| 13211 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13212 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 13213 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 13214 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13215 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13216 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 13217 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13218 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 13219 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13220 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 13221 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13222 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13223 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13224 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13225 | |
| 13226 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 13227 | EXPECT_EQ(200, response->headers->response_code()); |
| 13228 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 13229 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 13230 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 13231 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 13232 | HostPortPair::FromString("myproxy:70")), |
| 13233 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13234 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 13235 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 13236 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13237 | |
| 13238 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13239 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13240 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 13241 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13242 | } |
| 13243 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13244 | // Test a basic HTTPS GET request through a proxy, connecting to an IPv6 |
| 13245 | // literal host. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13246 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetIPv6) { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13247 | session_deps_.proxy_service = |
| 13248 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 13249 | BoundTestNetLog log; |
| 13250 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13251 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13252 | |
| 13253 | HttpRequestInfo request; |
| 13254 | request.method = "GET"; |
| 13255 | request.url = GURL("https://[::1]:443/"); |
| 13256 | |
| 13257 | // Since we have proxy, should try to establish tunnel. |
| 13258 | MockWrite data_writes1[] = { |
| 13259 | MockWrite("CONNECT [::1]:443 HTTP/1.1\r\n" |
| 13260 | "Host: [::1]:443\r\n" |
| 13261 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 13262 | |
| 13263 | MockWrite("GET / HTTP/1.1\r\n" |
| 13264 | "Host: [::1]\r\n" |
| 13265 | "Connection: keep-alive\r\n\r\n"), |
| 13266 | }; |
| 13267 | |
| 13268 | MockRead data_reads1[] = { |
| 13269 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 13270 | |
| 13271 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13272 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 13273 | MockRead("Content-Length: 100\r\n\r\n"), |
| 13274 | MockRead(SYNCHRONOUS, OK), |
| 13275 | }; |
| 13276 | |
| 13277 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 13278 | data_writes1, arraysize(data_writes1)); |
| 13279 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 13280 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 13281 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13282 | |
| 13283 | TestCompletionCallback callback1; |
| 13284 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13285 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13286 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13287 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13288 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13289 | |
| 13290 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13291 | EXPECT_THAT(rv, IsOk()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13292 | TestNetLogEntry::List entries; |
| 13293 | log.GetEntries(&entries); |
| 13294 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13295 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 13296 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13297 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13298 | entries, pos, |
| 13299 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 13300 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13301 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13302 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13303 | ASSERT_TRUE(response); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13304 | |
| 13305 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 13306 | EXPECT_EQ(200, response->headers->response_code()); |
| 13307 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 13308 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 13309 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 13310 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 13311 | HostPortPair::FromString("myproxy:70")), |
| 13312 | response->proxy_server); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13313 | |
| 13314 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13315 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13316 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 13317 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 13318 | } |
| 13319 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13320 | // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 13321 | // while establishing the tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13322 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 13323 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13324 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13325 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13326 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13327 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13328 | HttpRequestInfo request; |
| 13329 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13330 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13331 | |
| 13332 | // Since we have proxy, should try to establish tunnel. |
| 13333 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13334 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 13335 | "Host: www.example.org:443\r\n" |
| 13336 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13337 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13338 | MockWrite("GET / HTTP/1.1\r\n" |
| 13339 | "Host: www.example.org\r\n" |
| 13340 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13341 | }; |
| 13342 | |
| 13343 | MockRead data_reads1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13344 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13345 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13346 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13347 | }; |
| 13348 | |
| 13349 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 13350 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13351 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13352 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13353 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13354 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13355 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13356 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13357 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13358 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13359 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13360 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13361 | |
| 13362 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13363 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 13364 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 13365 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13366 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13367 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 13368 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13369 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 13370 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13371 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 13372 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13373 | } |
| 13374 | |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13375 | // Test for crbug.com/55424. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13376 | TEST_F(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13377 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13378 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13379 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13380 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13381 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13382 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13383 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13384 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13385 | }; |
| 13386 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13387 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 13388 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13389 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13390 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13391 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13392 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13393 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13394 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13395 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13396 | |
| 13397 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13398 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 13399 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 13400 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13401 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 13402 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13403 | |
| 13404 | HttpRequestInfo request; |
| 13405 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13406 | request.url = GURL("https://www.example.org/"); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13407 | |
| 13408 | // This is the important line that marks this as a preconnect. |
| 13409 | request.motivation = HttpRequestInfo::PRECONNECT_MOTIVATED; |
| 13410 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13411 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13412 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13413 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13414 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13415 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13416 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13417 | } |
| 13418 | |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13419 | // Given a net error, cause that error to be returned from the first Write() |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13420 | // call and verify that the HttpNetworkTransaction fails with that error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13421 | void HttpNetworkTransactionTest::CheckErrorIsPassedBack( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13422 | int error, IoMode mode) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13423 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13424 | request_info.url = GURL("https://www.example.com/"); |
| 13425 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13426 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13427 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13428 | SSLSocketDataProvider ssl_data(mode, OK); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13429 | MockWrite data_writes[] = { |
| 13430 | MockWrite(mode, error), |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13431 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13432 | StaticSocketDataProvider data(NULL, 0, data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13433 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13434 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13435 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13436 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13437 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13438 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13439 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13440 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13441 | if (rv == ERR_IO_PENDING) |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13442 | rv = callback.WaitForResult(); |
| 13443 | ASSERT_EQ(error, rv); |
| 13444 | } |
| 13445 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13446 | TEST_F(HttpNetworkTransactionTest, SSLWriteCertError) { |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13447 | // Just check a grab bag of cert errors. |
| 13448 | static const int kErrors[] = { |
| 13449 | ERR_CERT_COMMON_NAME_INVALID, |
| 13450 | ERR_CERT_AUTHORITY_INVALID, |
| 13451 | ERR_CERT_DATE_INVALID, |
| 13452 | }; |
| 13453 | for (size_t i = 0; i < arraysize(kErrors); i++) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13454 | CheckErrorIsPassedBack(kErrors[i], ASYNC); |
| 13455 | CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13456 | } |
| 13457 | } |
| 13458 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13459 | // Ensure that a client certificate is removed from the SSL client auth |
| 13460 | // cache when: |
| 13461 | // 1) No proxy is involved. |
| 13462 | // 2) TLS False Start is disabled. |
| 13463 | // 3) The initial TLS handshake requests a client certificate. |
| 13464 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13465 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_NoFalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13466 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13467 | request_info.url = GURL("https://www.example.com/"); |
| 13468 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13469 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13470 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13471 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13472 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13473 | |
| 13474 | // [ssl_]data1 contains the data for the first SSL handshake. When a |
| 13475 | // CertificateRequest is received for the first time, the handshake will |
| 13476 | // be aborted to allow the caller to provide a certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13477 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13478 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13479 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13480 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13481 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13482 | |
| 13483 | // [ssl_]data2 contains the data for the second SSL handshake. When TLS |
| 13484 | // False Start is not being used, the result of the SSL handshake will be |
| 13485 | // returned as part of the SSLClientSocket::Connect() call. This test |
| 13486 | // matches the result of a server sending a handshake_failure alert, |
| 13487 | // rather than a Finished message, because it requires a client |
| 13488 | // certificate and none was supplied. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13489 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13490 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13491 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13492 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13493 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13494 | |
| 13495 | // [ssl_]data3 contains the data for the third SSL handshake. When a |
| 13496 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 13497 | // HttpNetworkTransaction will attempt to fallback to TLSv1.1 if the previous |
| 13498 | // connection was attempted with TLSv1.2. This is transparent to the caller |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13499 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 13500 | // requiring a client certificate, this fallback handshake should also |
| 13501 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13502 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13503 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13504 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13505 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13506 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13507 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13508 | // [ssl_]data4 contains the data for the fourth SSL handshake. When a |
| 13509 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 13510 | // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous |
| 13511 | // connection was attempted with TLSv1.1. This is transparent to the caller |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13512 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 13513 | // requiring a client certificate, this fallback handshake should also |
| 13514 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13515 | SSLSocketDataProvider ssl_data4(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13516 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13517 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13518 | StaticSocketDataProvider data4(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13519 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13520 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13521 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13522 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13523 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13524 | // Begin the SSL handshake with the peer. This consumes ssl_data1. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13525 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13526 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13527 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13528 | |
| 13529 | // Complete the SSL handshake, which should abort due to requiring a |
| 13530 | // client certificate. |
| 13531 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13532 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13533 | |
| 13534 | // Indicate that no certificate should be supplied. From the perspective |
| 13535 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 13536 | // certificate, so this is the same as supply a |
| 13537 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13538 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13539 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13540 | |
| 13541 | // Ensure the certificate was added to the client auth cache before |
| 13542 | // allowing the connection to continue restarting. |
| 13543 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13544 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13545 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13546 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13547 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13548 | |
| 13549 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13550 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 13551 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13552 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13553 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13554 | |
| 13555 | // Ensure that the client certificate is removed from the cache on a |
| 13556 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13557 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13558 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13559 | } |
| 13560 | |
| 13561 | // Ensure that a client certificate is removed from the SSL client auth |
| 13562 | // cache when: |
| 13563 | // 1) No proxy is involved. |
| 13564 | // 2) TLS False Start is enabled. |
| 13565 | // 3) The initial TLS handshake requests a client certificate. |
| 13566 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13567 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_FalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13568 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13569 | request_info.url = GURL("https://www.example.com/"); |
| 13570 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13571 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13572 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13573 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13574 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13575 | |
| 13576 | // When TLS False Start is used, SSLClientSocket::Connect() calls will |
| 13577 | // return successfully after reading up to the peer's Certificate message. |
| 13578 | // This is to allow the caller to call SSLClientSocket::Write(), which can |
| 13579 | // enqueue application data to be sent in the same packet as the |
| 13580 | // ChangeCipherSpec and Finished messages. |
| 13581 | // The actual handshake will be finished when SSLClientSocket::Read() is |
| 13582 | // called, which expects to process the peer's ChangeCipherSpec and |
| 13583 | // Finished messages. If there was an error negotiating with the peer, |
| 13584 | // such as due to the peer requiring a client certificate when none was |
| 13585 | // supplied, the alert sent by the peer won't be processed until Read() is |
| 13586 | // called. |
| 13587 | |
| 13588 | // Like the non-False Start case, when a client certificate is requested by |
| 13589 | // the peer, the handshake is aborted during the Connect() call. |
| 13590 | // [ssl_]data1 represents the initial SSL handshake with the peer. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13591 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13592 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13593 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13594 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13595 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13596 | |
| 13597 | // When a client certificate is supplied, Connect() will not be aborted |
| 13598 | // when the peer requests the certificate. Instead, the handshake will |
| 13599 | // artificially succeed, allowing the caller to write the HTTP request to |
| 13600 | // the socket. The handshake messages are not processed until Read() is |
| 13601 | // called, which then detects that the handshake was aborted, due to the |
| 13602 | // peer sending a handshake_failure because it requires a client |
| 13603 | // certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13604 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13605 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13606 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13607 | MockRead data2_reads[] = { |
| 13608 | MockRead(ASYNC /* async */, ERR_SSL_PROTOCOL_ERROR), |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13609 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13610 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13611 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13612 | |
| 13613 | // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13614 | // the data for the SSL handshake once the TLSv1.1 connection falls back to |
| 13615 | // TLSv1. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13616 | SSLSocketDataProvider ssl_data3(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13617 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13618 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13619 | StaticSocketDataProvider data3(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13620 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13621 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13622 | // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection |
| 13623 | // falls back to SSLv3. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13624 | SSLSocketDataProvider ssl_data4(ASYNC, OK); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13625 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13626 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13627 | StaticSocketDataProvider data4(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13628 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13629 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 13630 | // Need one more if TLSv1.2 is enabled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13631 | SSLSocketDataProvider ssl_data5(ASYNC, OK); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 13632 | ssl_data5.cert_request_info = cert_request.get(); |
| 13633 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13634 | StaticSocketDataProvider data5(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 13635 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 13636 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13637 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13638 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13639 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13640 | // Begin the initial SSL handshake. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13641 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13642 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13643 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13644 | |
| 13645 | // Complete the SSL handshake, which should abort due to requiring a |
| 13646 | // client certificate. |
| 13647 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13648 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13649 | |
| 13650 | // Indicate that no certificate should be supplied. From the perspective |
| 13651 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 13652 | // certificate, so this is the same as supply a |
| 13653 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13654 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13655 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13656 | |
| 13657 | // Ensure the certificate was added to the client auth cache before |
| 13658 | // allowing the connection to continue restarting. |
| 13659 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13660 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13661 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13662 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13663 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13664 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13665 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13666 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 13667 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13668 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13669 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13670 | |
| 13671 | // Ensure that the client certificate is removed from the cache on a |
| 13672 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13673 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13674 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13675 | } |
| 13676 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13677 | // Ensure that a client certificate is removed from the SSL client auth |
| 13678 | // cache when: |
| 13679 | // 1) An HTTPS proxy is involved. |
| 13680 | // 3) The HTTPS proxy requests a client certificate. |
| 13681 | // 4) The client supplies an invalid/unacceptable certificate for the |
| 13682 | // proxy. |
| 13683 | // The test is repeated twice, first for connecting to an HTTPS endpoint, |
| 13684 | // then for connecting to an HTTP endpoint. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13685 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 13686 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13687 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13688 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13689 | |
| 13690 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13691 | cert_request->host_and_port = HostPortPair("proxy", 70); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13692 | |
| 13693 | // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of |
| 13694 | // [ssl_]data[1-3]. Rather than represending the endpoint |
| 13695 | // (www.example.com:443), they represent failures with the HTTPS proxy |
| 13696 | // (proxy:70). |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13697 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13698 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13699 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13700 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13701 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13702 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13703 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13704 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13705 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13706 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13707 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13708 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13709 | // TODO(wtc): find out why this unit test doesn't need [ssl_]data3. |
| 13710 | #if 0 |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13711 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13712 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13713 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13714 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13715 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13716 | #endif |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13717 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13718 | HttpRequestInfo requests[2]; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13719 | requests[0].url = GURL("https://www.example.com/"); |
| 13720 | requests[0].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13721 | requests[0].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13722 | |
| 13723 | requests[1].url = GURL("http://www.example.com/"); |
| 13724 | requests[1].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13725 | requests[1].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13726 | |
| 13727 | for (size_t i = 0; i < arraysize(requests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13728 | session_deps_.socket_factory->ResetNextMockIndexes(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13729 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13730 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13731 | |
| 13732 | // Begin the SSL handshake with the proxy. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13733 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13734 | int rv = trans.Start(&requests[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13735 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13736 | |
| 13737 | // Complete the SSL handshake, which should abort due to requiring a |
| 13738 | // client certificate. |
| 13739 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13740 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13741 | |
| 13742 | // Indicate that no certificate should be supplied. From the perspective |
| 13743 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 13744 | // certificate, so this is the same as supply a |
| 13745 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13746 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13747 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13748 | |
| 13749 | // Ensure the certificate was added to the client auth cache before |
| 13750 | // allowing the connection to continue restarting. |
| 13751 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13752 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13753 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13754 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13755 | ASSERT_FALSE(client_cert); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13756 | // Ensure the certificate was NOT cached for the endpoint. This only |
| 13757 | // applies to HTTPS requests, but is fine to check for HTTP requests. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13758 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13759 | HostPortPair("www.example.com", 443), &client_cert, |
| 13760 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13761 | |
| 13762 | // Restart the handshake. This will consume ssl_data2, which fails, and |
| 13763 | // then consume ssl_data3, which should also fail. The result code is |
| 13764 | // checked against what ssl_data3 should return. |
| 13765 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13766 | ASSERT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13767 | |
| 13768 | // Now that the new handshake has failed, ensure that the client |
| 13769 | // certificate was removed from the client auth cache. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13770 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13771 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13772 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13773 | HostPortPair("www.example.com", 443), &client_cert, |
| 13774 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13775 | } |
| 13776 | } |
| 13777 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13778 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPooling) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13779 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13780 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13781 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13782 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13783 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13784 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13785 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13786 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13787 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13788 | SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13789 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13790 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13791 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13792 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13793 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13794 | SpdySerializedFrame host1_resp_body( |
| 13795 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13796 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13797 | SpdySerializedFrame host2_resp_body( |
| 13798 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13799 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13800 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 13801 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13802 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13803 | }; |
| 13804 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 13805 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13806 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13807 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 13808 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13809 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13810 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 13811 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13812 | HttpRequestInfo request1; |
| 13813 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13814 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13815 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13816 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13817 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13818 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13819 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13820 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13821 | |
| 13822 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13823 | ASSERT_TRUE(response); |
| 13824 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13825 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13826 | |
| 13827 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13828 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13829 | EXPECT_EQ("hello!", response_data); |
| 13830 | |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13831 | // Preload mail.example.com into HostCache. |
| 13832 | HostPortPair host_port("mail.example.com", 443); |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 13833 | HostResolver::RequestInfo resolve_info(host_port); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13834 | AddressList ignored; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 13835 | std::unique_ptr<HostResolver::Request> request; |
| 13836 | rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 13837 | &ignored, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13838 | &request, NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13839 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 13840 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13841 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13842 | |
| 13843 | HttpRequestInfo request2; |
| 13844 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13845 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13846 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13847 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13848 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13849 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13850 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13851 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13852 | |
| 13853 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13854 | ASSERT_TRUE(response); |
| 13855 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13856 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13857 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13858 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13859 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13860 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13861 | } |
| 13862 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13863 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) { |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13864 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13865 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13866 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13867 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13868 | AddSSLSocketData(); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13869 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13870 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13871 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13872 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13873 | SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13874 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13875 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13876 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13877 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13878 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13879 | SpdySerializedFrame host1_resp_body( |
| 13880 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13881 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13882 | SpdySerializedFrame host2_resp_body( |
| 13883 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13884 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13885 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 13886 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13887 | MockRead(ASYNC, 0, 6), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13888 | }; |
| 13889 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 13890 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13891 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13892 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 13893 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13894 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13895 | |
| 13896 | TestCompletionCallback callback; |
| 13897 | HttpRequestInfo request1; |
| 13898 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13899 | request1.url = GURL("https://www.example.org/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13900 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13901 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13902 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13903 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13904 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13905 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13906 | |
| 13907 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13908 | ASSERT_TRUE(response); |
| 13909 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13910 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13911 | |
| 13912 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13913 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13914 | EXPECT_EQ("hello!", response_data); |
| 13915 | |
| 13916 | HttpRequestInfo request2; |
| 13917 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13918 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13919 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13920 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13921 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13922 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13923 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13924 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13925 | |
| 13926 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13927 | ASSERT_TRUE(response); |
| 13928 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13929 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13930 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13931 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13932 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13933 | EXPECT_EQ("hello!", response_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13934 | } |
| 13935 | |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 13936 | // Regression test for https://crbug.com/546991. |
| 13937 | // The server might not be able to serve an IP pooled request, and might send a |
| 13938 | // 421 Misdirected Request response status to indicate this. |
| 13939 | // HttpNetworkTransaction should reset the request and retry without IP pooling. |
| 13940 | TEST_F(HttpNetworkTransactionTest, RetryWithoutConnectionPooling) { |
| 13941 | // Two hosts resolve to the same IP address. |
| 13942 | const std::string ip_addr = "1.2.3.4"; |
| 13943 | IPAddress ip; |
| 13944 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 13945 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 13946 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13947 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 13948 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 13949 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 13950 | |
| 13951 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13952 | |
| 13953 | // Two requests on the first connection. |
| 13954 | SpdySerializedFrame req1( |
| 13955 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 13956 | spdy_util_.UpdateWithStreamDestruction(1); |
| 13957 | SpdySerializedFrame req2( |
| 13958 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
| 13959 | SpdySerializedFrame rst( |
| 13960 | spdy_util_.ConstructSpdyRstStream(3, ERROR_CODE_CANCEL)); |
| 13961 | MockWrite writes1[] = { |
| 13962 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 13963 | CreateMockWrite(rst, 6), |
| 13964 | }; |
| 13965 | |
| 13966 | // The first one succeeds, the second gets error 421 Misdirected Request. |
| 13967 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 13968 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 13969 | SpdyHeaderBlock response_headers; |
| 13970 | response_headers[SpdyTestUtil::GetStatusKey()] = "421"; |
| 13971 | SpdySerializedFrame resp2( |
| 13972 | spdy_util_.ConstructSpdyReply(3, std::move(response_headers))); |
| 13973 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 13974 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 13975 | |
| 13976 | MockConnect connect1(ASYNC, OK, peer_addr); |
| 13977 | SequencedSocketData data1(connect1, reads1, arraysize(reads1), writes1, |
| 13978 | arraysize(writes1)); |
| 13979 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 13980 | |
| 13981 | AddSSLSocketData(); |
| 13982 | |
| 13983 | // Retry the second request on a second connection. |
| 13984 | SpdyTestUtil spdy_util2; |
| 13985 | SpdySerializedFrame req3( |
| 13986 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 13987 | MockWrite writes2[] = { |
| 13988 | CreateMockWrite(req3, 0), |
| 13989 | }; |
| 13990 | |
| 13991 | SpdySerializedFrame resp3(spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 13992 | SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 13993 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 13994 | MockRead(ASYNC, 0, 3)}; |
| 13995 | |
| 13996 | MockConnect connect2(ASYNC, OK, peer_addr); |
| 13997 | SequencedSocketData data2(connect2, reads2, arraysize(reads2), writes2, |
| 13998 | arraysize(writes2)); |
| 13999 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 14000 | |
| 14001 | AddSSLSocketData(); |
| 14002 | |
| 14003 | // Preload mail.example.org into HostCache. |
| 14004 | HostPortPair host_port("mail.example.org", 443); |
| 14005 | HostResolver::RequestInfo resolve_info(host_port); |
| 14006 | AddressList ignored; |
| 14007 | std::unique_ptr<HostResolver::Request> request; |
| 14008 | TestCompletionCallback callback; |
| 14009 | int rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 14010 | &ignored, callback.callback(), |
| 14011 | &request, NetLogWithSource()); |
| 14012 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14013 | rv = callback.WaitForResult(); |
| 14014 | EXPECT_THAT(rv, IsOk()); |
| 14015 | |
| 14016 | HttpRequestInfo request1; |
| 14017 | request1.method = "GET"; |
| 14018 | request1.url = GURL("https://www.example.org/"); |
| 14019 | request1.load_flags = 0; |
| 14020 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 14021 | |
| 14022 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 14023 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14024 | rv = callback.WaitForResult(); |
| 14025 | EXPECT_THAT(rv, IsOk()); |
| 14026 | |
| 14027 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 14028 | ASSERT_TRUE(response); |
| 14029 | ASSERT_TRUE(response->headers); |
| 14030 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 14031 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 14032 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 14033 | std::string response_data; |
| 14034 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 14035 | EXPECT_EQ("hello!", response_data); |
| 14036 | |
| 14037 | HttpRequestInfo request2; |
| 14038 | request2.method = "GET"; |
| 14039 | request2.url = GURL("https://mail.example.org/"); |
| 14040 | request2.load_flags = 0; |
| 14041 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 14042 | |
| 14043 | BoundTestNetLog log; |
| 14044 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 14045 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14046 | rv = callback.WaitForResult(); |
| 14047 | EXPECT_THAT(rv, IsOk()); |
| 14048 | |
| 14049 | response = trans2.GetResponseInfo(); |
| 14050 | ASSERT_TRUE(response); |
| 14051 | ASSERT_TRUE(response->headers); |
| 14052 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 14053 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 14054 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 14055 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 14056 | EXPECT_EQ("hello!", response_data); |
| 14057 | |
| 14058 | TestNetLogEntry::List entries; |
| 14059 | log.GetEntries(&entries); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14060 | ExpectLogContainsSomewhere( |
| 14061 | entries, 0, NetLogEventType::HTTP_TRANSACTION_RESTART_MISDIRECTED_REQUEST, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14062 | NetLogEventPhase::NONE); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14063 | } |
| 14064 | |
| 14065 | // Test that HTTP 421 responses are properly returned to the caller if received |
| 14066 | // on the retry as well. HttpNetworkTransaction should not infinite loop or lose |
| 14067 | // portions of the response. |
| 14068 | TEST_F(HttpNetworkTransactionTest, ReturnHTTP421OnRetry) { |
| 14069 | // Two hosts resolve to the same IP address. |
| 14070 | const std::string ip_addr = "1.2.3.4"; |
| 14071 | IPAddress ip; |
| 14072 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 14073 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 14074 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14075 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14076 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 14077 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 14078 | |
| 14079 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14080 | |
| 14081 | // Two requests on the first connection. |
| 14082 | SpdySerializedFrame req1( |
| 14083 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 14084 | spdy_util_.UpdateWithStreamDestruction(1); |
| 14085 | SpdySerializedFrame req2( |
| 14086 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
| 14087 | SpdySerializedFrame rst( |
| 14088 | spdy_util_.ConstructSpdyRstStream(3, ERROR_CODE_CANCEL)); |
| 14089 | MockWrite writes1[] = { |
| 14090 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 14091 | CreateMockWrite(rst, 6), |
| 14092 | }; |
| 14093 | |
| 14094 | // The first one succeeds, the second gets error 421 Misdirected Request. |
| 14095 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 14096 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 14097 | SpdyHeaderBlock response_headers; |
| 14098 | response_headers[SpdyTestUtil::GetStatusKey()] = "421"; |
| 14099 | SpdySerializedFrame resp2( |
| 14100 | spdy_util_.ConstructSpdyReply(3, response_headers.Clone())); |
| 14101 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 14102 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 14103 | |
| 14104 | MockConnect connect1(ASYNC, OK, peer_addr); |
| 14105 | SequencedSocketData data1(connect1, reads1, arraysize(reads1), writes1, |
| 14106 | arraysize(writes1)); |
| 14107 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 14108 | |
| 14109 | AddSSLSocketData(); |
| 14110 | |
| 14111 | // Retry the second request on a second connection. It returns 421 Misdirected |
| 14112 | // Retry again. |
| 14113 | SpdyTestUtil spdy_util2; |
| 14114 | SpdySerializedFrame req3( |
| 14115 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 14116 | MockWrite writes2[] = { |
| 14117 | CreateMockWrite(req3, 0), |
| 14118 | }; |
| 14119 | |
| 14120 | SpdySerializedFrame resp3( |
| 14121 | spdy_util2.ConstructSpdyReply(1, std::move(response_headers))); |
| 14122 | SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 14123 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 14124 | MockRead(ASYNC, 0, 3)}; |
| 14125 | |
| 14126 | MockConnect connect2(ASYNC, OK, peer_addr); |
| 14127 | SequencedSocketData data2(connect2, reads2, arraysize(reads2), writes2, |
| 14128 | arraysize(writes2)); |
| 14129 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 14130 | |
| 14131 | AddSSLSocketData(); |
| 14132 | |
| 14133 | // Preload mail.example.org into HostCache. |
| 14134 | HostPortPair host_port("mail.example.org", 443); |
| 14135 | HostResolver::RequestInfo resolve_info(host_port); |
| 14136 | AddressList ignored; |
| 14137 | std::unique_ptr<HostResolver::Request> request; |
| 14138 | TestCompletionCallback callback; |
| 14139 | int rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 14140 | &ignored, callback.callback(), |
| 14141 | &request, NetLogWithSource()); |
| 14142 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14143 | rv = callback.WaitForResult(); |
| 14144 | EXPECT_THAT(rv, IsOk()); |
| 14145 | |
| 14146 | HttpRequestInfo request1; |
| 14147 | request1.method = "GET"; |
| 14148 | request1.url = GURL("https://www.example.org/"); |
| 14149 | request1.load_flags = 0; |
| 14150 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 14151 | |
| 14152 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 14153 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14154 | rv = callback.WaitForResult(); |
| 14155 | EXPECT_THAT(rv, IsOk()); |
| 14156 | |
| 14157 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 14158 | ASSERT_TRUE(response); |
| 14159 | ASSERT_TRUE(response->headers); |
| 14160 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 14161 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 14162 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 14163 | std::string response_data; |
| 14164 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 14165 | EXPECT_EQ("hello!", response_data); |
| 14166 | |
| 14167 | HttpRequestInfo request2; |
| 14168 | request2.method = "GET"; |
| 14169 | request2.url = GURL("https://mail.example.org/"); |
| 14170 | request2.load_flags = 0; |
| 14171 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 14172 | |
| 14173 | BoundTestNetLog log; |
| 14174 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 14175 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14176 | rv = callback.WaitForResult(); |
| 14177 | EXPECT_THAT(rv, IsOk()); |
| 14178 | |
| 14179 | // After a retry, the 421 Misdirected Request is reported back up to the |
| 14180 | // caller. |
| 14181 | response = trans2.GetResponseInfo(); |
| 14182 | ASSERT_TRUE(response); |
| 14183 | ASSERT_TRUE(response->headers); |
| 14184 | EXPECT_EQ("HTTP/1.1 421", response->headers->GetStatusLine()); |
| 14185 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 14186 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 14187 | EXPECT_TRUE(response->ssl_info.cert); |
| 14188 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 14189 | EXPECT_EQ("hello!", response_data); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14190 | } |
| 14191 | |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 14192 | class OneTimeCachingHostResolver : public MockHostResolverBase { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14193 | public: |
| 14194 | explicit OneTimeCachingHostResolver(const HostPortPair& host_port) |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 14195 | : MockHostResolverBase(/* use_caching = */ true), host_port_(host_port) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14196 | ~OneTimeCachingHostResolver() override {} |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14197 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14198 | int ResolveFromCache(const RequestInfo& info, |
| 14199 | AddressList* addresses, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14200 | const NetLogWithSource& net_log) override { |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 14201 | int rv = MockHostResolverBase::ResolveFromCache(info, addresses, net_log); |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 14202 | if (rv == OK && info.host_port_pair().Equals(host_port_)) |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 14203 | GetHostCache()->clear(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14204 | return rv; |
| 14205 | } |
| 14206 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14207 | private: |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14208 | const HostPortPair host_port_; |
| 14209 | }; |
| 14210 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14211 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 14212 | UseIPConnectionPoolingWithHostCacheExpiration) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14213 | // Set up a special HttpNetworkSession with a OneTimeCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14214 | session_deps_.host_resolver = std::make_unique<OneTimeCachingHostResolver>( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14215 | HostPortPair("mail.example.com", 443)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14216 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14217 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 14218 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14219 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14220 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14221 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14222 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14223 | SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14224 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14225 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14226 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14227 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14228 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14229 | SpdySerializedFrame host1_resp_body( |
| 14230 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14231 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14232 | SpdySerializedFrame host2_resp_body( |
| 14233 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14234 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14235 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 14236 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14237 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14238 | }; |
| 14239 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 14240 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14241 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14242 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 14243 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14244 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14245 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 14246 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14247 | HttpRequestInfo request1; |
| 14248 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14249 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14250 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14251 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14252 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14253 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14254 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14255 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14256 | |
| 14257 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14258 | ASSERT_TRUE(response); |
| 14259 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14260 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14261 | |
| 14262 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14263 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14264 | EXPECT_EQ("hello!", response_data); |
| 14265 | |
| 14266 | // Preload cache entries into HostCache. |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14267 | HostResolver::RequestInfo resolve_info(HostPortPair("mail.example.com", 443)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14268 | AddressList ignored; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 14269 | std::unique_ptr<HostResolver::Request> request; |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 14270 | rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 14271 | &ignored, callback.callback(), |
| 14272 | &request, NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14273 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 14274 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14275 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14276 | |
| 14277 | HttpRequestInfo request2; |
| 14278 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14279 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14280 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14281 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14282 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14283 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14284 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14285 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14286 | |
| 14287 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14288 | ASSERT_TRUE(response); |
| 14289 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14290 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14291 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14292 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14293 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14294 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14295 | } |
| 14296 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14297 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14298 | const std::string https_url = "https://www.example.org:8080/"; |
| 14299 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14300 | |
| 14301 | // SPDY GET for HTTPS URL |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14302 | SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14303 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14304 | |
| 14305 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14306 | CreateMockWrite(req1, 0), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14307 | }; |
| 14308 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14309 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14310 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 14311 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 14312 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3)}; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14313 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14314 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 14315 | arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14316 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 14317 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14318 | |
| 14319 | // HTTP GET for the HTTP URL |
| 14320 | MockWrite writes2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14321 | MockWrite(ASYNC, 0, |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 14322 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14323 | "Host: www.example.org:8080\r\n" |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 14324 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14325 | }; |
| 14326 | |
| 14327 | MockRead reads2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14328 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 14329 | MockRead(ASYNC, 2, "hello"), |
| 14330 | MockRead(ASYNC, OK, 3), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14331 | }; |
| 14332 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14333 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 14334 | arraysize(writes2)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14335 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14336 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14337 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14338 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14339 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 14340 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14341 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14342 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14343 | |
| 14344 | // Start the first transaction to set up the SpdySession |
| 14345 | HttpRequestInfo request1; |
| 14346 | request1.method = "GET"; |
| 14347 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14348 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14349 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14350 | TestCompletionCallback callback1; |
| 14351 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14352 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 14353 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14354 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14355 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14356 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 14357 | |
| 14358 | // Now, start the HTTP request |
| 14359 | HttpRequestInfo request2; |
| 14360 | request2.method = "GET"; |
| 14361 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14362 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14363 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14364 | TestCompletionCallback callback2; |
| 14365 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14366 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 14367 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14368 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14369 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14370 | EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 14371 | } |
| 14372 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14373 | // Alternative service requires HTTP/2 (or SPDY), but HTTP/1.1 is negotiated |
| 14374 | // with the alternative server. That connection should not be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14375 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceNotOnHttp11) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14376 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 14377 | HostPortPair alternative("www.example.org", 444); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14378 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14379 | // Negotiate HTTP/1.1 with alternative. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14380 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14381 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14382 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14383 | |
| 14384 | // No data should be read from the alternative, because HTTP/1.1 is |
| 14385 | // negotiated. |
| 14386 | StaticSocketDataProvider data; |
| 14387 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14388 | |
| 14389 | // 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] | 14390 | // negotiated. In order to test this, a failed connection to the server is |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14391 | // mocked. This way the request relies on the alternate Job. |
| 14392 | StaticSocketDataProvider data_refused; |
| 14393 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 14394 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 14395 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14396 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14397 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 14398 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14399 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 14400 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 14401 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 14402 | http_server_properties->SetHttp2AlternativeService( |
| 14403 | server, alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14404 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14405 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 14406 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14407 | request.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14408 | request.url = GURL("https://www.example.org:443"); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14409 | TestCompletionCallback callback; |
| 14410 | |
| 14411 | // HTTP/2 (or SPDY) is required for alternative service, if HTTP/1.1 is |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14412 | // negotiated, the alternate Job should fail with ERR_ALPN_NEGOTIATION_FAILED. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14413 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14414 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_ALPN_NEGOTIATION_FAILED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14415 | } |
| 14416 | |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14417 | // 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] | 14418 | // server, and an alternate one to the alternative server. If the former |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14419 | // succeeds, the request should succeed, even if the latter fails because |
| 14420 | // HTTP/1.1 is negotiated which is insufficient for alternative service. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14421 | TEST_F(HttpNetworkTransactionTest, FailedAlternativeServiceIsNotUserVisible) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14422 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 14423 | HostPortPair alternative("www.example.org", 444); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14424 | |
| 14425 | // Negotiate HTTP/1.1 with alternative. |
| 14426 | SSLSocketDataProvider alternative_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14427 | alternative_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14428 | session_deps_.socket_factory->AddSSLSocketDataProvider(&alternative_ssl); |
| 14429 | |
| 14430 | // No data should be read from the alternative, because HTTP/1.1 is |
| 14431 | // negotiated. |
| 14432 | StaticSocketDataProvider data; |
| 14433 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14434 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14435 | // Negotiate HTTP/1.1 with server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14436 | SSLSocketDataProvider origin_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14437 | origin_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14438 | session_deps_.socket_factory->AddSSLSocketDataProvider(&origin_ssl); |
| 14439 | |
| 14440 | MockWrite http_writes[] = { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14441 | MockWrite("GET / HTTP/1.1\r\n" |
| 14442 | "Host: www.example.org\r\n" |
| 14443 | "Connection: keep-alive\r\n\r\n"), |
| 14444 | MockWrite("GET /second HTTP/1.1\r\n" |
| 14445 | "Host: www.example.org\r\n" |
| 14446 | "Connection: keep-alive\r\n\r\n"), |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14447 | }; |
| 14448 | |
| 14449 | MockRead http_reads[] = { |
| 14450 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14451 | MockRead("Content-Type: text/html\r\n"), |
| 14452 | MockRead("Content-Length: 6\r\n\r\n"), |
| 14453 | MockRead("foobar"), |
| 14454 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14455 | MockRead("Content-Type: text/html\r\n"), |
| 14456 | MockRead("Content-Length: 7\r\n\r\n"), |
| 14457 | MockRead("another"), |
| 14458 | }; |
| 14459 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 14460 | http_writes, arraysize(http_writes)); |
| 14461 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 14462 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14463 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14464 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 14465 | HttpServerProperties* http_server_properties = |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14466 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 14467 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 14468 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 14469 | http_server_properties->SetHttp2AlternativeService( |
| 14470 | server, alternative_service, expiration); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14471 | |
| 14472 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 14473 | HttpRequestInfo request1; |
| 14474 | request1.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14475 | request1.url = GURL("https://www.example.org:443"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14476 | request1.load_flags = 0; |
| 14477 | TestCompletionCallback callback1; |
| 14478 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14479 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14480 | rv = callback1.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14481 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14482 | |
| 14483 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14484 | ASSERT_TRUE(response1); |
| 14485 | ASSERT_TRUE(response1->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14486 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 14487 | |
| 14488 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14489 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14490 | EXPECT_EQ("foobar", response_data1); |
| 14491 | |
| 14492 | // Alternative should be marked as broken, because HTTP/1.1 is not sufficient |
| 14493 | // for alternative service. |
| 14494 | EXPECT_TRUE( |
| 14495 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
| 14496 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14497 | // Since |alternative_service| is broken, a second transaction to server |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14498 | // should not start an alternate Job. It should pool to existing connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14499 | // to server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14500 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 14501 | HttpRequestInfo request2; |
| 14502 | request2.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14503 | request2.url = GURL("https://www.example.org:443/second"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14504 | request2.load_flags = 0; |
| 14505 | TestCompletionCallback callback2; |
| 14506 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14507 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14508 | rv = callback2.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14509 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14510 | |
| 14511 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14512 | ASSERT_TRUE(response2); |
| 14513 | ASSERT_TRUE(response2->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14514 | EXPECT_EQ("HTTP/1.1 200 OK", response2->headers->GetStatusLine()); |
| 14515 | |
| 14516 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14517 | ASSERT_THAT(ReadTransaction(&trans2, &response_data2), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14518 | EXPECT_EQ("another", response_data2); |
| 14519 | } |
| 14520 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14521 | // Alternative service requires HTTP/2 (or SPDY), but there is already a |
| 14522 | // HTTP/1.1 socket open to the alternative server. That socket should not be |
| 14523 | // used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14524 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceShouldNotPoolToHttp11) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14525 | url::SchemeHostPort server("https", "origin.example.org", 443); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14526 | HostPortPair alternative("alternative.example.org", 443); |
| 14527 | std::string origin_url = "https://origin.example.org:443"; |
| 14528 | std::string alternative_url = "https://alternative.example.org:443"; |
| 14529 | |
| 14530 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 14531 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14532 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14533 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14534 | |
| 14535 | // HTTP/1.1 data for |request1| and |request2|. |
| 14536 | MockWrite http_writes[] = { |
| 14537 | MockWrite( |
| 14538 | "GET / HTTP/1.1\r\n" |
| 14539 | "Host: alternative.example.org\r\n" |
| 14540 | "Connection: keep-alive\r\n\r\n"), |
| 14541 | MockWrite( |
| 14542 | "GET / HTTP/1.1\r\n" |
| 14543 | "Host: alternative.example.org\r\n" |
| 14544 | "Connection: keep-alive\r\n\r\n"), |
| 14545 | }; |
| 14546 | |
| 14547 | MockRead http_reads[] = { |
| 14548 | MockRead( |
| 14549 | "HTTP/1.1 200 OK\r\n" |
| 14550 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 14551 | "Content-Length: 40\r\n\r\n" |
| 14552 | "first HTTP/1.1 response from alternative"), |
| 14553 | MockRead( |
| 14554 | "HTTP/1.1 200 OK\r\n" |
| 14555 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 14556 | "Content-Length: 41\r\n\r\n" |
| 14557 | "second HTTP/1.1 response from alternative"), |
| 14558 | }; |
| 14559 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 14560 | http_writes, arraysize(http_writes)); |
| 14561 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 14562 | |
| 14563 | // This test documents that an alternate Job should not pool to an already |
| 14564 | // existing HTTP/1.1 connection. In order to test this, a failed connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14565 | // to the server is mocked. This way |request2| relies on the alternate Job. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14566 | StaticSocketDataProvider data_refused; |
| 14567 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 14568 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 14569 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14570 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14571 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 14572 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14573 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 14574 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 14575 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 14576 | http_server_properties->SetHttp2AlternativeService( |
| 14577 | server, alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14578 | |
| 14579 | // First transaction to alternative to open an HTTP/1.1 socket. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14580 | HttpRequestInfo request1; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 14581 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14582 | request1.method = "GET"; |
| 14583 | request1.url = GURL(alternative_url); |
| 14584 | request1.load_flags = 0; |
| 14585 | TestCompletionCallback callback1; |
| 14586 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14587 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14588 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14589 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14590 | ASSERT_TRUE(response1); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14591 | ASSERT_TRUE(response1->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14592 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14593 | EXPECT_TRUE(response1->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14594 | EXPECT_FALSE(response1->was_fetched_via_spdy); |
| 14595 | std::string response_data1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14596 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14597 | EXPECT_EQ("first HTTP/1.1 response from alternative", response_data1); |
| 14598 | |
| 14599 | // Request for origin.example.org, which has an alternative service. This |
| 14600 | // will start two Jobs: the alternative looks for connections to pool to, |
| 14601 | // 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] | 14602 | // open other connections to alternative server. The Job to server fails, so |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14603 | // this request fails. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14604 | HttpRequestInfo request2; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 14605 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14606 | request2.method = "GET"; |
| 14607 | request2.url = GURL(origin_url); |
| 14608 | request2.load_flags = 0; |
| 14609 | TestCompletionCallback callback2; |
| 14610 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14611 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14612 | EXPECT_THAT(callback2.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14613 | |
| 14614 | // Another transaction to alternative. This is to test that the HTTP/1.1 |
| 14615 | // socket is still open and in the pool. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14616 | HttpRequestInfo request3; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 14617 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14618 | request3.method = "GET"; |
| 14619 | request3.url = GURL(alternative_url); |
| 14620 | request3.load_flags = 0; |
| 14621 | TestCompletionCallback callback3; |
| 14622 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14623 | rv = trans3.Start(&request3, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14624 | EXPECT_THAT(callback3.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14625 | const HttpResponseInfo* response3 = trans3.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14626 | ASSERT_TRUE(response3); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14627 | ASSERT_TRUE(response3->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14628 | EXPECT_EQ("HTTP/1.1 200 OK", response3->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14629 | EXPECT_TRUE(response3->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14630 | EXPECT_FALSE(response3->was_fetched_via_spdy); |
| 14631 | std::string response_data3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14632 | ASSERT_THAT(ReadTransaction(&trans3, &response_data3), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14633 | EXPECT_EQ("second HTTP/1.1 response from alternative", response_data3); |
| 14634 | } |
| 14635 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14636 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14637 | const std::string https_url = "https://www.example.org:8080/"; |
| 14638 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14639 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14640 | // Separate SPDY util instance for naked and wrapped requests. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14641 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14642 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14643 | // SPDY GET for HTTPS URL (through CONNECT tunnel) |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14644 | const HostPortPair host_port_pair("www.example.org", 8080); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14645 | SpdySerializedFrame connect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 14646 | spdy_util_.ConstructSpdyConnect(NULL, 0, 1, LOWEST, host_port_pair)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14647 | SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14648 | spdy_util_wrapped.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14649 | SpdySerializedFrame wrapped_req1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 14650 | spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 14651 | |
| 14652 | // SPDY GET for HTTP URL (through the proxy, but not the tunnel). |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 14653 | SpdyHeaderBlock req2_block; |
| 14654 | req2_block[spdy_util_.GetMethodKey()] = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14655 | req2_block[spdy_util_.GetHostKey()] = "www.example.org:8080"; |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 14656 | req2_block[spdy_util_.GetSchemeKey()] = "http"; |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 14657 | req2_block[spdy_util_.GetPathKey()] = "/"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14658 | SpdySerializedFrame req2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14659 | spdy_util_.ConstructSpdyHeaders(3, std::move(req2_block), MEDIUM, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14660 | |
| 14661 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14662 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_req1, 2), |
| 14663 | CreateMockWrite(req2, 6), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14664 | }; |
| 14665 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14666 | SpdySerializedFrame conn_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14667 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14668 | SpdySerializedFrame resp1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14669 | spdy_util_wrapped.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14670 | SpdySerializedFrame body1(spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 14671 | SpdySerializedFrame wrapped_resp1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14672 | spdy_util_wrapped.ConstructWrappedSpdyFrame(resp1, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14673 | SpdySerializedFrame wrapped_body1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14674 | spdy_util_wrapped.ConstructWrappedSpdyFrame(body1, 1)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14675 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14676 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14677 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14678 | CreateMockRead(conn_resp, 1), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14679 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14680 | CreateMockRead(wrapped_resp1, 4), |
| 14681 | CreateMockRead(wrapped_body1, 5), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14682 | MockRead(ASYNC, ERR_IO_PENDING, 7), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14683 | CreateMockRead(resp2, 8), |
| 14684 | CreateMockRead(body2, 9), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14685 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 10), |
| 14686 | }; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14687 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14688 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 14689 | arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14690 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 14691 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14692 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 14693 | session_deps_.proxy_service = |
| 14694 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14695 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14696 | session_deps_.net_log = &log; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14697 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14698 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14699 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14700 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14701 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14702 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 14703 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14704 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14705 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14706 | |
| 14707 | // Start the first transaction to set up the SpdySession |
| 14708 | HttpRequestInfo request1; |
| 14709 | request1.method = "GET"; |
| 14710 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14711 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14712 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14713 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14714 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14715 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14716 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 14717 | data1.RunUntilPaused(); |
| 14718 | base::RunLoop().RunUntilIdle(); |
| 14719 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14720 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14721 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 14722 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 14723 | LoadTimingInfo load_timing_info1; |
| 14724 | EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); |
| 14725 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 14726 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 14727 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14728 | // Now, start the HTTP request. |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14729 | HttpRequestInfo request2; |
| 14730 | request2.method = "GET"; |
| 14731 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14732 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14733 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14734 | TestCompletionCallback callback2; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14735 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14736 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14737 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 14738 | data1.RunUntilPaused(); |
| 14739 | base::RunLoop().RunUntilIdle(); |
| 14740 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14741 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14742 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14743 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 14744 | |
| 14745 | LoadTimingInfo load_timing_info2; |
| 14746 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
| 14747 | // The established SPDY sessions is considered reused by the HTTP request. |
| 14748 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 14749 | // HTTP requests over a SPDY session should have a different connection |
| 14750 | // socket_log_id than requests over a tunnel. |
| 14751 | 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] | 14752 | } |
| 14753 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14754 | // Test that in the case where we have a SPDY session to a SPDY proxy |
| 14755 | // that we do not pool other origins that resolve to the same IP when |
| 14756 | // the certificate does not match the new origin. |
| 14757 | // http://crbug.com/134690 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14758 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14759 | const std::string url1 = "http://www.example.org/"; |
| 14760 | const std::string url2 = "https://news.example.org/"; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14761 | const std::string ip_addr = "1.2.3.4"; |
| 14762 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14763 | // Second SpdyTestUtil instance for the second socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14764 | SpdyTestUtil spdy_util_secure; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14765 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14766 | // SPDY GET for HTTP URL (through SPDY proxy) |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 14767 | SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14768 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14769 | SpdySerializedFrame req1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14770 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14771 | |
| 14772 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14773 | CreateMockWrite(req1, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14774 | }; |
| 14775 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14776 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14777 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14778 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14779 | MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(resp1, 2), |
| 14780 | CreateMockRead(body1, 3), MockRead(ASYNC, OK, 4), // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14781 | }; |
| 14782 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14783 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 14784 | arraysize(writes1)); |
martijn | fe9636e | 2016-02-06 14:33:32 | [diff] [blame] | 14785 | IPAddress ip; |
martijn | 654c8c4 | 2016-02-10 22:10:59 | [diff] [blame] | 14786 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14787 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 14788 | MockConnect connect_data1(ASYNC, OK, peer_addr); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14789 | data1.set_connect_data(connect_data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14790 | |
| 14791 | // SPDY GET for HTTPS URL (direct) |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14792 | SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14793 | spdy_util_secure.ConstructSpdyGet(url2.c_str(), 1, MEDIUM)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14794 | |
| 14795 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14796 | CreateMockWrite(req2, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14797 | }; |
| 14798 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14799 | SpdySerializedFrame resp2(spdy_util_secure.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14800 | SpdySerializedFrame body2(spdy_util_secure.ConstructSpdyDataFrame(1, true)); |
| 14801 | MockRead reads2[] = {CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14802 | MockRead(ASYNC, OK, 3)}; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14803 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14804 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 14805 | arraysize(writes2)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14806 | MockConnect connect_data2(ASYNC, OK); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14807 | data2.set_connect_data(connect_data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14808 | |
| 14809 | // Set up a proxy config that sends HTTP requests to a proxy, and |
| 14810 | // all others direct. |
| 14811 | ProxyConfig proxy_config; |
| 14812 | proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14813 | session_deps_.proxy_service = std::make_unique<ProxyService>( |
| 14814 | std::make_unique<ProxyConfigServiceFixed>(proxy_config), nullptr, |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14815 | nullptr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14816 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14817 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14818 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14819 | // Load a valid cert. Note, that this does not need to |
| 14820 | // be valid for proxy because the MockSSLClientSocket does |
| 14821 | // not actually verify it. But SpdySession will use this |
| 14822 | // to see if it is valid for the new origin |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14823 | ssl1.cert = ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem"); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14824 | ASSERT_TRUE(ssl1.cert); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14825 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 14826 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14827 | |
| 14828 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14829 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14830 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 14831 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14832 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14833 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14834 | session_deps_.host_resolver->rules()->AddRule("news.example.org", ip_addr); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14835 | session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14836 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14837 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14838 | |
| 14839 | // Start the first transaction to set up the SpdySession |
| 14840 | HttpRequestInfo request1; |
| 14841 | request1.method = "GET"; |
| 14842 | request1.url = GURL(url1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14843 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14844 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14845 | TestCompletionCallback callback1; |
| 14846 | ASSERT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14847 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14848 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 14849 | data1.RunUntilPaused(); |
| 14850 | base::RunLoop().RunUntilIdle(); |
| 14851 | data1.Resume(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14852 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14853 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14854 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 14855 | |
| 14856 | // Now, start the HTTP request |
| 14857 | HttpRequestInfo request2; |
| 14858 | request2.method = "GET"; |
| 14859 | request2.url = GURL(url2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14860 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14861 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14862 | TestCompletionCallback callback2; |
| 14863 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14864 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 14865 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14866 | |
| 14867 | ASSERT_TRUE(callback2.have_result()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14868 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14869 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 14870 | } |
| 14871 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14872 | // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 14873 | // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 14874 | // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 14875 | // SpdySession) do work. http://crbug.com/224701 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14876 | TEST_F(HttpNetworkTransactionTest, ErrorSocketNotConnected) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14877 | const std::string https_url = "https://www.example.org/"; |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14878 | |
| 14879 | MockRead reads1[] = { |
| 14880 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 14881 | }; |
| 14882 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14883 | SequencedSocketData data1(reads1, arraysize(reads1), NULL, 0); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14884 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14885 | SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14886 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, MEDIUM)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14887 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14888 | CreateMockWrite(req2, 0), |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14889 | }; |
| 14890 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14891 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14892 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14893 | MockRead reads2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14894 | CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
| 14895 | MockRead(ASYNC, OK, 3) // EOF |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14896 | }; |
| 14897 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14898 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 14899 | arraysize(writes2)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14900 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14901 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14902 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14903 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 14904 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14905 | |
| 14906 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14907 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14908 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 14909 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14910 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14911 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14912 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14913 | |
| 14914 | // Start the first transaction to set up the SpdySession and verify that |
| 14915 | // connection was closed. |
| 14916 | HttpRequestInfo request1; |
| 14917 | request1.method = "GET"; |
| 14918 | request1.url = GURL(https_url); |
| 14919 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14920 | HttpNetworkTransaction trans1(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14921 | TestCompletionCallback callback1; |
| 14922 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14923 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14924 | EXPECT_THAT(callback1.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14925 | |
| 14926 | // Now, start the second request and make sure it succeeds. |
| 14927 | HttpRequestInfo request2; |
| 14928 | request2.method = "GET"; |
| 14929 | request2.url = GURL(https_url); |
| 14930 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14931 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14932 | TestCompletionCallback callback2; |
| 14933 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14934 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14935 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14936 | ASSERT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14937 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 14938 | } |
| 14939 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14940 | TEST_F(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14941 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 14942 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14943 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 14944 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14945 | |
| 14946 | // Use two different hosts with different IPs so they don't get pooled. |
| 14947 | session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); |
| 14948 | session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14949 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14950 | |
| 14951 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14952 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14953 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14954 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14955 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 14956 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 14957 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14958 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14959 | spdy_util_.ConstructSpdyGet("https://www.a.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14960 | MockWrite spdy1_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14961 | CreateMockWrite(host1_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14962 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14963 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14964 | SpdySerializedFrame host1_resp_body( |
| 14965 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14966 | MockRead spdy1_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14967 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 14968 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14969 | }; |
| 14970 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14971 | // Use a separate test instance for the separate SpdySession that will be |
| 14972 | // created. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14973 | SpdyTestUtil spdy_util_2; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14974 | auto spdy1_data = std::make_unique<SequencedSocketData>( |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14975 | spdy1_reads, arraysize(spdy1_reads), spdy1_writes, |
| 14976 | arraysize(spdy1_writes)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14977 | session_deps_.socket_factory->AddSocketDataProvider(spdy1_data.get()); |
| 14978 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14979 | SpdySerializedFrame host2_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14980 | spdy_util_2.ConstructSpdyGet("https://www.b.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14981 | MockWrite spdy2_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14982 | CreateMockWrite(host2_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14983 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14984 | SpdySerializedFrame host2_resp(spdy_util_2.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14985 | SpdySerializedFrame host2_resp_body( |
| 14986 | spdy_util_2.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14987 | MockRead spdy2_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14988 | CreateMockRead(host2_resp, 1), CreateMockRead(host2_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 14989 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14990 | }; |
| 14991 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14992 | auto spdy2_data = std::make_unique<SequencedSocketData>( |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14993 | spdy2_reads, arraysize(spdy2_reads), spdy2_writes, |
| 14994 | arraysize(spdy2_writes)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14995 | session_deps_.socket_factory->AddSocketDataProvider(spdy2_data.get()); |
| 14996 | |
| 14997 | MockWrite http_write[] = { |
| 14998 | MockWrite("GET / HTTP/1.1\r\n" |
| 14999 | "Host: www.a.com\r\n" |
| 15000 | "Connection: keep-alive\r\n\r\n"), |
| 15001 | }; |
| 15002 | |
| 15003 | MockRead http_read[] = { |
| 15004 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15005 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 15006 | MockRead("Content-Length: 6\r\n\r\n"), |
| 15007 | MockRead("hello!"), |
| 15008 | }; |
| 15009 | StaticSocketDataProvider http_data(http_read, arraysize(http_read), |
| 15010 | http_write, arraysize(http_write)); |
| 15011 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 15012 | |
| 15013 | HostPortPair host_port_pair_a("www.a.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 15014 | SpdySessionKey spdy_session_key_a( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 15015 | host_port_pair_a, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15016 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15017 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15018 | |
| 15019 | TestCompletionCallback callback; |
| 15020 | HttpRequestInfo request1; |
| 15021 | request1.method = "GET"; |
| 15022 | request1.url = GURL("https://www.a.com/"); |
| 15023 | request1.load_flags = 0; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15024 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15025 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15026 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15027 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15028 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15029 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15030 | |
| 15031 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15032 | ASSERT_TRUE(response); |
| 15033 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15034 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15035 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15036 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15037 | |
| 15038 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15039 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15040 | EXPECT_EQ("hello!", response_data); |
| 15041 | trans.reset(); |
| 15042 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15043 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15044 | |
| 15045 | HostPortPair host_port_pair_b("www.b.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 15046 | SpdySessionKey spdy_session_key_b( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 15047 | host_port_pair_b, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15048 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15049 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15050 | HttpRequestInfo request2; |
| 15051 | request2.method = "GET"; |
| 15052 | request2.url = GURL("https://www.b.com/"); |
| 15053 | request2.load_flags = 0; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15054 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15055 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15056 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15057 | rv = trans->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15058 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15059 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15060 | |
| 15061 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15062 | ASSERT_TRUE(response); |
| 15063 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15064 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15065 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15066 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15067 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15068 | EXPECT_EQ("hello!", response_data); |
| 15069 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15070 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15071 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15072 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15073 | |
| 15074 | HostPortPair host_port_pair_a1("www.a.com", 80); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 15075 | SpdySessionKey spdy_session_key_a1( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 15076 | host_port_pair_a1, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15077 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15078 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15079 | HttpRequestInfo request3; |
| 15080 | request3.method = "GET"; |
| 15081 | request3.url = GURL("http://www.a.com/"); |
| 15082 | request3.load_flags = 0; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15083 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15084 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15085 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15086 | rv = trans->Start(&request3, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15087 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15088 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15089 | |
| 15090 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15091 | ASSERT_TRUE(response); |
| 15092 | ASSERT_TRUE(response->headers); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15093 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 15094 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15095 | EXPECT_FALSE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15096 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15097 | EXPECT_EQ("hello!", response_data); |
| 15098 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15099 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15100 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15101 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15102 | } |
| 15103 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15104 | TEST_F(HttpNetworkTransactionTest, HttpSyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15105 | HttpRequestInfo request; |
| 15106 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15107 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15108 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15109 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15110 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15111 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15112 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15113 | StaticSocketDataProvider data; |
| 15114 | data.set_connect_data(mock_connect); |
| 15115 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15116 | |
| 15117 | TestCompletionCallback callback; |
| 15118 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15119 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15120 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15121 | |
| 15122 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15123 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15124 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15125 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 15126 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15127 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 15128 | |
| 15129 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15130 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 15131 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15132 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15133 | |
| 15134 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15135 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15136 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15137 | } |
| 15138 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15139 | TEST_F(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15140 | HttpRequestInfo request; |
| 15141 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15142 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15143 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15144 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15145 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15146 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15147 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15148 | StaticSocketDataProvider data; |
| 15149 | data.set_connect_data(mock_connect); |
| 15150 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15151 | |
| 15152 | TestCompletionCallback callback; |
| 15153 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15154 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15155 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15156 | |
| 15157 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15158 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15159 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15160 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 15161 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15162 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 15163 | |
| 15164 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15165 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 15166 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15167 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15168 | |
| 15169 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15170 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15171 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15172 | } |
| 15173 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15174 | TEST_F(HttpNetworkTransactionTest, HttpSyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15175 | HttpRequestInfo request; |
| 15176 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15177 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15178 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15179 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15180 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15181 | |
| 15182 | MockWrite data_writes[] = { |
| 15183 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15184 | }; |
| 15185 | MockRead data_reads[] = { |
| 15186 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 15187 | }; |
| 15188 | |
| 15189 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 15190 | data_writes, arraysize(data_writes)); |
| 15191 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15192 | |
| 15193 | TestCompletionCallback callback; |
| 15194 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15195 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15196 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15197 | |
| 15198 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15199 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15200 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15201 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15202 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15203 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 15204 | } |
| 15205 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15206 | TEST_F(HttpNetworkTransactionTest, HttpAsyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15207 | HttpRequestInfo request; |
| 15208 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15209 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15210 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15211 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15212 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15213 | |
| 15214 | MockWrite data_writes[] = { |
| 15215 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
| 15216 | }; |
| 15217 | MockRead data_reads[] = { |
| 15218 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 15219 | }; |
| 15220 | |
| 15221 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 15222 | data_writes, arraysize(data_writes)); |
| 15223 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15224 | |
| 15225 | TestCompletionCallback callback; |
| 15226 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15227 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15228 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15229 | |
| 15230 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15231 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15232 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15233 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15234 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15235 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 15236 | } |
| 15237 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15238 | TEST_F(HttpNetworkTransactionTest, HttpSyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15239 | HttpRequestInfo request; |
| 15240 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15241 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15242 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15243 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15244 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15245 | |
| 15246 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15247 | MockWrite( |
| 15248 | "GET / HTTP/1.1\r\n" |
| 15249 | "Host: www.example.org\r\n" |
| 15250 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15251 | }; |
| 15252 | MockRead data_reads[] = { |
| 15253 | MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15254 | }; |
| 15255 | |
| 15256 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 15257 | data_writes, arraysize(data_writes)); |
| 15258 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15259 | |
| 15260 | TestCompletionCallback callback; |
| 15261 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15262 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15263 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15264 | |
| 15265 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15266 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15267 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15268 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15269 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15270 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 15271 | } |
| 15272 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15273 | TEST_F(HttpNetworkTransactionTest, HttpAsyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15274 | HttpRequestInfo request; |
| 15275 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15276 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15277 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15278 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15279 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15280 | |
| 15281 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15282 | MockWrite( |
| 15283 | "GET / HTTP/1.1\r\n" |
| 15284 | "Host: www.example.org\r\n" |
| 15285 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15286 | }; |
| 15287 | MockRead data_reads[] = { |
| 15288 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 15289 | }; |
| 15290 | |
| 15291 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 15292 | data_writes, arraysize(data_writes)); |
| 15293 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15294 | |
| 15295 | TestCompletionCallback callback; |
| 15296 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15297 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15298 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15299 | |
| 15300 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15301 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15302 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15303 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15304 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15305 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 15306 | } |
| 15307 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15308 | TEST_F(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15309 | HttpRequestInfo request; |
| 15310 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15311 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15312 | request.extra_headers.SetHeader("X-Foo", "bar"); |
| 15313 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15314 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15315 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15316 | |
| 15317 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15318 | MockWrite( |
| 15319 | "GET / HTTP/1.1\r\n" |
| 15320 | "Host: www.example.org\r\n" |
| 15321 | "Connection: keep-alive\r\n" |
| 15322 | "X-Foo: bar\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15323 | }; |
| 15324 | MockRead data_reads[] = { |
| 15325 | MockRead("HTTP/1.1 200 OK\r\n" |
| 15326 | "Content-Length: 5\r\n\r\n" |
| 15327 | "hello"), |
| 15328 | MockRead(ASYNC, ERR_UNEXPECTED), |
| 15329 | }; |
| 15330 | |
| 15331 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 15332 | data_writes, arraysize(data_writes)); |
| 15333 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15334 | |
| 15335 | TestCompletionCallback callback; |
| 15336 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15337 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15338 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15339 | |
| 15340 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15341 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15342 | |
| 15343 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15344 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15345 | std::string foo; |
| 15346 | EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo)); |
| 15347 | EXPECT_EQ("bar", foo); |
| 15348 | } |
| 15349 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15350 | namespace { |
| 15351 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 15352 | // Fake HttpStream that simply records calls to SetPriority(). |
| 15353 | class FakeStream : public HttpStream, |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15354 | public base::SupportsWeakPtr<FakeStream> { |
| 15355 | public: |
| 15356 | explicit FakeStream(RequestPriority priority) : priority_(priority) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15357 | ~FakeStream() override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15358 | |
| 15359 | RequestPriority priority() const { return priority_; } |
| 15360 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15361 | int InitializeStream(const HttpRequestInfo* request_info, |
| 15362 | RequestPriority priority, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15363 | const NetLogWithSource& net_log, |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15364 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15365 | return ERR_IO_PENDING; |
| 15366 | } |
| 15367 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15368 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 15369 | HttpResponseInfo* response, |
| 15370 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15371 | ADD_FAILURE(); |
| 15372 | return ERR_UNEXPECTED; |
| 15373 | } |
| 15374 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15375 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15376 | ADD_FAILURE(); |
| 15377 | return ERR_UNEXPECTED; |
| 15378 | } |
| 15379 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15380 | int ReadResponseBody(IOBuffer* buf, |
| 15381 | int buf_len, |
| 15382 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15383 | ADD_FAILURE(); |
| 15384 | return ERR_UNEXPECTED; |
| 15385 | } |
| 15386 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15387 | void Close(bool not_reusable) override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15388 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15389 | bool IsResponseBodyComplete() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15390 | ADD_FAILURE(); |
| 15391 | return false; |
| 15392 | } |
| 15393 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15394 | bool IsConnectionReused() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15395 | ADD_FAILURE(); |
| 15396 | return false; |
| 15397 | } |
| 15398 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15399 | void SetConnectionReused() override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15400 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 15401 | bool CanReuseConnection() const override { return false; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15402 | |
sclittle | 4de1bab9 | 2015-09-22 21:28:24 | [diff] [blame] | 15403 | int64_t GetTotalReceivedBytes() const override { |
[email protected] | bc92bc97 | 2013-12-13 08:32:59 | [diff] [blame] | 15404 | ADD_FAILURE(); |
| 15405 | return 0; |
| 15406 | } |
| 15407 | |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 15408 | int64_t GetTotalSentBytes() const override { |
| 15409 | ADD_FAILURE(); |
| 15410 | return 0; |
| 15411 | } |
| 15412 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15413 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15414 | ADD_FAILURE(); |
| 15415 | return false; |
| 15416 | } |
| 15417 | |
rch | cd37901 | 2017-04-12 21:53:32 | [diff] [blame] | 15418 | bool GetAlternativeService( |
| 15419 | AlternativeService* alternative_service) const override { |
| 15420 | ADD_FAILURE(); |
| 15421 | return false; |
| 15422 | } |
| 15423 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15424 | void GetSSLInfo(SSLInfo* ssl_info) override { ADD_FAILURE(); } |
| 15425 | |
| 15426 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15427 | ADD_FAILURE(); |
| 15428 | } |
| 15429 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15430 | bool GetRemoteEndpoint(IPEndPoint* endpoint) override { return false; } |
| 15431 | |
nharper | 78e6d2b | 2016-09-21 05:42:35 | [diff] [blame] | 15432 | Error GetTokenBindingSignature(crypto::ECPrivateKey* key, |
| 15433 | TokenBindingType tb_type, |
| 15434 | std::vector<uint8_t>* out) override { |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 15435 | ADD_FAILURE(); |
| 15436 | return ERR_NOT_IMPLEMENTED; |
| 15437 | } |
| 15438 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15439 | void Drain(HttpNetworkSession* session) override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15440 | |
zhongyi | ca364fbb | 2015-12-12 03:39:12 | [diff] [blame] | 15441 | void PopulateNetErrorDetails(NetErrorDetails* details) override { return; } |
| 15442 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15443 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15444 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 15445 | HttpStream* RenewStreamForAuth() override { return NULL; } |
| 15446 | |
Andrey Kosyakov | 83a6eee | 2017-08-14 19:20:04 | [diff] [blame] | 15447 | void SetRequestHeadersCallback(RequestHeadersCallback callback) override {} |
| 15448 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15449 | private: |
| 15450 | RequestPriority priority_; |
| 15451 | |
| 15452 | DISALLOW_COPY_AND_ASSIGN(FakeStream); |
| 15453 | }; |
| 15454 | |
| 15455 | // Fake HttpStreamRequest that simply records calls to SetPriority() |
| 15456 | // and vends FakeStreams with its current priority. |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15457 | class FakeStreamRequest : public HttpStreamRequest, |
| 15458 | public base::SupportsWeakPtr<FakeStreamRequest> { |
| 15459 | public: |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15460 | FakeStreamRequest(RequestPriority priority, |
| 15461 | HttpStreamRequest::Delegate* delegate) |
| 15462 | : priority_(priority), |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15463 | delegate_(delegate), |
| 15464 | websocket_stream_create_helper_(NULL) {} |
| 15465 | |
| 15466 | FakeStreamRequest(RequestPriority priority, |
| 15467 | HttpStreamRequest::Delegate* delegate, |
| 15468 | WebSocketHandshakeStreamBase::CreateHelper* create_helper) |
| 15469 | : priority_(priority), |
| 15470 | delegate_(delegate), |
| 15471 | websocket_stream_create_helper_(create_helper) {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15472 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15473 | ~FakeStreamRequest() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15474 | |
| 15475 | RequestPriority priority() const { return priority_; } |
| 15476 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15477 | const WebSocketHandshakeStreamBase::CreateHelper* |
| 15478 | websocket_stream_create_helper() const { |
| 15479 | return websocket_stream_create_helper_; |
| 15480 | } |
| 15481 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15482 | // Create a new FakeStream and pass it to the request's |
| 15483 | // delegate. Returns a weak pointer to the FakeStream. |
| 15484 | base::WeakPtr<FakeStream> FinishStreamRequest() { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15485 | auto fake_stream = std::make_unique<FakeStream>(priority_); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15486 | // Do this before calling OnStreamReady() as OnStreamReady() may |
| 15487 | // immediately delete |fake_stream|. |
| 15488 | base::WeakPtr<FakeStream> weak_stream = fake_stream->AsWeakPtr(); |
bnc | 5029f463 | 2017-06-08 16:19:00 | [diff] [blame] | 15489 | delegate_->OnStreamReady(SSLConfig(), ProxyInfo(), std::move(fake_stream)); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15490 | return weak_stream; |
| 15491 | } |
| 15492 | |
asanka | 681f02d | 2017-02-22 17:06:39 | [diff] [blame] | 15493 | int RestartTunnelWithProxyAuth() override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15494 | ADD_FAILURE(); |
| 15495 | return ERR_UNEXPECTED; |
| 15496 | } |
| 15497 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15498 | LoadState GetLoadState() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15499 | ADD_FAILURE(); |
| 15500 | return LoadState(); |
| 15501 | } |
| 15502 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15503 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15504 | |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15505 | bool was_alpn_negotiated() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15506 | |
bnc | 6227b26e | 2016-08-12 02:00:43 | [diff] [blame] | 15507 | NextProto negotiated_protocol() const override { return kProtoUnknown; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15508 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15509 | bool using_spdy() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15510 | |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 15511 | const ConnectionAttempts& connection_attempts() const override { |
| 15512 | static ConnectionAttempts no_attempts; |
| 15513 | return no_attempts; |
| 15514 | } |
| 15515 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15516 | private: |
| 15517 | RequestPriority priority_; |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15518 | HttpStreamRequest::Delegate* const delegate_; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15519 | WebSocketHandshakeStreamBase::CreateHelper* websocket_stream_create_helper_; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15520 | |
| 15521 | DISALLOW_COPY_AND_ASSIGN(FakeStreamRequest); |
| 15522 | }; |
| 15523 | |
| 15524 | // Fake HttpStreamFactory that vends FakeStreamRequests. |
| 15525 | class FakeStreamFactory : public HttpStreamFactory { |
| 15526 | public: |
| 15527 | FakeStreamFactory() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15528 | ~FakeStreamFactory() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15529 | |
| 15530 | // Returns a WeakPtr<> to the last HttpStreamRequest returned by |
| 15531 | // RequestStream() (which may be NULL if it was destroyed already). |
| 15532 | base::WeakPtr<FakeStreamRequest> last_stream_request() { |
| 15533 | return last_stream_request_; |
| 15534 | } |
| 15535 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15536 | std::unique_ptr<HttpStreamRequest> RequestStream( |
| 15537 | const HttpRequestInfo& info, |
| 15538 | RequestPriority priority, |
| 15539 | const SSLConfig& server_ssl_config, |
| 15540 | const SSLConfig& proxy_ssl_config, |
| 15541 | HttpStreamRequest::Delegate* delegate, |
| 15542 | bool enable_ip_based_pooling, |
| 15543 | bool enable_alternative_services, |
| 15544 | const NetLogWithSource& net_log) override { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15545 | auto fake_request = std::make_unique<FakeStreamRequest>(priority, delegate); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15546 | last_stream_request_ = fake_request->AsWeakPtr(); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15547 | return std::move(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15548 | } |
| 15549 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15550 | std::unique_ptr<HttpStreamRequest> RequestBidirectionalStreamImpl( |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 15551 | const HttpRequestInfo& info, |
| 15552 | RequestPriority priority, |
| 15553 | const SSLConfig& server_ssl_config, |
| 15554 | const SSLConfig& proxy_ssl_config, |
| 15555 | HttpStreamRequest::Delegate* delegate, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15556 | bool enable_ip_based_pooling, |
bnc | accd496 | 2017-04-06 21:00:26 | [diff] [blame] | 15557 | bool enable_alternative_services, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15558 | const NetLogWithSource& net_log) override { |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 15559 | NOTREACHED(); |
| 15560 | return nullptr; |
| 15561 | } |
| 15562 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15563 | std::unique_ptr<HttpStreamRequest> RequestWebSocketHandshakeStream( |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15564 | const HttpRequestInfo& info, |
| 15565 | RequestPriority priority, |
| 15566 | const SSLConfig& server_ssl_config, |
| 15567 | const SSLConfig& proxy_ssl_config, |
| 15568 | HttpStreamRequest::Delegate* delegate, |
[email protected] | 467086b | 2013-11-12 08:19:46 | [diff] [blame] | 15569 | WebSocketHandshakeStreamBase::CreateHelper* create_helper, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15570 | bool enable_ip_based_pooling, |
bnc | accd496 | 2017-04-06 21:00:26 | [diff] [blame] | 15571 | bool enable_alternative_services, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15572 | const NetLogWithSource& net_log) override { |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15573 | auto fake_request = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15574 | std::make_unique<FakeStreamRequest>(priority, delegate, create_helper); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15575 | last_stream_request_ = fake_request->AsWeakPtr(); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15576 | return std::move(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15577 | } |
| 15578 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15579 | void PreconnectStreams(int num_streams, |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 15580 | const HttpRequestInfo& info) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15581 | ADD_FAILURE(); |
| 15582 | } |
| 15583 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15584 | const HostMappingRules* GetHostMappingRules() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15585 | ADD_FAILURE(); |
| 15586 | return NULL; |
| 15587 | } |
| 15588 | |
xunjieli | f5267de | 2017-01-20 21:18:57 | [diff] [blame] | 15589 | void DumpMemoryStats(base::trace_event::ProcessMemoryDump* pmd, |
| 15590 | const std::string& parent_absolute_name) const override { |
| 15591 | ADD_FAILURE(); |
| 15592 | } |
| 15593 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15594 | private: |
| 15595 | base::WeakPtr<FakeStreamRequest> last_stream_request_; |
| 15596 | |
| 15597 | DISALLOW_COPY_AND_ASSIGN(FakeStreamFactory); |
| 15598 | }; |
| 15599 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15600 | // TODO(ricea): Maybe unify this with the one in |
| 15601 | // url_request_http_job_unittest.cc ? |
| 15602 | class FakeWebSocketBasicHandshakeStream : public WebSocketHandshakeStreamBase { |
| 15603 | public: |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15604 | FakeWebSocketBasicHandshakeStream( |
| 15605 | std::unique_ptr<ClientSocketHandle> connection, |
| 15606 | bool using_proxy) |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 15607 | : state_(std::move(connection), using_proxy, false) {} |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15608 | |
| 15609 | // Fake implementation of HttpStreamBase methods. |
| 15610 | // This ends up being quite "real" because this object has to really send data |
| 15611 | // on the mock socket. It might be easier to use the real implementation, but |
| 15612 | // the fact that the WebSocket code is not compiled on iOS makes that |
| 15613 | // difficult. |
| 15614 | int InitializeStream(const HttpRequestInfo* request_info, |
| 15615 | RequestPriority priority, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15616 | const NetLogWithSource& net_log, |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15617 | const CompletionCallback& callback) override { |
| 15618 | state_.Initialize(request_info, priority, net_log, callback); |
| 15619 | return OK; |
| 15620 | } |
| 15621 | |
| 15622 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 15623 | HttpResponseInfo* response, |
| 15624 | const CompletionCallback& callback) override { |
| 15625 | return parser()->SendRequest(state_.GenerateRequestLine(), request_headers, |
| 15626 | response, callback); |
| 15627 | } |
| 15628 | |
| 15629 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
| 15630 | return parser()->ReadResponseHeaders(callback); |
| 15631 | } |
| 15632 | |
| 15633 | int ReadResponseBody(IOBuffer* buf, |
| 15634 | int buf_len, |
| 15635 | const CompletionCallback& callback) override { |
| 15636 | NOTREACHED(); |
| 15637 | return ERR_IO_PENDING; |
| 15638 | } |
| 15639 | |
| 15640 | void Close(bool not_reusable) override { |
| 15641 | if (parser()) |
| 15642 | parser()->Close(true); |
| 15643 | } |
| 15644 | |
| 15645 | bool IsResponseBodyComplete() const override { |
| 15646 | NOTREACHED(); |
| 15647 | return false; |
| 15648 | } |
| 15649 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15650 | bool IsConnectionReused() const override { |
| 15651 | NOTREACHED(); |
| 15652 | return false; |
| 15653 | } |
| 15654 | void SetConnectionReused() override { NOTREACHED(); } |
| 15655 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 15656 | bool CanReuseConnection() const override { return false; } |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15657 | |
sclittle | 4de1bab9 | 2015-09-22 21:28:24 | [diff] [blame] | 15658 | int64_t GetTotalReceivedBytes() const override { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15659 | NOTREACHED(); |
| 15660 | return 0; |
| 15661 | } |
| 15662 | |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 15663 | int64_t GetTotalSentBytes() const override { |
| 15664 | NOTREACHED(); |
| 15665 | return 0; |
| 15666 | } |
| 15667 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15668 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
| 15669 | NOTREACHED(); |
| 15670 | return false; |
| 15671 | } |
| 15672 | |
rch | cd37901 | 2017-04-12 21:53:32 | [diff] [blame] | 15673 | bool GetAlternativeService( |
| 15674 | AlternativeService* alternative_service) const override { |
| 15675 | ADD_FAILURE(); |
| 15676 | return false; |
| 15677 | } |
| 15678 | |
Adam Rice | cb76ac6 | 2015-02-20 05:33:25 | [diff] [blame] | 15679 | void GetSSLInfo(SSLInfo* ssl_info) override {} |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15680 | |
| 15681 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
| 15682 | NOTREACHED(); |
| 15683 | } |
| 15684 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15685 | bool GetRemoteEndpoint(IPEndPoint* endpoint) override { return false; } |
| 15686 | |
nharper | 78e6d2b | 2016-09-21 05:42:35 | [diff] [blame] | 15687 | Error GetTokenBindingSignature(crypto::ECPrivateKey* key, |
| 15688 | TokenBindingType tb_type, |
| 15689 | std::vector<uint8_t>* out) override { |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 15690 | ADD_FAILURE(); |
| 15691 | return ERR_NOT_IMPLEMENTED; |
| 15692 | } |
| 15693 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15694 | void Drain(HttpNetworkSession* session) override { NOTREACHED(); } |
| 15695 | |
zhongyi | ca364fbb | 2015-12-12 03:39:12 | [diff] [blame] | 15696 | void PopulateNetErrorDetails(NetErrorDetails* details) override { return; } |
| 15697 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15698 | void SetPriority(RequestPriority priority) override { NOTREACHED(); } |
| 15699 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15700 | HttpStream* RenewStreamForAuth() override { |
| 15701 | NOTREACHED(); |
| 15702 | return nullptr; |
| 15703 | } |
| 15704 | |
| 15705 | // Fake implementation of WebSocketHandshakeStreamBase method(s) |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15706 | std::unique_ptr<WebSocketStream> Upgrade() override { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15707 | NOTREACHED(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15708 | return std::unique_ptr<WebSocketStream>(); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15709 | } |
| 15710 | |
| 15711 | private: |
| 15712 | HttpStreamParser* parser() const { return state_.parser(); } |
| 15713 | HttpBasicState state_; |
| 15714 | |
| 15715 | DISALLOW_COPY_AND_ASSIGN(FakeWebSocketBasicHandshakeStream); |
| 15716 | }; |
| 15717 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15718 | // TODO(yhirano): Split this class out into a net/websockets file, if it is |
| 15719 | // worth doing. |
| 15720 | class FakeWebSocketStreamCreateHelper : |
| 15721 | public WebSocketHandshakeStreamBase::CreateHelper { |
| 15722 | public: |
bnc | 615cf2f | 2017-05-19 18:53:26 | [diff] [blame] | 15723 | std::unique_ptr<WebSocketHandshakeStreamBase> CreateBasicStream( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15724 | std::unique_ptr<ClientSocketHandle> connection, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 15725 | bool using_proxy) override { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15726 | return std::make_unique<FakeWebSocketBasicHandshakeStream>( |
bnc | 615cf2f | 2017-05-19 18:53:26 | [diff] [blame] | 15727 | std::move(connection), using_proxy); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15728 | } |
| 15729 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15730 | ~FakeWebSocketStreamCreateHelper() override {} |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15731 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15732 | virtual std::unique_ptr<WebSocketStream> Upgrade() { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15733 | NOTREACHED(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15734 | return std::unique_ptr<WebSocketStream>(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15735 | } |
| 15736 | }; |
| 15737 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15738 | } // namespace |
| 15739 | |
| 15740 | // Make sure that HttpNetworkTransaction passes on its priority to its |
| 15741 | // stream request on start. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15742 | TEST_F(HttpNetworkTransactionTest, SetStreamRequestPriorityOnStart) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15743 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15744 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15745 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15746 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15747 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15748 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15749 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15750 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15751 | ASSERT_FALSE(fake_factory->last_stream_request()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15752 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15753 | TestCompletionCallback callback; |
| 15754 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15755 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15756 | |
| 15757 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 15758 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15759 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15760 | EXPECT_EQ(LOW, fake_request->priority()); |
| 15761 | } |
| 15762 | |
| 15763 | // Make sure that HttpNetworkTransaction passes on its priority |
| 15764 | // updates to its stream request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15765 | TEST_F(HttpNetworkTransactionTest, SetStreamRequestPriority) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15766 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15767 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15768 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15769 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15770 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15771 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15772 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15773 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15774 | TestCompletionCallback callback; |
| 15775 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15776 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15777 | |
| 15778 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 15779 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15780 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15781 | EXPECT_EQ(LOW, fake_request->priority()); |
| 15782 | |
| 15783 | trans.SetPriority(LOWEST); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15784 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15785 | EXPECT_EQ(LOWEST, fake_request->priority()); |
| 15786 | } |
| 15787 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15788 | // Make sure that HttpNetworkTransaction passes on its priority |
| 15789 | // updates to its stream. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15790 | TEST_F(HttpNetworkTransactionTest, SetStreamPriority) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15791 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15792 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15793 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15794 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15795 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15796 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15797 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15798 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15799 | TestCompletionCallback callback; |
| 15800 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15801 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15802 | |
| 15803 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 15804 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15805 | ASSERT_TRUE(fake_request); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15806 | base::WeakPtr<FakeStream> fake_stream = fake_request->FinishStreamRequest(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15807 | ASSERT_TRUE(fake_stream); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15808 | EXPECT_EQ(LOW, fake_stream->priority()); |
| 15809 | |
| 15810 | trans.SetPriority(LOWEST); |
| 15811 | EXPECT_EQ(LOWEST, fake_stream->priority()); |
| 15812 | } |
| 15813 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15814 | TEST_F(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15815 | // The same logic needs to be tested for both ws: and wss: schemes, but this |
| 15816 | // test is already parameterised on NextProto, so it uses a loop to verify |
| 15817 | // that the different schemes work. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15818 | std::string test_cases[] = {"ws://www.example.org/", |
| 15819 | "wss://www.example.org/"}; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15820 | for (size_t i = 0; i < arraysize(test_cases); ++i) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15821 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15822 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15823 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
| 15824 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
[email protected] | 0191b51c | 2013-11-18 10:55:23 | [diff] [blame] | 15825 | peer.SetHttpStreamFactoryForWebSocket( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15826 | std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15827 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15828 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15829 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15830 | trans.SetWebSocketHandshakeStreamCreateHelper( |
| 15831 | &websocket_stream_create_helper); |
| 15832 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15833 | TestCompletionCallback callback; |
| 15834 | request.method = "GET"; |
| 15835 | request.url = GURL(test_cases[i]); |
| 15836 | |
| 15837 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15838 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15839 | |
| 15840 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 15841 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15842 | ASSERT_TRUE(fake_request); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15843 | EXPECT_EQ(&websocket_stream_create_helper, |
| 15844 | fake_request->websocket_stream_create_helper()); |
| 15845 | } |
| 15846 | } |
| 15847 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15848 | // Tests that when a used socket is returned to the SSL socket pool, it's closed |
| 15849 | // if the transport socket pool is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15850 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15851 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 15852 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15853 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 15854 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15855 | |
| 15856 | // Set up SSL request. |
| 15857 | |
| 15858 | HttpRequestInfo ssl_request; |
| 15859 | ssl_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15860 | ssl_request.url = GURL("https://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15861 | |
| 15862 | MockWrite ssl_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15863 | MockWrite( |
| 15864 | "GET / HTTP/1.1\r\n" |
| 15865 | "Host: www.example.org\r\n" |
| 15866 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15867 | }; |
| 15868 | MockRead ssl_reads[] = { |
| 15869 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15870 | MockRead("Content-Length: 11\r\n\r\n"), |
| 15871 | MockRead("hello world"), |
| 15872 | MockRead(SYNCHRONOUS, OK), |
| 15873 | }; |
| 15874 | StaticSocketDataProvider ssl_data(ssl_reads, arraysize(ssl_reads), |
| 15875 | ssl_writes, arraysize(ssl_writes)); |
| 15876 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 15877 | |
| 15878 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 15879 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15880 | |
| 15881 | // Set up HTTP request. |
| 15882 | |
| 15883 | HttpRequestInfo http_request; |
| 15884 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15885 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15886 | |
| 15887 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15888 | MockWrite( |
| 15889 | "GET / HTTP/1.1\r\n" |
| 15890 | "Host: www.example.org\r\n" |
| 15891 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15892 | }; |
| 15893 | MockRead http_reads[] = { |
| 15894 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15895 | MockRead("Content-Length: 7\r\n\r\n"), |
| 15896 | MockRead("falafel"), |
| 15897 | MockRead(SYNCHRONOUS, OK), |
| 15898 | }; |
| 15899 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 15900 | http_writes, arraysize(http_writes)); |
| 15901 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 15902 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15903 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15904 | |
| 15905 | // Start the SSL request. |
| 15906 | TestCompletionCallback ssl_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15907 | HttpNetworkTransaction ssl_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15908 | ASSERT_EQ(ERR_IO_PENDING, |
| 15909 | ssl_trans.Start(&ssl_request, ssl_callback.callback(), |
| 15910 | NetLogWithSource())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15911 | |
| 15912 | // Start the HTTP request. Pool should stall. |
| 15913 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15914 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15915 | ASSERT_EQ(ERR_IO_PENDING, |
| 15916 | http_trans.Start(&http_request, http_callback.callback(), |
| 15917 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15918 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15919 | |
| 15920 | // Wait for response from SSL request. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15921 | ASSERT_THAT(ssl_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15922 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15923 | ASSERT_THAT(ReadTransaction(&ssl_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15924 | EXPECT_EQ("hello world", response_data); |
| 15925 | |
| 15926 | // The SSL socket should automatically be closed, so the HTTP request can |
| 15927 | // start. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15928 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 15929 | ASSERT_FALSE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15930 | |
| 15931 | // The HTTP request can now complete. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15932 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15933 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15934 | EXPECT_EQ("falafel", response_data); |
| 15935 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15936 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15937 | } |
| 15938 | |
| 15939 | // Tests that when a SSL connection is established but there's no corresponding |
| 15940 | // request that needs it, the new socket is closed if the transport socket pool |
| 15941 | // is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15942 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15943 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 15944 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15945 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 15946 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15947 | |
| 15948 | // Set up an ssl request. |
| 15949 | |
| 15950 | HttpRequestInfo ssl_request; |
| 15951 | ssl_request.method = "GET"; |
| 15952 | ssl_request.url = GURL("https://www.foopy.com/"); |
| 15953 | |
| 15954 | // No data will be sent on the SSL socket. |
| 15955 | StaticSocketDataProvider ssl_data; |
| 15956 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 15957 | |
| 15958 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 15959 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15960 | |
| 15961 | // Set up HTTP request. |
| 15962 | |
| 15963 | HttpRequestInfo http_request; |
| 15964 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15965 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15966 | |
| 15967 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15968 | MockWrite( |
| 15969 | "GET / HTTP/1.1\r\n" |
| 15970 | "Host: www.example.org\r\n" |
| 15971 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15972 | }; |
| 15973 | MockRead http_reads[] = { |
| 15974 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15975 | MockRead("Content-Length: 7\r\n\r\n"), |
| 15976 | MockRead("falafel"), |
| 15977 | MockRead(SYNCHRONOUS, OK), |
| 15978 | }; |
| 15979 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 15980 | http_writes, arraysize(http_writes)); |
| 15981 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 15982 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15983 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15984 | |
| 15985 | // Preconnect an SSL socket. A preconnect is needed because connect jobs are |
| 15986 | // cancelled when a normal transaction is cancelled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15987 | HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 15988 | http_stream_factory->PreconnectStreams(1, ssl_request); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15989 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15990 | |
| 15991 | // Start the HTTP request. Pool should stall. |
| 15992 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15993 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15994 | ASSERT_EQ(ERR_IO_PENDING, |
| 15995 | http_trans.Start(&http_request, http_callback.callback(), |
| 15996 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15997 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15998 | |
| 15999 | // The SSL connection will automatically be closed once the connection is |
| 16000 | // established, to let the HTTP request start. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16001 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16002 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16003 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16004 | EXPECT_EQ("falafel", response_data); |
| 16005 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16006 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16007 | } |
| 16008 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16009 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16010 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16011 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16012 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16013 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16014 | |
| 16015 | HttpRequestInfo request; |
| 16016 | request.method = "POST"; |
| 16017 | request.url = GURL("http://www.foo.com/"); |
| 16018 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16019 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16020 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16021 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16022 | // Send headers successfully, but get an error while sending the body. |
| 16023 | MockWrite data_writes[] = { |
| 16024 | MockWrite("POST / HTTP/1.1\r\n" |
| 16025 | "Host: www.foo.com\r\n" |
| 16026 | "Connection: keep-alive\r\n" |
| 16027 | "Content-Length: 3\r\n\r\n"), |
| 16028 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16029 | }; |
| 16030 | |
| 16031 | MockRead data_reads[] = { |
| 16032 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 16033 | MockRead("hello world"), |
| 16034 | MockRead(SYNCHRONOUS, OK), |
| 16035 | }; |
| 16036 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16037 | arraysize(data_writes)); |
| 16038 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16039 | |
| 16040 | TestCompletionCallback callback; |
| 16041 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16042 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16043 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16044 | |
| 16045 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16046 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16047 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16048 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16049 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16050 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16051 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16052 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 16053 | |
| 16054 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16055 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16056 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16057 | EXPECT_EQ("hello world", response_data); |
| 16058 | } |
| 16059 | |
| 16060 | // This test makes sure the retry logic doesn't trigger when reading an error |
| 16061 | // response from a server that rejected a POST with a CONNECTION_RESET. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16062 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16063 | PostReadsErrorResponseAfterResetOnReusedSocket) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16064 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16065 | MockWrite data_writes[] = { |
| 16066 | MockWrite("GET / HTTP/1.1\r\n" |
| 16067 | "Host: www.foo.com\r\n" |
| 16068 | "Connection: keep-alive\r\n\r\n"), |
| 16069 | MockWrite("POST / HTTP/1.1\r\n" |
| 16070 | "Host: www.foo.com\r\n" |
| 16071 | "Connection: keep-alive\r\n" |
| 16072 | "Content-Length: 3\r\n\r\n"), |
| 16073 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16074 | }; |
| 16075 | |
| 16076 | MockRead data_reads[] = { |
| 16077 | MockRead("HTTP/1.1 200 Peachy\r\n" |
| 16078 | "Content-Length: 14\r\n\r\n"), |
| 16079 | MockRead("first response"), |
| 16080 | MockRead("HTTP/1.1 400 Not OK\r\n" |
| 16081 | "Content-Length: 15\r\n\r\n"), |
| 16082 | MockRead("second response"), |
| 16083 | MockRead(SYNCHRONOUS, OK), |
| 16084 | }; |
| 16085 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16086 | arraysize(data_writes)); |
| 16087 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16088 | |
| 16089 | TestCompletionCallback callback; |
| 16090 | HttpRequestInfo request1; |
| 16091 | request1.method = "GET"; |
| 16092 | request1.url = GURL("http://www.foo.com/"); |
| 16093 | request1.load_flags = 0; |
| 16094 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16095 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16096 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16097 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16098 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16099 | |
| 16100 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16101 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16102 | |
| 16103 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16104 | ASSERT_TRUE(response1); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16105 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16106 | EXPECT_TRUE(response1->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16107 | EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine()); |
| 16108 | |
| 16109 | std::string response_data1; |
| 16110 | rv = ReadTransaction(trans1.get(), &response_data1); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16111 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16112 | EXPECT_EQ("first response", response_data1); |
| 16113 | // Delete the transaction to release the socket back into the socket pool. |
| 16114 | trans1.reset(); |
| 16115 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16116 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16117 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16118 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16119 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16120 | |
| 16121 | HttpRequestInfo request2; |
| 16122 | request2.method = "POST"; |
| 16123 | request2.url = GURL("http://www.foo.com/"); |
| 16124 | request2.upload_data_stream = &upload_data_stream; |
| 16125 | request2.load_flags = 0; |
| 16126 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16127 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16128 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16129 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16130 | |
| 16131 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16132 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16133 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16134 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16135 | ASSERT_TRUE(response2); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16136 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16137 | EXPECT_TRUE(response2->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16138 | EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine()); |
| 16139 | |
| 16140 | std::string response_data2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16141 | rv = ReadTransaction(&trans2, &response_data2); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16142 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16143 | EXPECT_EQ("second response", response_data2); |
| 16144 | } |
| 16145 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16146 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16147 | PostReadsErrorResponseAfterResetPartialBodySent) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16148 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16149 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16150 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16151 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16152 | |
| 16153 | HttpRequestInfo request; |
| 16154 | request.method = "POST"; |
| 16155 | request.url = GURL("http://www.foo.com/"); |
| 16156 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16157 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16158 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16159 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16160 | // Send headers successfully, but get an error while sending the body. |
| 16161 | MockWrite data_writes[] = { |
| 16162 | MockWrite("POST / HTTP/1.1\r\n" |
| 16163 | "Host: www.foo.com\r\n" |
| 16164 | "Connection: keep-alive\r\n" |
| 16165 | "Content-Length: 3\r\n\r\n" |
| 16166 | "fo"), |
| 16167 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16168 | }; |
| 16169 | |
| 16170 | MockRead data_reads[] = { |
| 16171 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 16172 | MockRead("hello world"), |
| 16173 | MockRead(SYNCHRONOUS, OK), |
| 16174 | }; |
| 16175 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16176 | arraysize(data_writes)); |
| 16177 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16178 | |
| 16179 | TestCompletionCallback callback; |
| 16180 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16181 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16182 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16183 | |
| 16184 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16185 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16186 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16187 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16188 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16189 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16190 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16191 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 16192 | |
| 16193 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16194 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16195 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16196 | EXPECT_EQ("hello world", response_data); |
| 16197 | } |
| 16198 | |
| 16199 | // This tests the more common case than the previous test, where headers and |
| 16200 | // body are not merged into a single request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16201 | TEST_F(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) { |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 16202 | ChunkedUploadDataStream upload_data_stream(0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16203 | |
| 16204 | HttpRequestInfo request; |
| 16205 | request.method = "POST"; |
| 16206 | request.url = GURL("http://www.foo.com/"); |
| 16207 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16208 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16209 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16210 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16211 | // Send headers successfully, but get an error while sending the body. |
| 16212 | MockWrite data_writes[] = { |
| 16213 | MockWrite("POST / HTTP/1.1\r\n" |
| 16214 | "Host: www.foo.com\r\n" |
| 16215 | "Connection: keep-alive\r\n" |
| 16216 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 16217 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16218 | }; |
| 16219 | |
| 16220 | MockRead data_reads[] = { |
| 16221 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 16222 | MockRead("hello world"), |
| 16223 | MockRead(SYNCHRONOUS, OK), |
| 16224 | }; |
| 16225 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16226 | arraysize(data_writes)); |
| 16227 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16228 | |
| 16229 | TestCompletionCallback callback; |
| 16230 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16231 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16232 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16233 | // Make sure the headers are sent before adding a chunk. This ensures that |
| 16234 | // they can't be merged with the body in a single send. Not currently |
| 16235 | // necessary since a chunked body is never merged with headers, but this makes |
| 16236 | // the test more future proof. |
| 16237 | base::RunLoop().RunUntilIdle(); |
| 16238 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 16239 | upload_data_stream.AppendData("last chunk", 10, true); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16240 | |
| 16241 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16242 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16243 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16244 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16245 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16246 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16247 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16248 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 16249 | |
| 16250 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16251 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16252 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16253 | EXPECT_EQ("hello world", response_data); |
| 16254 | } |
| 16255 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16256 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16257 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16258 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16259 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16260 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16261 | |
| 16262 | HttpRequestInfo request; |
| 16263 | request.method = "POST"; |
| 16264 | request.url = GURL("http://www.foo.com/"); |
| 16265 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16266 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16267 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16268 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16269 | |
| 16270 | MockWrite data_writes[] = { |
| 16271 | MockWrite("POST / HTTP/1.1\r\n" |
| 16272 | "Host: www.foo.com\r\n" |
| 16273 | "Connection: keep-alive\r\n" |
| 16274 | "Content-Length: 3\r\n\r\n"), |
| 16275 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16276 | }; |
| 16277 | |
| 16278 | MockRead data_reads[] = { |
| 16279 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 16280 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 16281 | MockRead("hello world"), |
| 16282 | MockRead(SYNCHRONOUS, OK), |
| 16283 | }; |
| 16284 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16285 | arraysize(data_writes)); |
| 16286 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16287 | |
| 16288 | TestCompletionCallback callback; |
| 16289 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16290 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16291 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16292 | |
| 16293 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16294 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16295 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16296 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16297 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16298 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16299 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16300 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 16301 | |
| 16302 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16303 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16304 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16305 | EXPECT_EQ("hello world", response_data); |
| 16306 | } |
| 16307 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16308 | TEST_F(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16309 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16310 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16311 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16312 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16313 | |
| 16314 | HttpRequestInfo request; |
| 16315 | request.method = "POST"; |
| 16316 | request.url = GURL("http://www.foo.com/"); |
| 16317 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16318 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16319 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16320 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16321 | // Send headers successfully, but get an error while sending the body. |
| 16322 | MockWrite data_writes[] = { |
| 16323 | MockWrite("POST / HTTP/1.1\r\n" |
| 16324 | "Host: www.foo.com\r\n" |
| 16325 | "Connection: keep-alive\r\n" |
| 16326 | "Content-Length: 3\r\n\r\n"), |
| 16327 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16328 | }; |
| 16329 | |
| 16330 | MockRead data_reads[] = { |
| 16331 | MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"), |
| 16332 | MockRead("hello world"), |
| 16333 | MockRead(SYNCHRONOUS, OK), |
| 16334 | }; |
| 16335 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16336 | arraysize(data_writes)); |
| 16337 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16338 | |
| 16339 | TestCompletionCallback callback; |
| 16340 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16341 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16342 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16343 | |
| 16344 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16345 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16346 | } |
| 16347 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16348 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16349 | PostIgnoresNonErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16350 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16351 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16352 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16353 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16354 | |
| 16355 | HttpRequestInfo request; |
| 16356 | request.method = "POST"; |
| 16357 | request.url = GURL("http://www.foo.com/"); |
| 16358 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16359 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16360 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16361 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16362 | // Send headers successfully, but get an error while sending the body. |
| 16363 | MockWrite data_writes[] = { |
| 16364 | MockWrite("POST / HTTP/1.1\r\n" |
| 16365 | "Host: www.foo.com\r\n" |
| 16366 | "Connection: keep-alive\r\n" |
| 16367 | "Content-Length: 3\r\n\r\n"), |
| 16368 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16369 | }; |
| 16370 | |
| 16371 | MockRead data_reads[] = { |
| 16372 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 16373 | MockRead("HTTP/1.0 302 Redirect\r\n"), |
| 16374 | MockRead("Location: http://somewhere-else.com/\r\n"), |
| 16375 | MockRead("Content-Length: 0\r\n\r\n"), |
| 16376 | MockRead(SYNCHRONOUS, OK), |
| 16377 | }; |
| 16378 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16379 | arraysize(data_writes)); |
| 16380 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16381 | |
| 16382 | TestCompletionCallback callback; |
| 16383 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16384 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16385 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16386 | |
| 16387 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16388 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16389 | } |
| 16390 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16391 | TEST_F(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16392 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16393 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16394 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16395 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16396 | |
| 16397 | HttpRequestInfo request; |
| 16398 | request.method = "POST"; |
| 16399 | request.url = GURL("http://www.foo.com/"); |
| 16400 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16401 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16402 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16403 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16404 | // Send headers successfully, but get an error while sending the body. |
| 16405 | MockWrite data_writes[] = { |
| 16406 | MockWrite("POST / HTTP/1.1\r\n" |
| 16407 | "Host: www.foo.com\r\n" |
| 16408 | "Connection: keep-alive\r\n" |
| 16409 | "Content-Length: 3\r\n\r\n"), |
| 16410 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16411 | }; |
| 16412 | |
| 16413 | MockRead data_reads[] = { |
| 16414 | MockRead("HTTP 0.9 rocks!"), |
| 16415 | MockRead(SYNCHRONOUS, OK), |
| 16416 | }; |
| 16417 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16418 | arraysize(data_writes)); |
| 16419 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16420 | |
| 16421 | TestCompletionCallback callback; |
| 16422 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16423 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16424 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16425 | |
| 16426 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16427 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16428 | } |
| 16429 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16430 | TEST_F(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16431 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16432 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16433 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16434 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16435 | |
| 16436 | HttpRequestInfo request; |
| 16437 | request.method = "POST"; |
| 16438 | request.url = GURL("http://www.foo.com/"); |
| 16439 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16440 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16441 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16442 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16443 | // Send headers successfully, but get an error while sending the body. |
| 16444 | MockWrite data_writes[] = { |
| 16445 | MockWrite("POST / HTTP/1.1\r\n" |
| 16446 | "Host: www.foo.com\r\n" |
| 16447 | "Connection: keep-alive\r\n" |
| 16448 | "Content-Length: 3\r\n\r\n"), |
| 16449 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16450 | }; |
| 16451 | |
| 16452 | MockRead data_reads[] = { |
| 16453 | MockRead("HTTP/1.0 400 Not a Full Response\r\n"), |
| 16454 | MockRead(SYNCHRONOUS, OK), |
| 16455 | }; |
| 16456 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16457 | arraysize(data_writes)); |
| 16458 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16459 | |
| 16460 | TestCompletionCallback callback; |
| 16461 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16462 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16463 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16464 | |
| 16465 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16466 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16467 | } |
| 16468 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16469 | // Verify that proxy headers are not sent to the destination server when |
| 16470 | // establishing a tunnel for a secure WebSocket connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16471 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWssTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16472 | HttpRequestInfo request; |
| 16473 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16474 | request.url = GURL("wss://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16475 | AddWebSocketHeaders(&request.extra_headers); |
| 16476 | |
| 16477 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 16478 | session_deps_.proxy_service = |
| 16479 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16480 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16481 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16482 | |
| 16483 | // Since a proxy is configured, try to establish a tunnel. |
| 16484 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16485 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 16486 | "Host: www.example.org:443\r\n" |
| 16487 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16488 | |
| 16489 | // After calling trans->RestartWithAuth(), this is the request we should |
| 16490 | // be issuing -- the final header line contains the credentials. |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16491 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 16492 | "Host: www.example.org:443\r\n" |
| 16493 | "Proxy-Connection: keep-alive\r\n" |
| 16494 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16495 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16496 | MockWrite("GET / HTTP/1.1\r\n" |
| 16497 | "Host: www.example.org\r\n" |
| 16498 | "Connection: Upgrade\r\n" |
| 16499 | "Upgrade: websocket\r\n" |
| 16500 | "Origin: http://www.example.org\r\n" |
| 16501 | "Sec-WebSocket-Version: 13\r\n" |
| 16502 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16503 | }; |
| 16504 | |
| 16505 | // The proxy responds to the connect with a 407, using a persistent |
| 16506 | // connection. |
| 16507 | MockRead data_reads[] = { |
| 16508 | // No credentials. |
| 16509 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 16510 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 16511 | MockRead("Content-Length: 0\r\n"), |
| 16512 | MockRead("Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16513 | |
| 16514 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 16515 | |
| 16516 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 16517 | MockRead("Upgrade: websocket\r\n"), |
| 16518 | MockRead("Connection: Upgrade\r\n"), |
| 16519 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 16520 | }; |
| 16521 | |
| 16522 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16523 | arraysize(data_writes)); |
| 16524 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16525 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 16526 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16527 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16528 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16529 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16530 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 16531 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 16532 | &websocket_stream_create_helper); |
| 16533 | |
| 16534 | { |
| 16535 | TestCompletionCallback callback; |
| 16536 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16537 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16538 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16539 | |
| 16540 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16541 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16542 | } |
| 16543 | |
| 16544 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 16545 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16546 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16547 | EXPECT_EQ(407, response->headers->response_code()); |
| 16548 | |
| 16549 | { |
| 16550 | TestCompletionCallback callback; |
| 16551 | |
| 16552 | int rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 16553 | callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16554 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16555 | |
| 16556 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16557 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16558 | } |
| 16559 | |
| 16560 | response = trans->GetResponseInfo(); |
| 16561 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16562 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16563 | |
| 16564 | EXPECT_EQ(101, response->headers->response_code()); |
| 16565 | |
| 16566 | trans.reset(); |
| 16567 | session->CloseAllConnections(); |
| 16568 | } |
| 16569 | |
| 16570 | // Verify that proxy headers are not sent to the destination server when |
| 16571 | // establishing a tunnel for an insecure WebSocket connection. |
| 16572 | // This requires the authentication info to be injected into the auth cache |
| 16573 | // due to crbug.com/395064 |
| 16574 | // TODO(ricea): Change to use a 407 response once issue 395064 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16575 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWsTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16576 | HttpRequestInfo request; |
| 16577 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16578 | request.url = GURL("ws://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16579 | AddWebSocketHeaders(&request.extra_headers); |
| 16580 | |
| 16581 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 16582 | session_deps_.proxy_service = |
| 16583 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16584 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16585 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16586 | |
| 16587 | MockWrite data_writes[] = { |
| 16588 | // Try to establish a tunnel for the WebSocket connection, with |
| 16589 | // credentials. Because WebSockets have a separate set of socket pools, |
| 16590 | // they cannot and will not use the same TCP/IP connection as the |
| 16591 | // preflight HTTP request. |
| 16592 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16593 | "CONNECT www.example.org:80 HTTP/1.1\r\n" |
| 16594 | "Host: www.example.org:80\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16595 | "Proxy-Connection: keep-alive\r\n" |
| 16596 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 16597 | |
| 16598 | MockWrite( |
| 16599 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16600 | "Host: www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16601 | "Connection: Upgrade\r\n" |
| 16602 | "Upgrade: websocket\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16603 | "Origin: http://www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16604 | "Sec-WebSocket-Version: 13\r\n" |
| 16605 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
| 16606 | }; |
| 16607 | |
| 16608 | MockRead data_reads[] = { |
| 16609 | // HTTP CONNECT with credentials. |
| 16610 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 16611 | |
| 16612 | // WebSocket connection established inside tunnel. |
| 16613 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 16614 | MockRead("Upgrade: websocket\r\n"), |
| 16615 | MockRead("Connection: Upgrade\r\n"), |
| 16616 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 16617 | }; |
| 16618 | |
| 16619 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16620 | arraysize(data_writes)); |
| 16621 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16622 | |
| 16623 | session->http_auth_cache()->Add( |
| 16624 | GURL("http://myproxy:70/"), "MyRealm1", HttpAuth::AUTH_SCHEME_BASIC, |
| 16625 | "Basic realm=MyRealm1", AuthCredentials(kFoo, kBar), "/"); |
| 16626 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16627 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16628 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16629 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 16630 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 16631 | &websocket_stream_create_helper); |
| 16632 | |
| 16633 | TestCompletionCallback callback; |
| 16634 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16635 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16636 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16637 | |
| 16638 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16639 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16640 | |
| 16641 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 16642 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16643 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16644 | |
| 16645 | EXPECT_EQ(101, response->headers->response_code()); |
| 16646 | |
| 16647 | trans.reset(); |
| 16648 | session->CloseAllConnections(); |
| 16649 | } |
| 16650 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16651 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16652 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16653 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16654 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16655 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16656 | |
| 16657 | HttpRequestInfo request; |
| 16658 | request.method = "POST"; |
| 16659 | request.url = GURL("http://www.foo.com/"); |
| 16660 | request.upload_data_stream = &upload_data_stream; |
| 16661 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16662 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16663 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16664 | MockWrite data_writes[] = { |
| 16665 | MockWrite("POST / HTTP/1.1\r\n" |
| 16666 | "Host: www.foo.com\r\n" |
| 16667 | "Connection: keep-alive\r\n" |
| 16668 | "Content-Length: 3\r\n\r\n"), |
| 16669 | MockWrite("foo"), |
| 16670 | }; |
| 16671 | |
| 16672 | MockRead data_reads[] = { |
| 16673 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16674 | MockRead(SYNCHRONOUS, OK), |
| 16675 | }; |
| 16676 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16677 | arraysize(data_writes)); |
| 16678 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16679 | |
| 16680 | TestCompletionCallback callback; |
| 16681 | |
| 16682 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16683 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16684 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16685 | |
| 16686 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16687 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16688 | |
| 16689 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16690 | trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16691 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16692 | trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16693 | } |
| 16694 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16695 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost100Continue) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16696 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16697 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16698 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16699 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16700 | |
| 16701 | HttpRequestInfo request; |
| 16702 | request.method = "POST"; |
| 16703 | request.url = GURL("http://www.foo.com/"); |
| 16704 | request.upload_data_stream = &upload_data_stream; |
| 16705 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16706 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16707 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16708 | MockWrite data_writes[] = { |
| 16709 | MockWrite("POST / HTTP/1.1\r\n" |
| 16710 | "Host: www.foo.com\r\n" |
| 16711 | "Connection: keep-alive\r\n" |
| 16712 | "Content-Length: 3\r\n\r\n"), |
| 16713 | MockWrite("foo"), |
| 16714 | }; |
| 16715 | |
| 16716 | MockRead data_reads[] = { |
| 16717 | MockRead("HTTP/1.1 100 Continue\r\n\r\n"), |
| 16718 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16719 | MockRead(SYNCHRONOUS, OK), |
| 16720 | }; |
| 16721 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16722 | arraysize(data_writes)); |
| 16723 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16724 | |
| 16725 | TestCompletionCallback callback; |
| 16726 | |
| 16727 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16728 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16729 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16730 | |
| 16731 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16732 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16733 | |
| 16734 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16735 | trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16736 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16737 | trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16738 | } |
| 16739 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16740 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesChunkedPost) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16741 | ChunkedUploadDataStream upload_data_stream(0); |
| 16742 | |
| 16743 | HttpRequestInfo request; |
| 16744 | request.method = "POST"; |
| 16745 | request.url = GURL("http://www.foo.com/"); |
| 16746 | request.upload_data_stream = &upload_data_stream; |
| 16747 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16748 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16749 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16750 | // Send headers successfully, but get an error while sending the body. |
| 16751 | MockWrite data_writes[] = { |
| 16752 | MockWrite("POST / HTTP/1.1\r\n" |
| 16753 | "Host: www.foo.com\r\n" |
| 16754 | "Connection: keep-alive\r\n" |
| 16755 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 16756 | MockWrite("1\r\nf\r\n"), MockWrite("2\r\noo\r\n"), MockWrite("0\r\n\r\n"), |
| 16757 | }; |
| 16758 | |
| 16759 | MockRead data_reads[] = { |
| 16760 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16761 | MockRead(SYNCHRONOUS, OK), |
| 16762 | }; |
| 16763 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16764 | arraysize(data_writes)); |
| 16765 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16766 | |
| 16767 | TestCompletionCallback callback; |
| 16768 | |
| 16769 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16770 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16771 | |
| 16772 | base::RunLoop().RunUntilIdle(); |
| 16773 | upload_data_stream.AppendData("f", 1, false); |
| 16774 | |
| 16775 | base::RunLoop().RunUntilIdle(); |
| 16776 | upload_data_stream.AppendData("oo", 2, true); |
| 16777 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16778 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16779 | |
| 16780 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16781 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16782 | |
| 16783 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16784 | trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16785 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16786 | trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16787 | } |
| 16788 | |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16789 | // Confirm that transactions whose throttle is created in (and stays in) |
| 16790 | // the unthrottled state are not blocked. |
| 16791 | TEST_F(HttpNetworkTransactionTest, ThrottlingUnthrottled) { |
| 16792 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16793 | std::unique_ptr<HttpNetworkSession> session( |
| 16794 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16795 | |
| 16796 | // Send a simple request and make sure it goes through. |
| 16797 | HttpRequestInfo request; |
| 16798 | request.method = "GET"; |
| 16799 | request.url = GURL("http://www.example.org/"); |
| 16800 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16801 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16802 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16803 | |
| 16804 | MockWrite data_writes[] = { |
| 16805 | MockWrite("GET / HTTP/1.1\r\n" |
| 16806 | "Host: www.example.org\r\n" |
| 16807 | "Connection: keep-alive\r\n\r\n"), |
| 16808 | }; |
| 16809 | MockRead data_reads[] = { |
| 16810 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16811 | MockRead(SYNCHRONOUS, OK), |
| 16812 | }; |
| 16813 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16814 | arraysize(data_writes)); |
| 16815 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16816 | |
| 16817 | TestCompletionCallback callback; |
| 16818 | trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16819 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 16820 | } |
| 16821 | |
| 16822 | // Confirm requests can be blocked by a throttler, and are resumed |
| 16823 | // when the throttle is unblocked. |
| 16824 | TEST_F(HttpNetworkTransactionTest, ThrottlingBasic) { |
| 16825 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16826 | std::unique_ptr<HttpNetworkSession> session( |
| 16827 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16828 | |
| 16829 | // Send a simple request and make sure it goes through. |
| 16830 | HttpRequestInfo request; |
| 16831 | request.method = "GET"; |
| 16832 | request.url = GURL("http://www.example.org/"); |
| 16833 | |
| 16834 | MockWrite data_writes[] = { |
| 16835 | MockWrite("GET / HTTP/1.1\r\n" |
| 16836 | "Host: www.example.org\r\n" |
| 16837 | "Connection: keep-alive\r\n\r\n"), |
| 16838 | }; |
| 16839 | MockRead data_reads[] = { |
| 16840 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16841 | MockRead(SYNCHRONOUS, OK), |
| 16842 | }; |
| 16843 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16844 | arraysize(data_writes)); |
| 16845 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16846 | |
| 16847 | // Start a request that will be throttled at start; confirm it |
| 16848 | // doesn't complete. |
| 16849 | throttler->set_throttle_new_requests(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16850 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16851 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16852 | |
| 16853 | TestCompletionCallback callback; |
| 16854 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16855 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16856 | |
| 16857 | base::RunLoop().RunUntilIdle(); |
| 16858 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 16859 | EXPECT_FALSE(callback.have_result()); |
| 16860 | |
| 16861 | // Confirm the request goes on to complete when unthrottled. |
| 16862 | throttler->UnthrottleAllRequests(); |
| 16863 | base::RunLoop().RunUntilIdle(); |
| 16864 | ASSERT_TRUE(callback.have_result()); |
| 16865 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 16866 | } |
| 16867 | |
| 16868 | // Destroy a request while it's throttled. |
| 16869 | TEST_F(HttpNetworkTransactionTest, ThrottlingDestruction) { |
| 16870 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16871 | std::unique_ptr<HttpNetworkSession> session( |
| 16872 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16873 | |
| 16874 | // Send a simple request and make sure it goes through. |
| 16875 | HttpRequestInfo request; |
| 16876 | request.method = "GET"; |
| 16877 | request.url = GURL("http://www.example.org/"); |
| 16878 | |
| 16879 | MockWrite data_writes[] = { |
| 16880 | MockWrite("GET / HTTP/1.1\r\n" |
| 16881 | "Host: www.example.org\r\n" |
| 16882 | "Connection: keep-alive\r\n\r\n"), |
| 16883 | }; |
| 16884 | MockRead data_reads[] = { |
| 16885 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16886 | MockRead(SYNCHRONOUS, OK), |
| 16887 | }; |
| 16888 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16889 | arraysize(data_writes)); |
| 16890 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16891 | |
| 16892 | // Start a request that will be throttled at start; confirm it |
| 16893 | // doesn't complete. |
| 16894 | throttler->set_throttle_new_requests(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16895 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16896 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16897 | |
| 16898 | TestCompletionCallback callback; |
| 16899 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16900 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16901 | |
| 16902 | base::RunLoop().RunUntilIdle(); |
| 16903 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 16904 | EXPECT_FALSE(callback.have_result()); |
| 16905 | |
| 16906 | EXPECT_EQ(1u, throttler->num_outstanding_requests()); |
| 16907 | trans.reset(); |
| 16908 | EXPECT_EQ(0u, throttler->num_outstanding_requests()); |
| 16909 | } |
| 16910 | |
| 16911 | // Confirm the throttler receives SetPriority calls. |
| 16912 | TEST_F(HttpNetworkTransactionTest, ThrottlingPrioritySet) { |
| 16913 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16914 | std::unique_ptr<HttpNetworkSession> session( |
| 16915 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16916 | |
| 16917 | // Send a simple request and make sure it goes through. |
| 16918 | HttpRequestInfo request; |
| 16919 | request.method = "GET"; |
| 16920 | request.url = GURL("http://www.example.org/"); |
| 16921 | |
| 16922 | MockWrite data_writes[] = { |
| 16923 | MockWrite("GET / HTTP/1.1\r\n" |
| 16924 | "Host: www.example.org\r\n" |
| 16925 | "Connection: keep-alive\r\n\r\n"), |
| 16926 | }; |
| 16927 | MockRead data_reads[] = { |
| 16928 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16929 | MockRead(SYNCHRONOUS, OK), |
| 16930 | }; |
| 16931 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16932 | arraysize(data_writes)); |
| 16933 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16934 | |
| 16935 | throttler->set_throttle_new_requests(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16936 | auto trans = std::make_unique<HttpNetworkTransaction>(IDLE, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16937 | // Start the transaction to associate a throttle with it. |
| 16938 | TestCompletionCallback callback; |
| 16939 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16940 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16941 | |
| 16942 | EXPECT_EQ(0, throttler->num_set_priority_calls()); |
| 16943 | trans->SetPriority(LOW); |
| 16944 | EXPECT_EQ(1, throttler->num_set_priority_calls()); |
| 16945 | EXPECT_EQ(LOW, throttler->last_priority_set()); |
| 16946 | |
| 16947 | throttler->UnthrottleAllRequests(); |
| 16948 | base::RunLoop().RunUntilIdle(); |
| 16949 | ASSERT_TRUE(callback.have_result()); |
| 16950 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 16951 | } |
| 16952 | |
| 16953 | // Confirm that unthrottling from a SetPriority call by the |
| 16954 | // throttler works properly. |
| 16955 | TEST_F(HttpNetworkTransactionTest, ThrottlingPrioritySetUnthrottle) { |
| 16956 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16957 | std::unique_ptr<HttpNetworkSession> session( |
| 16958 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16959 | |
| 16960 | // Send a simple request and make sure it goes through. |
| 16961 | HttpRequestInfo request; |
| 16962 | request.method = "GET"; |
| 16963 | request.url = GURL("http://www.example.org/"); |
| 16964 | |
| 16965 | MockWrite data_writes[] = { |
| 16966 | MockWrite("GET / HTTP/1.1\r\n" |
| 16967 | "Host: www.example.org\r\n" |
| 16968 | "Connection: keep-alive\r\n\r\n"), |
| 16969 | }; |
| 16970 | MockRead data_reads[] = { |
| 16971 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16972 | MockRead(SYNCHRONOUS, OK), |
| 16973 | }; |
| 16974 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16975 | arraysize(data_writes)); |
| 16976 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16977 | |
| 16978 | StaticSocketDataProvider reads1(data_reads, arraysize(data_reads), |
| 16979 | data_writes, arraysize(data_writes)); |
| 16980 | session_deps_.socket_factory->AddSocketDataProvider(&reads1); |
| 16981 | |
| 16982 | // Start a request that will be throttled at start; confirm it |
| 16983 | // doesn't complete. |
| 16984 | throttler->set_throttle_new_requests(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16985 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16986 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16987 | |
| 16988 | TestCompletionCallback callback; |
| 16989 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16990 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16991 | |
| 16992 | base::RunLoop().RunUntilIdle(); |
| 16993 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 16994 | EXPECT_FALSE(callback.have_result()); |
| 16995 | |
| 16996 | // Create a new request, call SetPriority on it to unthrottle, |
| 16997 | // and make sure that allows the original request to complete. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16998 | auto trans1 = std::make_unique<HttpNetworkTransaction>(LOW, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16999 | throttler->set_priority_change_closure( |
| 17000 | base::Bind(&TestNetworkStreamThrottler::UnthrottleAllRequests, |
| 17001 | base::Unretained(throttler))); |
| 17002 | |
| 17003 | // Start the transaction to associate a throttle with it. |
| 17004 | TestCompletionCallback callback1; |
| 17005 | rv = trans1->Start(&request, callback1.callback(), NetLogWithSource()); |
| 17006 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 17007 | |
| 17008 | trans1->SetPriority(IDLE); |
| 17009 | |
| 17010 | base::RunLoop().RunUntilIdle(); |
| 17011 | ASSERT_TRUE(callback.have_result()); |
| 17012 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 17013 | ASSERT_TRUE(callback1.have_result()); |
| 17014 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 17015 | } |
| 17016 | |
| 17017 | // Transaction will be destroyed when the unique_ptr goes out of scope. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17018 | void DestroyTransaction(std::unique_ptr<HttpNetworkTransaction> transaction) {} |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17019 | |
| 17020 | // Confirm that destroying a transaction from a SetPriority call by the |
| 17021 | // throttler works properly. |
| 17022 | TEST_F(HttpNetworkTransactionTest, ThrottlingPrioritySetDestroy) { |
| 17023 | TestNetworkStreamThrottler* throttler(nullptr); |
| 17024 | std::unique_ptr<HttpNetworkSession> session( |
| 17025 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 17026 | |
| 17027 | // Send a simple request and make sure it goes through. |
| 17028 | HttpRequestInfo request; |
| 17029 | request.method = "GET"; |
| 17030 | request.url = GURL("http://www.example.org/"); |
| 17031 | |
| 17032 | MockWrite data_writes[] = { |
| 17033 | MockWrite("GET / HTTP/1.1\r\n" |
| 17034 | "Host: www.example.org\r\n" |
| 17035 | "Connection: keep-alive\r\n\r\n"), |
| 17036 | }; |
| 17037 | MockRead data_reads[] = { |
| 17038 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17039 | MockRead(SYNCHRONOUS, OK), |
| 17040 | }; |
| 17041 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 17042 | arraysize(data_writes)); |
| 17043 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 17044 | |
| 17045 | StaticSocketDataProvider reads1(data_reads, arraysize(data_reads), |
| 17046 | data_writes, arraysize(data_writes)); |
| 17047 | session_deps_.socket_factory->AddSocketDataProvider(&reads1); |
| 17048 | |
| 17049 | // Start a request that will be throttled at start; confirm it |
| 17050 | // doesn't complete. |
| 17051 | throttler->set_throttle_new_requests(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17052 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17053 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17054 | |
| 17055 | TestCompletionCallback callback; |
| 17056 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 17057 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 17058 | |
| 17059 | base::RunLoop().RunUntilIdle(); |
| 17060 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 17061 | EXPECT_FALSE(callback.have_result()); |
| 17062 | |
| 17063 | // Arrange for the set priority call on the above transaction to delete |
| 17064 | // the transaction. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17065 | HttpNetworkTransaction* trans_ptr(trans.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17066 | throttler->set_priority_change_closure( |
| 17067 | base::Bind(&DestroyTransaction, base::Passed(&trans))); |
| 17068 | |
| 17069 | // Call it and check results (partially a "doesn't crash" test). |
| 17070 | trans_ptr->SetPriority(IDLE); |
| 17071 | trans_ptr = nullptr; // No longer a valid pointer. |
| 17072 | |
| 17073 | base::RunLoop().RunUntilIdle(); |
| 17074 | ASSERT_FALSE(callback.have_result()); |
| 17075 | } |
| 17076 | |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17077 | #if !defined(OS_IOS) |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17078 | TEST_F(HttpNetworkTransactionTest, TokenBindingSpdy) { |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17079 | const std::string https_url = "https://www.example.com"; |
| 17080 | HttpRequestInfo request; |
| 17081 | request.url = GURL(https_url); |
| 17082 | request.method = "GET"; |
| 17083 | |
| 17084 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 17085 | ssl.token_binding_negotiated = true; |
| 17086 | ssl.token_binding_key_param = TB_PARAM_ECDSAP256; |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 17087 | ssl.next_proto = kProtoHTTP2; |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17088 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 17089 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 17090 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17091 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 17092 | MockRead reads[] = {CreateMockRead(resp), CreateMockRead(body), |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17093 | MockRead(ASYNC, ERR_IO_PENDING)}; |
| 17094 | StaticSocketDataProvider data(reads, arraysize(reads), nullptr, 0); |
| 17095 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17096 | session_deps_.channel_id_service = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17097 | std::make_unique<ChannelIDService>(new DefaultChannelIDStore(nullptr)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17098 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17099 | |
| 17100 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17101 | TestCompletionCallback callback; |
| 17102 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17103 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
fdoray | f33fede | 2017-05-11 21:18:10 | [diff] [blame] | 17104 | |
| 17105 | NetTestSuite::GetScopedTaskEnvironment()->RunUntilIdle(); |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17106 | |
| 17107 | EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); |
| 17108 | HttpRequestHeaders headers; |
| 17109 | ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); |
| 17110 | EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); |
| 17111 | } |
| 17112 | #endif // !defined(OS_IOS) |
| 17113 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17114 | void CheckContentEncodingMatching(SpdySessionDependencies* session_deps, |
| 17115 | const std::string& accept_encoding, |
| 17116 | const std::string& content_encoding, |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17117 | const std::string& location, |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17118 | bool should_match) { |
| 17119 | HttpRequestInfo request; |
| 17120 | request.method = "GET"; |
| 17121 | request.url = GURL("http://www.foo.com/"); |
| 17122 | request.extra_headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, |
| 17123 | accept_encoding); |
| 17124 | |
| 17125 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps)); |
| 17126 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17127 | // Send headers successfully, but get an error while sending the body. |
| 17128 | MockWrite data_writes[] = { |
| 17129 | MockWrite("GET / HTTP/1.1\r\n" |
| 17130 | "Host: www.foo.com\r\n" |
| 17131 | "Connection: keep-alive\r\n" |
| 17132 | "Accept-Encoding: "), |
| 17133 | MockWrite(accept_encoding.data()), MockWrite("\r\n\r\n"), |
| 17134 | }; |
| 17135 | |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17136 | std::string response_code = "200 OK"; |
| 17137 | std::string extra; |
| 17138 | if (!location.empty()) { |
| 17139 | response_code = "301 Redirect\r\nLocation: "; |
| 17140 | response_code.append(location); |
| 17141 | } |
| 17142 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17143 | MockRead data_reads[] = { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17144 | MockRead("HTTP/1.0 "), |
| 17145 | MockRead(response_code.data()), |
| 17146 | MockRead("\r\nContent-Encoding: "), |
| 17147 | MockRead(content_encoding.data()), |
| 17148 | MockRead("\r\n\r\n"), |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17149 | MockRead(SYNCHRONOUS, OK), |
| 17150 | }; |
| 17151 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 17152 | arraysize(data_writes)); |
| 17153 | session_deps->socket_factory->AddSocketDataProvider(&data); |
| 17154 | |
| 17155 | TestCompletionCallback callback; |
| 17156 | |
| 17157 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17158 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17159 | |
| 17160 | rv = callback.WaitForResult(); |
| 17161 | if (should_match) { |
| 17162 | EXPECT_THAT(rv, IsOk()); |
| 17163 | } else { |
| 17164 | EXPECT_THAT(rv, IsError(ERR_CONTENT_DECODING_FAILED)); |
| 17165 | } |
| 17166 | } |
| 17167 | |
| 17168 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding1) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17169 | CheckContentEncodingMatching(&session_deps_, "gzip,sdch", "br", "", false); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17170 | } |
| 17171 | |
| 17172 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding2) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17173 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "", "", |
| 17174 | true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17175 | } |
| 17176 | |
| 17177 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding3) { |
| 17178 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17179 | "", false); |
| 17180 | } |
| 17181 | |
| 17182 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding4) { |
| 17183 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
| 17184 | "www.foo.com/other", true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17185 | } |
| 17186 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17187 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsSync) { |
| 17188 | ProxyConfig proxy_config; |
| 17189 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 17190 | proxy_config.set_pac_mandatory(true); |
| 17191 | MockAsyncProxyResolver resolver; |
| 17192 | session_deps_.proxy_service.reset(new ProxyService( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17193 | std::make_unique<ProxyConfigServiceFixed>(proxy_config), |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17194 | base::WrapUnique(new FailingProxyResolverFactory), nullptr)); |
| 17195 | |
| 17196 | HttpRequestInfo request; |
| 17197 | request.method = "GET"; |
| 17198 | request.url = GURL("http://www.example.org/"); |
| 17199 | |
| 17200 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 17201 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17202 | |
| 17203 | TestCompletionCallback callback; |
| 17204 | |
| 17205 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17206 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17207 | EXPECT_THAT(callback.WaitForResult(), |
| 17208 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 17209 | } |
| 17210 | |
| 17211 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsAsync) { |
| 17212 | ProxyConfig proxy_config; |
| 17213 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 17214 | proxy_config.set_pac_mandatory(true); |
| 17215 | MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 17216 | new MockAsyncProxyResolverFactory(false); |
| 17217 | MockAsyncProxyResolver resolver; |
| 17218 | session_deps_.proxy_service.reset( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17219 | new ProxyService(std::make_unique<ProxyConfigServiceFixed>(proxy_config), |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17220 | base::WrapUnique(proxy_resolver_factory), nullptr)); |
| 17221 | HttpRequestInfo request; |
| 17222 | request.method = "GET"; |
| 17223 | request.url = GURL("http://www.example.org/"); |
| 17224 | |
| 17225 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 17226 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17227 | |
| 17228 | TestCompletionCallback callback; |
| 17229 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17230 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17231 | |
| 17232 | proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder( |
| 17233 | ERR_FAILED, &resolver); |
| 17234 | EXPECT_THAT(callback.WaitForResult(), |
| 17235 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 17236 | } |
| 17237 | |
| 17238 | TEST_F(HttpNetworkTransactionTest, NoSupportedProxies) { |
| 17239 | session_deps_.proxy_service = |
| 17240 | ProxyService::CreateFixedFromPacResult("QUIC myproxy.org:443"); |
| 17241 | session_deps_.enable_quic = false; |
| 17242 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 17243 | |
| 17244 | HttpRequestInfo request; |
| 17245 | request.method = "GET"; |
| 17246 | request.url = GURL("http://www.example.org/"); |
| 17247 | |
| 17248 | TestCompletionCallback callback; |
| 17249 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17250 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17251 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17252 | |
| 17253 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_NO_SUPPORTED_PROXIES)); |
| 17254 | } |
| 17255 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 17256 | } // namespace net |