[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] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5979 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5980 | }; |
| 5981 | |
| 5982 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5983 | // After restarting with a null identity, this is the |
| 5984 | // request we should be issuing -- the final header line contains a Type |
| 5985 | // 1 message. |
| 5986 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5987 | "Host: 172.22.68.17\r\n" |
| 5988 | "Connection: keep-alive\r\n" |
| 5989 | "Authorization: NTLM " |
| 5990 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 5991 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5992 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 5993 | // (the credentials for the origin server). The second request continues |
| 5994 | // on the same connection. |
| 5995 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 5996 | "Host: 172.22.68.17\r\n" |
| 5997 | "Connection: keep-alive\r\n" |
| 5998 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 5999 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 6000 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBVKW" |
| 6001 | "Yma5xzVAAAAAAAAAAAAAAAAAAAAACH+gWcm+YsP9Tqb9zCR3WAeZZX" |
| 6002 | "ahlhx5I=\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6003 | }; |
| 6004 | |
| 6005 | MockRead data_reads2[] = { |
| 6006 | // The origin server responds with a Type 2 message. |
| 6007 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 6008 | MockRead("WWW-Authenticate: NTLM " |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6009 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCjGpMpPGlYKkAAAAAAAAAALo" |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6010 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 6011 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 6012 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 6013 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 6014 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 6015 | "BtAAAAAAA=\r\n"), |
| 6016 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6017 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6018 | MockRead("You are not authorized to view this page\r\n"), |
| 6019 | |
| 6020 | // Lastly we get the desired content. |
| 6021 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6022 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 6023 | MockRead("Content-Length: 13\r\n\r\n"), |
| 6024 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6025 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6026 | }; |
| 6027 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6028 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6029 | data_writes1, arraysize(data_writes1)); |
| 6030 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6031 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6032 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6033 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6034 | |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame^] | 6035 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 6036 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 6037 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 6038 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 6039 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6040 | TestCompletionCallback callback1; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6041 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6042 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6043 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6044 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6045 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6046 | |
| 6047 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6048 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6049 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6050 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6051 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6052 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6053 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6054 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6055 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6056 | TestCompletionCallback callback2; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6057 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6058 | rv = trans.RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
| 6059 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6060 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6061 | |
| 6062 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6063 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6064 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6065 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6066 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6067 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6068 | ASSERT_TRUE(response); |
| 6069 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6070 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6071 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6072 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6073 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6074 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6075 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6076 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6077 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6078 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6079 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6080 | ASSERT_TRUE(response); |
| 6081 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6082 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 6083 | } |
| 6084 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6085 | // Enter a wrong password, and then the correct one. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6086 | TEST_F(HttpNetworkTransactionTest, NTLMAuth2) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6087 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6088 | request.method = "GET"; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame^] | 6089 | request.url = GURL("https://172.22.68.17/kids/login.aspx"); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6090 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6091 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom2, |
| 6092 | MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6093 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6094 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6095 | MockWrite data_writes1[] = { |
| 6096 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6097 | "Host: 172.22.68.17\r\n" |
| 6098 | "Connection: keep-alive\r\n\r\n"), |
| 6099 | }; |
| 6100 | |
| 6101 | MockRead data_reads1[] = { |
| 6102 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 6103 | // Negotiate and NTLM are often requested together. However, we only want |
| 6104 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 6105 | // the header that requests Negotiate for this test. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6106 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 6107 | MockRead("Connection: close\r\n"), |
| 6108 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6109 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6110 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6111 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6112 | }; |
| 6113 | |
| 6114 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6115 | // After restarting with a null identity, this is the |
| 6116 | // request we should be issuing -- the final header line contains a Type |
| 6117 | // 1 message. |
| 6118 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6119 | "Host: 172.22.68.17\r\n" |
| 6120 | "Connection: keep-alive\r\n" |
| 6121 | "Authorization: NTLM " |
| 6122 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6123 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6124 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 6125 | // (the credentials for the origin server). The second request continues |
| 6126 | // on the same connection. |
| 6127 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6128 | "Host: 172.22.68.17\r\n" |
| 6129 | "Connection: keep-alive\r\n" |
| 6130 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 6131 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 6132 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwCWeY" |
| 6133 | "XnSZNwoQAAAAAAAAAAAAAAAAAAAADLa34/phTTKzNTWdub+uyFleOj" |
| 6134 | "4Ww7b7E=\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6135 | }; |
| 6136 | |
| 6137 | MockRead data_reads2[] = { |
| 6138 | // The origin server responds with a Type 2 message. |
| 6139 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 6140 | MockRead("WWW-Authenticate: NTLM " |
| 6141 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCbVWUZezVGpAAAAAAAAAAALo" |
| 6142 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 6143 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 6144 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 6145 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 6146 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 6147 | "BtAAAAAAA=\r\n"), |
| 6148 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6149 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6150 | MockRead("You are not authorized to view this page\r\n"), |
| 6151 | |
| 6152 | // Wrong password. |
| 6153 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6154 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 6155 | MockRead("Connection: close\r\n"), |
| 6156 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6157 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6158 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6159 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6160 | }; |
| 6161 | |
| 6162 | MockWrite data_writes3[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6163 | // After restarting with a null identity, this is the |
| 6164 | // request we should be issuing -- the final header line contains a Type |
| 6165 | // 1 message. |
| 6166 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6167 | "Host: 172.22.68.17\r\n" |
| 6168 | "Connection: keep-alive\r\n" |
| 6169 | "Authorization: NTLM " |
| 6170 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6171 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6172 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 6173 | // (the credentials for the origin server). The second request continues |
| 6174 | // on the same connection. |
| 6175 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6176 | "Host: 172.22.68.17\r\n" |
| 6177 | "Connection: keep-alive\r\n" |
| 6178 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 6179 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 6180 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBO54" |
| 6181 | "dFMVvTHwAAAAAAAAAAAAAAAAAAAACS7sT6Uzw7L0L//WUqlIaVWpbI" |
| 6182 | "+4MUm7c=\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6183 | }; |
| 6184 | |
| 6185 | MockRead data_reads3[] = { |
| 6186 | // The origin server responds with a Type 2 message. |
| 6187 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 6188 | MockRead("WWW-Authenticate: NTLM " |
| 6189 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCL24VN8dgOR8AAAAAAAAAALo" |
| 6190 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 6191 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 6192 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 6193 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 6194 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 6195 | "BtAAAAAAA=\r\n"), |
| 6196 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6197 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6198 | MockRead("You are not authorized to view this page\r\n"), |
| 6199 | |
| 6200 | // Lastly we get the desired content. |
| 6201 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6202 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 6203 | MockRead("Content-Length: 13\r\n\r\n"), |
| 6204 | MockRead("Please Login\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6205 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6206 | }; |
| 6207 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6208 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6209 | data_writes1, arraysize(data_writes1)); |
| 6210 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6211 | data_writes2, arraysize(data_writes2)); |
| 6212 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 6213 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6214 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6215 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6216 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6217 | |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame^] | 6218 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 6219 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 6220 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 6221 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 6222 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 6223 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 6224 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6225 | TestCompletionCallback callback1; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6226 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6227 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6228 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6229 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6230 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6231 | |
| 6232 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6233 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6234 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6235 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6236 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6237 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6238 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6239 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6240 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6241 | TestCompletionCallback callback2; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6242 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6243 | // Enter the wrong password. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6244 | rv = trans.RestartWithAuth(AuthCredentials(kTestingNTLM, kWrongPassword), |
| 6245 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6246 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6247 | |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6248 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6249 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6250 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6251 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6252 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6253 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6254 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6255 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6256 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6257 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6258 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6259 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6260 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6261 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6262 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6263 | TestCompletionCallback callback4; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6264 | |
| 6265 | // Now enter the right password. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6266 | rv = trans.RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
| 6267 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6268 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6269 | |
| 6270 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6271 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6272 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6273 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6274 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6275 | TestCompletionCallback callback5; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6276 | |
| 6277 | // One more roundtrip |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6278 | rv = trans.RestartWithAuth(AuthCredentials(), callback5.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6279 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6280 | |
| 6281 | rv = callback5.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6282 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6283 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6284 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6285 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6286 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 6287 | } |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame^] | 6288 | |
| 6289 | // NTLM is not supported over HTTP/2, therefore the server requests a downgrade, |
| 6290 | // and the request is retried on an HTTP/1.1 connection. |
| 6291 | TEST_F(HttpNetworkTransactionTest, NTLMOverHttp2) { |
| 6292 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter(MockGenerateRandom1, |
| 6293 | MockGetHostName); |
| 6294 | |
| 6295 | const char* kUrl = "https://172.22.68.17/kids/login.aspx"; |
| 6296 | |
| 6297 | HttpRequestInfo request; |
| 6298 | request.method = "GET"; |
| 6299 | request.url = GURL(kUrl); |
| 6300 | |
| 6301 | // First request without credentials. |
| 6302 | SpdyHeaderBlock request_headers0(spdy_util_.ConstructGetHeaderBlock(kUrl)); |
| 6303 | SpdySerializedFrame request0(spdy_util_.ConstructSpdyHeaders( |
| 6304 | 1, std::move(request_headers0), LOWEST, true)); |
| 6305 | |
| 6306 | SpdyHeaderBlock response_headers0; |
| 6307 | response_headers0[spdy_util_.GetStatusKey()] = "401"; |
| 6308 | response_headers0["www-authenticate"] = "NTLM"; |
| 6309 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyResponseHeaders( |
| 6310 | 1, std::move(response_headers0), true)); |
| 6311 | |
| 6312 | // Stream 1 is closed. |
| 6313 | spdy_util_.UpdateWithStreamDestruction(1); |
| 6314 | |
| 6315 | // Retry with authorization header. |
| 6316 | SpdyHeaderBlock request_headers1(spdy_util_.ConstructGetHeaderBlock(kUrl)); |
| 6317 | request_headers1["authorization"] = |
| 6318 | "NTLM TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA="; |
| 6319 | SpdySerializedFrame request1(spdy_util_.ConstructSpdyHeaders( |
| 6320 | 3, std::move(request_headers1), LOWEST, true)); |
| 6321 | |
| 6322 | SpdySerializedFrame go_away(spdy_util_.ConstructSpdyGoAway( |
| 6323 | 0, ERROR_CODE_HTTP_1_1_REQUIRED, "NTLM not supported over HTTP/2.")); |
| 6324 | |
| 6325 | MockWrite writes0[] = { |
| 6326 | CreateMockWrite(request0, 0), CreateMockWrite(request1, 2), |
| 6327 | }; |
| 6328 | MockRead reads0[] = {CreateMockRead(resp, 1), CreateMockRead(go_away, 3)}; |
| 6329 | |
| 6330 | // Retry yet again using HTTP/1.1. |
| 6331 | MockWrite writes1[] = { |
| 6332 | // After restarting with a null identity, this is the |
| 6333 | // request we should be issuing -- the final header line contains a Type |
| 6334 | // 1 message. |
| 6335 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6336 | "Host: 172.22.68.17\r\n" |
| 6337 | "Connection: keep-alive\r\n" |
| 6338 | "Authorization: NTLM " |
| 6339 | "TlRMTVNTUAABAAAAB4IIAAAAAAAAAAAAAAAAAAAAAAA=\r\n\r\n"), |
| 6340 | |
| 6341 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 6342 | // (the credentials for the origin server). The second request continues |
| 6343 | // on the same connection. |
| 6344 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6345 | "Host: 172.22.68.17\r\n" |
| 6346 | "Connection: keep-alive\r\n" |
| 6347 | "Authorization: NTLM TlRMTVNTUAADAAAAGAAYAGgAAAAYABgAgA" |
| 6348 | "AAAAAAAABAAAAAGAAYAEAAAAAQABAAWAAAAAAAAAAAAAAABYIIAHQA" |
| 6349 | "ZQBzAHQAaQBuAGcALQBuAHQAbABtAFcAVABDAC0AVwBJAE4ANwBVKW" |
| 6350 | "Yma5xzVAAAAAAAAAAAAAAAAAAAAACH+gWcm+YsP9Tqb9zCR3WAeZZX" |
| 6351 | "ahlhx5I=\r\n\r\n"), |
| 6352 | }; |
| 6353 | |
| 6354 | MockRead reads1[] = { |
| 6355 | // The origin server responds with a Type 2 message. |
| 6356 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 6357 | MockRead("WWW-Authenticate: NTLM " |
| 6358 | "TlRMTVNTUAACAAAADAAMADgAAAAFgokCjGpMpPGlYKkAAAAAAAAAALo" |
| 6359 | "AugBEAAAABQEoCgAAAA9HAE8ATwBHAEwARQACAAwARwBPAE8ARwBMAE" |
| 6360 | "UAAQAaAEEASwBFAEUAUwBBAFIAQQAtAEMATwBSAFAABAAeAGMAbwByA" |
| 6361 | "HAALgBnAG8AbwBnAGwAZQAuAGMAbwBtAAMAQABhAGsAZQBlAHMAYQBy" |
| 6362 | "AGEALQBjAG8AcgBwAC4AYQBkAC4AYwBvAHIAcAAuAGcAbwBvAGcAbAB" |
| 6363 | "lAC4AYwBvAG0ABQAeAGMAbwByAHAALgBnAG8AbwBnAGwAZQAuAGMAbw" |
| 6364 | "BtAAAAAAA=\r\n"), |
| 6365 | MockRead("Content-Length: 42\r\n"), |
| 6366 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6367 | MockRead("You are not authorized to view this page\r\n"), |
| 6368 | |
| 6369 | // Lastly we get the desired content. |
| 6370 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6371 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 6372 | MockRead("Content-Length: 13\r\n\r\n"), MockRead("Please Login\r\n"), |
| 6373 | MockRead(SYNCHRONOUS, OK), |
| 6374 | }; |
| 6375 | SequencedSocketData data0(reads0, arraysize(reads0), writes0, |
| 6376 | arraysize(writes0)); |
| 6377 | StaticSocketDataProvider data1(reads1, arraysize(reads1), writes1, |
| 6378 | arraysize(writes1)); |
| 6379 | session_deps_.socket_factory->AddSocketDataProvider(&data0); |
| 6380 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6381 | |
| 6382 | SSLSocketDataProvider ssl0(ASYNC, OK); |
| 6383 | ssl0.next_proto = kProtoHTTP2; |
| 6384 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 6385 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl0); |
| 6386 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 6387 | |
| 6388 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6389 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 6390 | |
| 6391 | TestCompletionCallback callback1; |
| 6392 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
| 6393 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6394 | |
| 6395 | rv = callback1.WaitForResult(); |
| 6396 | EXPECT_THAT(rv, IsOk()); |
| 6397 | |
| 6398 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
| 6399 | |
| 6400 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 6401 | ASSERT_TRUE(response); |
| 6402 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
| 6403 | |
| 6404 | TestCompletionCallback callback2; |
| 6405 | |
| 6406 | rv = trans.RestartWithAuth(AuthCredentials(kTestingNTLM, kTestingNTLM), |
| 6407 | callback2.callback()); |
| 6408 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6409 | |
| 6410 | rv = callback2.WaitForResult(); |
| 6411 | EXPECT_THAT(rv, IsOk()); |
| 6412 | |
| 6413 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 6414 | |
| 6415 | response = trans.GetResponseInfo(); |
| 6416 | ASSERT_TRUE(response); |
| 6417 | EXPECT_FALSE(response->auth_challenge); |
| 6418 | |
| 6419 | TestCompletionCallback callback3; |
| 6420 | |
| 6421 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
| 6422 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6423 | |
| 6424 | rv = callback3.WaitForResult(); |
| 6425 | EXPECT_THAT(rv, IsOk()); |
| 6426 | |
| 6427 | response = trans.GetResponseInfo(); |
| 6428 | ASSERT_TRUE(response); |
| 6429 | EXPECT_FALSE(response->auth_challenge); |
| 6430 | EXPECT_EQ(13, response->headers->GetContentLength()); |
| 6431 | } |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6432 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6433 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6434 | // Test reading a server response which has only headers, and no body. |
| 6435 | // After some maximum number of bytes is consumed, the transaction should |
| 6436 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6437 | TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6438 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6439 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6440 | request.url = GURL("http://www.example.org/"); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6441 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6442 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6443 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6444 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 6445 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 6446 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 6447 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6448 | |
| 6449 | MockRead data_reads[] = { |
| 6450 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6451 | MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6452 | MockRead("\r\nBODY"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6453 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6454 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6455 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6456 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6457 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6458 | TestCompletionCallback callback; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6459 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6460 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6461 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6462 | |
| 6463 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6464 | EXPECT_THAT(rv, IsError(ERR_RESPONSE_HEADERS_TOO_BIG)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6465 | } |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6466 | |
| 6467 | // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 6468 | // establish tunnel. |
| 6469 | // http://code.google.com/p/chromium/issues/detail?id=3772 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6470 | TEST_F(HttpNetworkTransactionTest, DontRecycleTransportSocketForSSLTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6471 | HttpRequestInfo request; |
| 6472 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6473 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6474 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6475 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 6476 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 6477 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6478 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6479 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6480 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6481 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6482 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6483 | // Since we have proxy, should try to establish tunnel. |
| 6484 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 6485 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6486 | "Host: www.example.org:443\r\n" |
| 6487 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6488 | }; |
| 6489 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 6490 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6491 | // connection. Usually a proxy would return 501 (not implemented), |
| 6492 | // or 200 (tunnel established). |
| 6493 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 6494 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 6495 | MockRead("Content-Length: 10\r\n\r\n"), |
| 6496 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6497 | }; |
| 6498 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6499 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6500 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6501 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6502 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6503 | TestCompletionCallback callback1; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6504 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6505 | int rv = trans->Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6506 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6507 | |
| 6508 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6509 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6510 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6511 | // Empty the current queue. This is necessary because idle sockets are |
| 6512 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6513 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6514 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6515 | // We now check to make sure the TCPClientSocket was not added back to |
| 6516 | // the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6517 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6518 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6519 | base::RunLoop().RunUntilIdle(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6520 | // Make sure that the socket didn't get recycled after calling the destructor. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6521 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 6522 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6523 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6524 | // Make sure that we recycle a socket after reading all of the response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6525 | TEST_F(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6526 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6527 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6528 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6529 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6530 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6531 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6532 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6533 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6534 | MockRead data_reads[] = { |
| 6535 | // A part of the response body is received with the response headers. |
| 6536 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 6537 | // The rest of the response body is received in two parts. |
| 6538 | MockRead("lo"), |
| 6539 | MockRead(" world"), |
| 6540 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6541 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6542 | }; |
| 6543 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6544 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6545 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6546 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6547 | TestCompletionCallback callback; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6548 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6549 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6550 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6551 | |
| 6552 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6553 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6554 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6555 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6556 | ASSERT_TRUE(response); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6557 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6558 | EXPECT_TRUE(response->headers); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6559 | std::string status_line = response->headers->GetStatusLine(); |
| 6560 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 6561 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6562 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6563 | |
| 6564 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6565 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6566 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6567 | EXPECT_EQ("hello world", response_data); |
| 6568 | |
| 6569 | // Empty the current queue. This is necessary because idle sockets are |
| 6570 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6571 | base::RunLoop().RunUntilIdle(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6572 | |
| 6573 | // 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] | 6574 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 6575 | } |
| 6576 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6577 | // Make sure that we recycle a SSL socket after reading all of the response |
| 6578 | // body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6579 | TEST_F(HttpNetworkTransactionTest, RecycleSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6580 | HttpRequestInfo request; |
| 6581 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6582 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6583 | |
| 6584 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6585 | MockWrite( |
| 6586 | "GET / HTTP/1.1\r\n" |
| 6587 | "Host: www.example.org\r\n" |
| 6588 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6589 | }; |
| 6590 | |
| 6591 | MockRead data_reads[] = { |
| 6592 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6593 | MockRead("Content-Length: 11\r\n\r\n"), |
| 6594 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6595 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6596 | }; |
| 6597 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6598 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6599 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6600 | |
| 6601 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6602 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6603 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6604 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6605 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6606 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6607 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6608 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6609 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6610 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6611 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6612 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6613 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6614 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6615 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6616 | ASSERT_TRUE(response); |
| 6617 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6618 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6619 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6620 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6621 | |
| 6622 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6623 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6624 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6625 | EXPECT_EQ("hello world", response_data); |
| 6626 | |
| 6627 | // Empty the current queue. This is necessary because idle sockets are |
| 6628 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6629 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6630 | |
| 6631 | // 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] | 6632 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6633 | } |
| 6634 | |
| 6635 | // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it |
| 6636 | // from the pool and make sure that we recover okay. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6637 | TEST_F(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6638 | HttpRequestInfo request; |
| 6639 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6640 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6641 | |
| 6642 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6643 | MockWrite( |
| 6644 | "GET / HTTP/1.1\r\n" |
| 6645 | "Host: www.example.org\r\n" |
| 6646 | "Connection: keep-alive\r\n\r\n"), |
| 6647 | MockWrite( |
| 6648 | "GET / HTTP/1.1\r\n" |
| 6649 | "Host: www.example.org\r\n" |
| 6650 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6651 | }; |
| 6652 | |
| 6653 | MockRead data_reads[] = { |
mmenke | 911ee022 | 2015-12-04 03:58:42 | [diff] [blame] | 6654 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 6655 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6656 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6657 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6658 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6659 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6660 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6661 | |
| 6662 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 6663 | data_writes, arraysize(data_writes)); |
| 6664 | StaticSocketDataProvider data2(data_reads, arraysize(data_reads), |
| 6665 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6666 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6667 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6668 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6669 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6670 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6671 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6672 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6673 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6674 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6675 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6676 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6677 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6678 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6679 | |
| 6680 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6681 | ASSERT_TRUE(response); |
| 6682 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6683 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6684 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6685 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6686 | |
| 6687 | std::string response_data; |
| 6688 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6689 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6690 | EXPECT_EQ("hello world", response_data); |
| 6691 | |
| 6692 | // Empty the current queue. This is necessary because idle sockets are |
| 6693 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6694 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6695 | |
| 6696 | // 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] | 6697 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6698 | |
| 6699 | // Now start the second transaction, which should reuse the previous socket. |
| 6700 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6701 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6702 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6703 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6704 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6705 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6706 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6707 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6708 | |
| 6709 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6710 | ASSERT_TRUE(response); |
| 6711 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6712 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6713 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6714 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6715 | |
| 6716 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6717 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6718 | EXPECT_EQ("hello world", response_data); |
| 6719 | |
| 6720 | // Empty the current queue. This is necessary because idle sockets are |
| 6721 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6722 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6723 | |
| 6724 | // 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] | 6725 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 6726 | } |
| 6727 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6728 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 6729 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6730 | TEST_F(HttpNetworkTransactionTest, FlushSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6731 | HttpRequestInfo request; |
| 6732 | request.method = "GET"; |
| 6733 | request.url = GURL("http://www.example.org/"); |
| 6734 | request.load_flags = 0; |
| 6735 | |
| 6736 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6737 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6738 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6739 | |
| 6740 | MockRead data_reads[] = { |
| 6741 | // A part of the response body is received with the response headers. |
| 6742 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 6743 | // The rest of the response body is received in two parts. |
| 6744 | MockRead("lo"), MockRead(" world"), |
| 6745 | MockRead("junk"), // Should not be read!! |
| 6746 | MockRead(SYNCHRONOUS, OK), |
| 6747 | }; |
| 6748 | |
| 6749 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 6750 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6751 | |
| 6752 | TestCompletionCallback callback; |
| 6753 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6754 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6755 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6756 | |
| 6757 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6758 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6759 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6760 | ASSERT_TRUE(response); |
| 6761 | EXPECT_TRUE(response->headers); |
| 6762 | std::string status_line = response->headers->GetStatusLine(); |
| 6763 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 6764 | |
| 6765 | // Make memory critical notification and ensure the transaction still has been |
| 6766 | // operating right. |
| 6767 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 6768 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 6769 | base::RunLoop().RunUntilIdle(); |
| 6770 | |
| 6771 | // Socket should not be flushed as long as it is not idle. |
| 6772 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 6773 | |
| 6774 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6775 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6776 | EXPECT_THAT(rv, IsOk()); |
| 6777 | EXPECT_EQ("hello world", response_data); |
| 6778 | |
| 6779 | // Empty the current queue. This is necessary because idle sockets are |
| 6780 | // added to the connection pool asynchronously with a PostTask. |
| 6781 | base::RunLoop().RunUntilIdle(); |
| 6782 | |
| 6783 | // We now check to make sure the socket was added back to the pool. |
| 6784 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 6785 | |
| 6786 | // Idle sockets should be flushed now. |
| 6787 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 6788 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 6789 | base::RunLoop().RunUntilIdle(); |
| 6790 | |
| 6791 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 6792 | } |
| 6793 | |
| 6794 | // Grab an SSL socket, use it, and put it back into the pool. Then, make |
| 6795 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6796 | TEST_F(HttpNetworkTransactionTest, FlushSSLSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6797 | HttpRequestInfo request; |
| 6798 | request.method = "GET"; |
| 6799 | request.url = GURL("https://www.example.org/"); |
| 6800 | request.load_flags = 0; |
| 6801 | |
| 6802 | MockWrite data_writes[] = { |
| 6803 | MockWrite("GET / HTTP/1.1\r\n" |
| 6804 | "Host: www.example.org\r\n" |
| 6805 | "Connection: keep-alive\r\n\r\n"), |
| 6806 | }; |
| 6807 | |
| 6808 | MockRead data_reads[] = { |
| 6809 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 6810 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
| 6811 | |
| 6812 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6813 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6814 | |
| 6815 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 6816 | arraysize(data_writes)); |
| 6817 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6818 | |
| 6819 | TestCompletionCallback callback; |
| 6820 | |
| 6821 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6822 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6823 | |
| 6824 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6825 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6826 | |
| 6827 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6828 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6829 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6830 | ASSERT_TRUE(response); |
| 6831 | ASSERT_TRUE(response->headers); |
| 6832 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6833 | |
| 6834 | // Make memory critical notification and ensure the transaction still has been |
| 6835 | // operating right. |
| 6836 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 6837 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 6838 | base::RunLoop().RunUntilIdle(); |
| 6839 | |
| 6840 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 6841 | |
| 6842 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6843 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 6844 | EXPECT_THAT(rv, IsOk()); |
| 6845 | EXPECT_EQ("hello world", response_data); |
| 6846 | |
| 6847 | // Empty the current queue. This is necessary because idle sockets are |
| 6848 | // added to the connection pool asynchronously with a PostTask. |
| 6849 | base::RunLoop().RunUntilIdle(); |
| 6850 | |
| 6851 | // We now check to make sure the socket was added back to the pool. |
| 6852 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 6853 | |
| 6854 | // Make memory notification once again and ensure idle socket is closed. |
| 6855 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 6856 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 6857 | base::RunLoop().RunUntilIdle(); |
| 6858 | |
| 6859 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 6860 | } |
| 6861 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6862 | // Make sure that we recycle a socket after a zero-length response. |
| 6863 | // http://crbug.com/9880 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6864 | TEST_F(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6865 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6866 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6867 | request.url = GURL( |
| 6868 | "http://www.example.org/csi?v=3&s=web&action=&" |
| 6869 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 6870 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 6871 | "rt=prt.2642,ol.2649,xjs.2951"); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6872 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6873 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6874 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6875 | MockRead data_reads[] = { |
| 6876 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 6877 | "Content-Length: 0\r\n" |
| 6878 | "Content-Type: text/html\r\n\r\n"), |
| 6879 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6880 | MockRead(SYNCHRONOUS, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6881 | }; |
| 6882 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6883 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6884 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6885 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 6886 | // Transaction must be created after the MockReads, so it's destroyed before |
| 6887 | // them. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6888 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 6889 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6890 | TestCompletionCallback callback; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6891 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6892 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6893 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6894 | |
| 6895 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6896 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6897 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6898 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6899 | ASSERT_TRUE(response); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6900 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6901 | EXPECT_TRUE(response->headers); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6902 | std::string status_line = response->headers->GetStatusLine(); |
| 6903 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 6904 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6905 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6906 | |
| 6907 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6908 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6909 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6910 | EXPECT_EQ("", response_data); |
| 6911 | |
| 6912 | // Empty the current queue. This is necessary because idle sockets are |
| 6913 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 6914 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6915 | |
| 6916 | // 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] | 6917 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 6918 | } |
| 6919 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6920 | TEST_F(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6921 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 6922 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6923 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 6924 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 6925 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6926 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6927 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 6928 | // after use. |
| 6929 | request[0].method = "GET"; |
| 6930 | request[0].url = GURL("http://www.google.com/"); |
| 6931 | request[0].load_flags = 0; |
| 6932 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 6933 | // transaction 1. The first attempts fails when writing the POST data. |
| 6934 | // This causes the transaction to retry with a new socket. The second |
| 6935 | // attempt succeeds. |
| 6936 | request[1].method = "POST"; |
| 6937 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 6938 | request[1].upload_data_stream = &upload_data_stream; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6939 | request[1].load_flags = 0; |
| 6940 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6941 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6942 | |
| 6943 | // The first socket is used for transaction 1 and the first attempt of |
| 6944 | // transaction 2. |
| 6945 | |
| 6946 | // The response of transaction 1. |
| 6947 | MockRead data_reads1[] = { |
| 6948 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 6949 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6950 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6951 | }; |
| 6952 | // The mock write results of transaction 1 and the first attempt of |
| 6953 | // transaction 2. |
| 6954 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6955 | MockWrite(SYNCHRONOUS, 64), // GET |
| 6956 | MockWrite(SYNCHRONOUS, 93), // POST |
| 6957 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6958 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6959 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 6960 | data_writes1, arraysize(data_writes1)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6961 | |
| 6962 | // The second socket is used for the second attempt of transaction 2. |
| 6963 | |
| 6964 | // The response of transaction 2. |
| 6965 | MockRead data_reads2[] = { |
| 6966 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 6967 | MockRead("welcome"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6968 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6969 | }; |
| 6970 | // The mock write results of the second attempt of transaction 2. |
| 6971 | MockWrite data_writes2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6972 | MockWrite(SYNCHRONOUS, 93), // POST |
| 6973 | MockWrite(SYNCHRONOUS, 3), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6974 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 6975 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 6976 | data_writes2, arraysize(data_writes2)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6977 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6978 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6979 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6980 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 6981 | const char* const kExpectedResponseData[] = { |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6982 | "hello world", "welcome" |
| 6983 | }; |
| 6984 | |
| 6985 | for (int i = 0; i < 2; ++i) { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6986 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6987 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6988 | TestCompletionCallback callback; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6989 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6990 | int rv = trans.Start(&request[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6991 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6992 | |
| 6993 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6994 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6995 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6996 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6997 | ASSERT_TRUE(response); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 6998 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6999 | EXPECT_TRUE(response->headers); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7000 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 7001 | |
| 7002 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7003 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7004 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7005 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 7006 | } |
| 7007 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7008 | |
| 7009 | // Test the request-challenge-retry sequence for basic auth when there is |
| 7010 | // 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] | 7011 | // it fails the identity from the URL is used to answer the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7012 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7013 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7014 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7015 | request.url = GURL("http://foo:b@[email protected]/"); |
[email protected] | 7b08ba6 | 2012-02-10 20:19:41 | [diff] [blame] | 7016 | request.load_flags = LOAD_NORMAL; |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 7017 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7018 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7019 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7020 | |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 7021 | // The password contains an escaped character -- for this test to pass it |
| 7022 | // will need to be unescaped by HttpNetworkTransaction. |
| 7023 | EXPECT_EQ("b%40r", request.url.password()); |
| 7024 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7025 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7026 | MockWrite( |
| 7027 | "GET / HTTP/1.1\r\n" |
| 7028 | "Host: www.example.org\r\n" |
| 7029 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7030 | }; |
| 7031 | |
| 7032 | MockRead data_reads1[] = { |
| 7033 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7034 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7035 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7036 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7037 | }; |
| 7038 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7039 | // After the challenge above, the transaction will be restarted using the |
| 7040 | // identity from the url (foo, b@r) to answer the challenge. |
| 7041 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7042 | MockWrite( |
| 7043 | "GET / HTTP/1.1\r\n" |
| 7044 | "Host: www.example.org\r\n" |
| 7045 | "Connection: keep-alive\r\n" |
| 7046 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7047 | }; |
| 7048 | |
| 7049 | MockRead data_reads2[] = { |
| 7050 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7051 | MockRead("Content-Length: 100\r\n\r\n"), |
| 7052 | MockRead(SYNCHRONOUS, OK), |
| 7053 | }; |
| 7054 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7055 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7056 | data_writes1, arraysize(data_writes1)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7057 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7058 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7059 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7060 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7061 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7062 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7063 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7064 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7065 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7066 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7067 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7068 | |
| 7069 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7070 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7071 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7072 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7073 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7074 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7075 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7076 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7077 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7078 | |
| 7079 | // There is no challenge info, since the identity in URL worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7080 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7081 | |
| 7082 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7083 | |
| 7084 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7085 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7086 | } |
| 7087 | |
| 7088 | // Test the request-challenge-retry sequence for basic auth when there is an |
| 7089 | // incorrect identity in the URL. The identity from the URL should be used only |
| 7090 | // once. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7091 | TEST_F(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7092 | HttpRequestInfo request; |
| 7093 | request.method = "GET"; |
| 7094 | // Note: the URL has a username:password in it. The password "baz" is |
| 7095 | // wrong (should be "bar"). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7096 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7097 | |
| 7098 | request.load_flags = LOAD_NORMAL; |
| 7099 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7100 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7101 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7102 | |
| 7103 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7104 | MockWrite( |
| 7105 | "GET / HTTP/1.1\r\n" |
| 7106 | "Host: www.example.org\r\n" |
| 7107 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7108 | }; |
| 7109 | |
| 7110 | MockRead data_reads1[] = { |
| 7111 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7112 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7113 | MockRead("Content-Length: 10\r\n\r\n"), |
| 7114 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 7115 | }; |
| 7116 | |
| 7117 | // After the challenge above, the transaction will be restarted using the |
| 7118 | // identity from the url (foo, baz) to answer the challenge. |
| 7119 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7120 | MockWrite( |
| 7121 | "GET / HTTP/1.1\r\n" |
| 7122 | "Host: www.example.org\r\n" |
| 7123 | "Connection: keep-alive\r\n" |
| 7124 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7125 | }; |
| 7126 | |
| 7127 | MockRead data_reads2[] = { |
| 7128 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7129 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7130 | MockRead("Content-Length: 10\r\n\r\n"), |
| 7131 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 7132 | }; |
| 7133 | |
| 7134 | // After the challenge above, the transaction will be restarted using the |
| 7135 | // identity supplied by the user (foo, bar) to answer the challenge. |
| 7136 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7137 | MockWrite( |
| 7138 | "GET / HTTP/1.1\r\n" |
| 7139 | "Host: www.example.org\r\n" |
| 7140 | "Connection: keep-alive\r\n" |
| 7141 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7142 | }; |
| 7143 | |
| 7144 | MockRead data_reads3[] = { |
| 7145 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7146 | MockRead("Content-Length: 100\r\n\r\n"), |
| 7147 | MockRead(SYNCHRONOUS, OK), |
| 7148 | }; |
| 7149 | |
| 7150 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7151 | data_writes1, arraysize(data_writes1)); |
| 7152 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7153 | data_writes2, arraysize(data_writes2)); |
| 7154 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 7155 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7156 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7157 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7158 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7159 | |
| 7160 | TestCompletionCallback callback1; |
| 7161 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7162 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7163 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7164 | |
| 7165 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7166 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7167 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7168 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7169 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7170 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7171 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7172 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7173 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7174 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7175 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7176 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7177 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7178 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 7179 | |
| 7180 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7181 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7182 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7183 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7184 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7185 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7186 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7187 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7188 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7189 | |
| 7190 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7191 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7192 | |
| 7193 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7194 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 7195 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7196 | base::RunLoop().RunUntilIdle(); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 7197 | } |
| 7198 | |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7199 | |
| 7200 | // Test the request-challenge-retry sequence for basic auth when there is a |
| 7201 | // correct identity in the URL, but its use is being suppressed. The identity |
| 7202 | // from the URL should never be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7203 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURLSuppressed) { |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7204 | HttpRequestInfo request; |
| 7205 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7206 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7207 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
| 7208 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7209 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7210 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7211 | |
| 7212 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7213 | MockWrite( |
| 7214 | "GET / HTTP/1.1\r\n" |
| 7215 | "Host: www.example.org\r\n" |
| 7216 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7217 | }; |
| 7218 | |
| 7219 | MockRead data_reads1[] = { |
| 7220 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7221 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7222 | MockRead("Content-Length: 10\r\n\r\n"), |
| 7223 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 7224 | }; |
| 7225 | |
| 7226 | // After the challenge above, the transaction will be restarted using the |
| 7227 | // identity supplied by the user, not the one in the URL, to answer the |
| 7228 | // challenge. |
| 7229 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7230 | MockWrite( |
| 7231 | "GET / HTTP/1.1\r\n" |
| 7232 | "Host: www.example.org\r\n" |
| 7233 | "Connection: keep-alive\r\n" |
| 7234 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7235 | }; |
| 7236 | |
| 7237 | MockRead data_reads3[] = { |
| 7238 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7239 | MockRead("Content-Length: 100\r\n\r\n"), |
| 7240 | MockRead(SYNCHRONOUS, OK), |
| 7241 | }; |
| 7242 | |
| 7243 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7244 | data_writes1, arraysize(data_writes1)); |
| 7245 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 7246 | data_writes3, arraysize(data_writes3)); |
| 7247 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7248 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 7249 | |
| 7250 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7251 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7252 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7253 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7254 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7255 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7256 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7257 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7258 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7259 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 7260 | |
| 7261 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7262 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7263 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7264 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7265 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7266 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7267 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7268 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7269 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7270 | |
| 7271 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7272 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7273 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7274 | |
| 7275 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7276 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7277 | } |
| 7278 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7279 | // Test that previously tried username/passwords for a realm get re-used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7280 | TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7281 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7282 | |
| 7283 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 7284 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7285 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7286 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7287 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7288 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7289 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7290 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7291 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7292 | MockWrite( |
| 7293 | "GET /x/y/z HTTP/1.1\r\n" |
| 7294 | "Host: www.example.org\r\n" |
| 7295 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7296 | }; |
| 7297 | |
| 7298 | MockRead data_reads1[] = { |
| 7299 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7300 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7301 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7302 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7303 | }; |
| 7304 | |
| 7305 | // Resend with authorization (username=foo, password=bar) |
| 7306 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7307 | MockWrite( |
| 7308 | "GET /x/y/z HTTP/1.1\r\n" |
| 7309 | "Host: www.example.org\r\n" |
| 7310 | "Connection: keep-alive\r\n" |
| 7311 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7312 | }; |
| 7313 | |
| 7314 | // Sever accepts the authorization. |
| 7315 | MockRead data_reads2[] = { |
| 7316 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7317 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7318 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7319 | }; |
| 7320 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7321 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7322 | data_writes1, arraysize(data_writes1)); |
| 7323 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7324 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7325 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7326 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7327 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7328 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7329 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7330 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7331 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7332 | |
| 7333 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7334 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7335 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7336 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7337 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7338 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7339 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7340 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7341 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7342 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 7343 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7344 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7345 | |
| 7346 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7347 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7348 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7349 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7350 | ASSERT_TRUE(response); |
| 7351 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7352 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7353 | } |
| 7354 | |
| 7355 | // ------------------------------------------------------------------------ |
| 7356 | |
| 7357 | // Transaction 2: authenticate (foo2, bar2) on MyRealm2 |
| 7358 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7359 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7360 | request.method = "GET"; |
| 7361 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 7362 | // protection space as MyRealm1. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7363 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7364 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7365 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7366 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7367 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7368 | MockWrite( |
| 7369 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 7370 | "Host: www.example.org\r\n" |
| 7371 | "Connection: keep-alive\r\n" |
| 7372 | // Send preemptive authorization for MyRealm1 |
| 7373 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7374 | }; |
| 7375 | |
| 7376 | // The server didn't like the preemptive authorization, and |
| 7377 | // challenges us for a different realm (MyRealm2). |
| 7378 | MockRead data_reads1[] = { |
| 7379 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7380 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 7381 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7382 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7383 | }; |
| 7384 | |
| 7385 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 7386 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7387 | MockWrite( |
| 7388 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 7389 | "Host: www.example.org\r\n" |
| 7390 | "Connection: keep-alive\r\n" |
| 7391 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7392 | }; |
| 7393 | |
| 7394 | // Sever accepts the authorization. |
| 7395 | MockRead data_reads2[] = { |
| 7396 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7397 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7398 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7399 | }; |
| 7400 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7401 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7402 | data_writes1, arraysize(data_writes1)); |
| 7403 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7404 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7405 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7406 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7407 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7408 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7409 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7410 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7411 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7412 | |
| 7413 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7414 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7415 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7416 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7417 | ASSERT_TRUE(response); |
| 7418 | ASSERT_TRUE(response->auth_challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7419 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 7420 | EXPECT_EQ("http://www.example.org", |
| 7421 | response->auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7422 | EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 7423 | EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7424 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7425 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7426 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7427 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 7428 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7429 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7430 | |
| 7431 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7432 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7433 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7434 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7435 | ASSERT_TRUE(response); |
| 7436 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7437 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7438 | } |
| 7439 | |
| 7440 | // ------------------------------------------------------------------------ |
| 7441 | |
| 7442 | // Transaction 3: Resend a request in MyRealm's protection space -- |
| 7443 | // succeed with preemptive authorization. |
| 7444 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7445 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7446 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7447 | request.url = GURL("http://www.example.org/x/y/z2"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7448 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7449 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7450 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7451 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7452 | MockWrite( |
| 7453 | "GET /x/y/z2 HTTP/1.1\r\n" |
| 7454 | "Host: www.example.org\r\n" |
| 7455 | "Connection: keep-alive\r\n" |
| 7456 | // The authorization for MyRealm1 gets sent preemptively |
| 7457 | // (since the url is in the same protection space) |
| 7458 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7459 | }; |
| 7460 | |
| 7461 | // Sever accepts the preemptive authorization |
| 7462 | MockRead data_reads1[] = { |
| 7463 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7464 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7465 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7466 | }; |
| 7467 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7468 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7469 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7470 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7471 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7472 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7473 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7474 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7475 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7476 | |
| 7477 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7478 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7479 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7480 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7481 | ASSERT_TRUE(response); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7482 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7483 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7484 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7485 | } |
| 7486 | |
| 7487 | // ------------------------------------------------------------------------ |
| 7488 | |
| 7489 | // Transaction 4: request another URL in MyRealm (however the |
| 7490 | // url is not known to belong to the protection space, so no pre-auth). |
| 7491 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7492 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7493 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7494 | request.url = GURL("http://www.example.org/x/1"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7495 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7496 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7497 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7498 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7499 | MockWrite( |
| 7500 | "GET /x/1 HTTP/1.1\r\n" |
| 7501 | "Host: www.example.org\r\n" |
| 7502 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7503 | }; |
| 7504 | |
| 7505 | MockRead data_reads1[] = { |
| 7506 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7507 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7508 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7509 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7510 | }; |
| 7511 | |
| 7512 | // Resend with authorization from MyRealm's cache. |
| 7513 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7514 | MockWrite( |
| 7515 | "GET /x/1 HTTP/1.1\r\n" |
| 7516 | "Host: www.example.org\r\n" |
| 7517 | "Connection: keep-alive\r\n" |
| 7518 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7519 | }; |
| 7520 | |
| 7521 | // Sever accepts the authorization. |
| 7522 | MockRead data_reads2[] = { |
| 7523 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7524 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7525 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7526 | }; |
| 7527 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7528 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7529 | data_writes1, arraysize(data_writes1)); |
| 7530 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7531 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7532 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7533 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7534 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7535 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7536 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7537 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7538 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7539 | |
| 7540 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7541 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7542 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7543 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7544 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7545 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7546 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7547 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7548 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7549 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7550 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7551 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7552 | ASSERT_TRUE(response); |
| 7553 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7554 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7555 | } |
| 7556 | |
| 7557 | // ------------------------------------------------------------------------ |
| 7558 | |
| 7559 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 7560 | // cached identity. Should invalidate and re-prompt. |
| 7561 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7562 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7563 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7564 | request.url = GURL("http://www.example.org/p/q/t"); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7565 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7566 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7567 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7568 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7569 | MockWrite( |
| 7570 | "GET /p/q/t HTTP/1.1\r\n" |
| 7571 | "Host: www.example.org\r\n" |
| 7572 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7573 | }; |
| 7574 | |
| 7575 | MockRead data_reads1[] = { |
| 7576 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7577 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7578 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7579 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7580 | }; |
| 7581 | |
| 7582 | // Resend with authorization from cache for MyRealm. |
| 7583 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7584 | MockWrite( |
| 7585 | "GET /p/q/t HTTP/1.1\r\n" |
| 7586 | "Host: www.example.org\r\n" |
| 7587 | "Connection: keep-alive\r\n" |
| 7588 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7589 | }; |
| 7590 | |
| 7591 | // Sever rejects the authorization. |
| 7592 | MockRead data_reads2[] = { |
| 7593 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7594 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7595 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7596 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7597 | }; |
| 7598 | |
| 7599 | // At this point we should prompt for new credentials for MyRealm. |
| 7600 | // Restart with username=foo3, password=foo4. |
| 7601 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7602 | MockWrite( |
| 7603 | "GET /p/q/t HTTP/1.1\r\n" |
| 7604 | "Host: www.example.org\r\n" |
| 7605 | "Connection: keep-alive\r\n" |
| 7606 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7607 | }; |
| 7608 | |
| 7609 | // Sever accepts the authorization. |
| 7610 | MockRead data_reads3[] = { |
| 7611 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7612 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7613 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7614 | }; |
| 7615 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7616 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7617 | data_writes1, arraysize(data_writes1)); |
| 7618 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7619 | data_writes2, arraysize(data_writes2)); |
| 7620 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 7621 | data_writes3, arraysize(data_writes3)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7622 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7623 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7624 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7625 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7626 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7627 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7628 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7629 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7630 | |
| 7631 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7632 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7633 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7634 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7635 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7636 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7637 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7638 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7639 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7640 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7641 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7642 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7643 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7644 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7645 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7646 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7647 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7648 | rv = trans.RestartWithAuth(AuthCredentials(kFoo3, kBar3), |
| 7649 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7650 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7651 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7652 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7653 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7654 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7655 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7656 | ASSERT_TRUE(response); |
| 7657 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7658 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7659 | } |
| 7660 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7661 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7662 | // Tests that nonce count increments when multiple auth attempts |
| 7663 | // are started with the same nonce. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7664 | TEST_F(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { |
[email protected] | 54fea256 | 2010-11-17 14:40:44 | [diff] [blame] | 7665 | HttpAuthHandlerDigest::Factory* digest_factory = |
| 7666 | new HttpAuthHandlerDigest::Factory(); |
| 7667 | HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = |
| 7668 | new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); |
| 7669 | digest_factory->set_nonce_generator(nonce_generator); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7670 | session_deps_.http_auth_handler_factory.reset(digest_factory); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7671 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7672 | |
| 7673 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 7674 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7675 | HttpRequestInfo request; |
| 7676 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7677 | request.url = GURL("http://www.example.org/x/y/z"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7678 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7679 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7680 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7681 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7682 | MockWrite( |
| 7683 | "GET /x/y/z HTTP/1.1\r\n" |
| 7684 | "Host: www.example.org\r\n" |
| 7685 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7686 | }; |
| 7687 | |
| 7688 | MockRead data_reads1[] = { |
| 7689 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7690 | MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " |
| 7691 | "algorithm=MD5, qop=\"auth\"\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7692 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7693 | }; |
| 7694 | |
| 7695 | // Resend with authorization (username=foo, password=bar) |
| 7696 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7697 | MockWrite( |
| 7698 | "GET /x/y/z HTTP/1.1\r\n" |
| 7699 | "Host: www.example.org\r\n" |
| 7700 | "Connection: keep-alive\r\n" |
| 7701 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 7702 | "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " |
| 7703 | "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " |
| 7704 | "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7705 | }; |
| 7706 | |
| 7707 | // Sever accepts the authorization. |
| 7708 | MockRead data_reads2[] = { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 7709 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7710 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7711 | }; |
| 7712 | |
| 7713 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7714 | data_writes1, arraysize(data_writes1)); |
| 7715 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 7716 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7717 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7718 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7719 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7720 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7721 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7722 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7723 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7724 | |
| 7725 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7726 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7727 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7728 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7729 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7730 | EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge.get())); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7731 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7732 | TestCompletionCallback callback2; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7733 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7734 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 7735 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7736 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7737 | |
| 7738 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7739 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7740 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7741 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7742 | ASSERT_TRUE(response); |
| 7743 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7744 | } |
| 7745 | |
| 7746 | // ------------------------------------------------------------------------ |
| 7747 | |
| 7748 | // Transaction 2: Request another resource in digestive's protection space. |
| 7749 | // This will preemptively add an Authorization header which should have an |
| 7750 | // "nc" value of 2 (as compared to 1 in the first use. |
| 7751 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7752 | HttpRequestInfo request; |
| 7753 | request.method = "GET"; |
| 7754 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 7755 | // protection space as digest. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7756 | request.url = GURL("http://www.example.org/x/y/a/b"); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7757 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7758 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7759 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7760 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7761 | MockWrite( |
| 7762 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 7763 | "Host: www.example.org\r\n" |
| 7764 | "Connection: keep-alive\r\n" |
| 7765 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 7766 | "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " |
| 7767 | "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " |
| 7768 | "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7769 | }; |
| 7770 | |
| 7771 | // Sever accepts the authorization. |
| 7772 | MockRead data_reads1[] = { |
| 7773 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7774 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7775 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7776 | }; |
| 7777 | |
| 7778 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 7779 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7780 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7781 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7782 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7783 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7784 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7785 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7786 | |
| 7787 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7788 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7789 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7790 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7791 | ASSERT_TRUE(response); |
| 7792 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 7793 | } |
| 7794 | } |
| 7795 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7796 | // Test the ResetStateForRestart() private method. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7797 | TEST_F(HttpNetworkTransactionTest, ResetStateForRestart) { |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7798 | // Create a transaction (the dependencies aren't important). |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7799 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7800 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7801 | |
| 7802 | // Setup some state (which we expect ResetStateForRestart() will clear). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7803 | trans.read_buf_ = new IOBuffer(15); |
| 7804 | trans.read_buf_len_ = 15; |
| 7805 | trans.request_headers_.SetHeader("Authorization", "NTLM"); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7806 | |
| 7807 | // Setup state in response_ |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7808 | HttpResponseInfo* response = &trans.response_; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7809 | response->auth_challenge = new AuthChallengeInfo(); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 7810 | response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7811 | response->response_time = base::Time::Now(); |
| 7812 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7813 | |
| 7814 | { // Setup state for response_.vary_data |
| 7815 | HttpRequestInfo request; |
| 7816 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 7817 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 7818 | scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 7819 | request.extra_headers.SetHeader("Foo", "1"); |
| 7820 | request.extra_headers.SetHeader("bar", "23"); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7821 | EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7822 | } |
| 7823 | |
| 7824 | // Cause the above state to be reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7825 | trans.ResetStateForRestart(); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7826 | |
| 7827 | // Verify that the state that needed to be reset, has been reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7828 | EXPECT_FALSE(trans.read_buf_); |
| 7829 | EXPECT_EQ(0, trans.read_buf_len_); |
| 7830 | EXPECT_TRUE(trans.request_headers_.IsEmpty()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7831 | EXPECT_FALSE(response->auth_challenge); |
| 7832 | EXPECT_FALSE(response->headers); |
[email protected] | 34f4094 | 2010-10-04 00:34:04 | [diff] [blame] | 7833 | EXPECT_FALSE(response->was_cached); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 7834 | EXPECT_EQ(0U, response->ssl_info.cert_status); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 7835 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 7836 | } |
| 7837 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7838 | // Test HTTPS connections to a site with a bad certificate |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7839 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7840 | HttpRequestInfo request; |
| 7841 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7842 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7843 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7844 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7845 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7846 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7847 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7848 | MockWrite( |
| 7849 | "GET / HTTP/1.1\r\n" |
| 7850 | "Host: www.example.org\r\n" |
| 7851 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7852 | }; |
| 7853 | |
| 7854 | MockRead data_reads[] = { |
| 7855 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7856 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7857 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7858 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7859 | }; |
| 7860 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 7861 | StaticSocketDataProvider ssl_bad_certificate; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7862 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7863 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7864 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 7865 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7866 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7867 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 7868 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7869 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 7870 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7871 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7872 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7873 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7874 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7875 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7876 | |
| 7877 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7878 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7879 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7880 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7881 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7882 | |
| 7883 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7884 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7885 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7886 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7887 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7888 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7889 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7890 | } |
| 7891 | |
| 7892 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 7893 | // proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7894 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7895 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7896 | |
| 7897 | HttpRequestInfo request; |
| 7898 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7899 | request.url = GURL("https://www.example.org/"); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7900 | |
| 7901 | MockWrite proxy_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7902 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7903 | "Host: www.example.org:443\r\n" |
| 7904 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7905 | }; |
| 7906 | |
| 7907 | MockRead proxy_reads[] = { |
| 7908 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7909 | MockRead(SYNCHRONOUS, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7910 | }; |
| 7911 | |
| 7912 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7913 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7914 | "Host: www.example.org:443\r\n" |
| 7915 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7916 | MockWrite("GET / HTTP/1.1\r\n" |
| 7917 | "Host: www.example.org\r\n" |
| 7918 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7919 | }; |
| 7920 | |
| 7921 | MockRead data_reads[] = { |
| 7922 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 7923 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7924 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7925 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7926 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7927 | }; |
| 7928 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 7929 | StaticSocketDataProvider ssl_bad_certificate( |
| 7930 | proxy_reads, arraysize(proxy_reads), |
| 7931 | proxy_writes, arraysize(proxy_writes)); |
| 7932 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7933 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7934 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 7935 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7936 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7937 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 7938 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7939 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 7940 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7941 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7942 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7943 | |
| 7944 | for (int i = 0; i < 2; i++) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7945 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7946 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7947 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7948 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7949 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7950 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7951 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7952 | |
| 7953 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7954 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7955 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7956 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7957 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7958 | |
| 7959 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7960 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7961 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7962 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7963 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7964 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 7965 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7966 | } |
| 7967 | } |
| 7968 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7969 | |
| 7970 | // Test HTTPS connections to a site, going through an HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7971 | TEST_F(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 7972 | session_deps_.proxy_service = |
| 7973 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 7974 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7975 | session_deps_.net_log = &net_log; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7976 | |
| 7977 | HttpRequestInfo request; |
| 7978 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7979 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7980 | |
| 7981 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7982 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7983 | "Host: www.example.org:443\r\n" |
| 7984 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7985 | MockWrite("GET / HTTP/1.1\r\n" |
| 7986 | "Host: www.example.org\r\n" |
| 7987 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7988 | }; |
| 7989 | |
| 7990 | MockRead data_reads[] = { |
| 7991 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 7992 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7993 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7994 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7995 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 7996 | }; |
| 7997 | |
| 7998 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 7999 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8000 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 8001 | SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8002 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8003 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8004 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 8005 | session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8006 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8007 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8008 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8009 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8010 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8011 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8012 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8013 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8014 | |
| 8015 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8016 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8017 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8018 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8019 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8020 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 8021 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8022 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8023 | EXPECT_EQ(200, response->headers->response_code()); |
| 8024 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8025 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8026 | |
| 8027 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8028 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8029 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8030 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8031 | } |
| 8032 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8033 | // Test an HTTPS Proxy's ability to redirect a CONNECT request |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8034 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8035 | session_deps_.proxy_service = |
| 8036 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8037 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8038 | session_deps_.net_log = &net_log; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8039 | |
| 8040 | HttpRequestInfo request; |
| 8041 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8042 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8043 | |
| 8044 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8045 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8046 | "Host: www.example.org:443\r\n" |
| 8047 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8048 | }; |
| 8049 | |
| 8050 | MockRead data_reads[] = { |
| 8051 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 8052 | MockRead("Location: http://login.example.com/\r\n"), |
| 8053 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8054 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8055 | }; |
| 8056 | |
| 8057 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8058 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8059 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8060 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8061 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8062 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8063 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8064 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8065 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8066 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8067 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8068 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8069 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8070 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8071 | |
| 8072 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8073 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8074 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8075 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8076 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8077 | |
| 8078 | EXPECT_EQ(302, response->headers->response_code()); |
| 8079 | std::string url; |
| 8080 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 8081 | EXPECT_EQ("http://login.example.com/", url); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8082 | |
| 8083 | // In the case of redirects from proxies, HttpNetworkTransaction returns |
| 8084 | // timing for the proxy connection instead of the connection to the host, |
| 8085 | // and no send / receive times. |
| 8086 | // See HttpNetworkTransaction::OnHttpsProxyTunnelResponse. |
| 8087 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8088 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8089 | |
| 8090 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 8091 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8092 | |
| 8093 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 8094 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 8095 | load_timing_info.proxy_resolve_end); |
| 8096 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 8097 | load_timing_info.connect_timing.connect_start); |
| 8098 | ExpectConnectTimingHasTimes( |
| 8099 | load_timing_info.connect_timing, |
| 8100 | CONNECT_TIMING_HAS_DNS_TIMES | CONNECT_TIMING_HAS_SSL_TIMES); |
| 8101 | |
| 8102 | EXPECT_TRUE(load_timing_info.send_start.is_null()); |
| 8103 | EXPECT_TRUE(load_timing_info.send_end.is_null()); |
| 8104 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8105 | } |
| 8106 | |
| 8107 | // Test an HTTPS (SPDY) Proxy's ability to redirect a CONNECT request |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8108 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8109 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8110 | |
| 8111 | HttpRequestInfo request; |
| 8112 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8113 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8114 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8115 | SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8116 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8117 | SpdySerializedFrame goaway( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 8118 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8119 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8120 | CreateMockWrite(conn, 0, SYNCHRONOUS), |
| 8121 | CreateMockWrite(goaway, 2, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8122 | }; |
| 8123 | |
| 8124 | static const char* const kExtraHeaders[] = { |
| 8125 | "location", |
| 8126 | "http://login.example.com/", |
| 8127 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8128 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
bnc | c9f762a | 2016-12-06 20:38:23 | [diff] [blame] | 8129 | "302", kExtraHeaders, arraysize(kExtraHeaders) / 2, 1)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8130 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8131 | CreateMockRead(resp, 1), MockRead(ASYNC, 0, 3), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8132 | }; |
| 8133 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8134 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 8135 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8136 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8137 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8138 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8139 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8140 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8141 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8142 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8143 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8144 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8145 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8146 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8147 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8148 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8149 | |
| 8150 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8151 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8152 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8153 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8154 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8155 | |
| 8156 | EXPECT_EQ(302, response->headers->response_code()); |
| 8157 | std::string url; |
| 8158 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 8159 | EXPECT_EQ("http://login.example.com/", url); |
| 8160 | } |
| 8161 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 8162 | // Test that an HTTPS proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8163 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8164 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8165 | |
| 8166 | HttpRequestInfo request; |
| 8167 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8168 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8169 | |
| 8170 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8171 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8172 | "Host: www.example.org:443\r\n" |
| 8173 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8174 | }; |
| 8175 | |
| 8176 | MockRead data_reads[] = { |
| 8177 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 8178 | MockRead("Content-Length: 23\r\n\r\n"), |
| 8179 | MockRead("The host does not exist"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8180 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8181 | }; |
| 8182 | |
| 8183 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8184 | data_writes, arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8185 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8186 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8187 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8188 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8189 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8190 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8191 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8192 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8193 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8194 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8195 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8196 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8197 | |
| 8198 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8199 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8200 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 8201 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8202 | } |
| 8203 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 8204 | // Test that a SPDY proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8205 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaSpdyProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8206 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8207 | |
| 8208 | HttpRequestInfo request; |
| 8209 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8210 | request.url = GURL("https://www.example.org/"); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8211 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8212 | SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8213 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8214 | SpdySerializedFrame rst( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 8215 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8216 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8217 | CreateMockWrite(conn, 0), CreateMockWrite(rst, 3), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8218 | }; |
| 8219 | |
| 8220 | static const char* const kExtraHeaders[] = { |
| 8221 | "location", |
| 8222 | "http://login.example.com/", |
| 8223 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8224 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
bnc | c9f762a | 2016-12-06 20:38:23 | [diff] [blame] | 8225 | "404", kExtraHeaders, arraysize(kExtraHeaders) / 2, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8226 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 8227 | 1, "The host does not exist", 23, true)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8228 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8229 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8230 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8231 | }; |
| 8232 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8233 | SequencedSocketData data(data_reads, arraysize(data_reads), data_writes, |
| 8234 | arraysize(data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8235 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8236 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8237 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8238 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8239 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8240 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8241 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8242 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8243 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8244 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8245 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8246 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8247 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8248 | |
| 8249 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8250 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8251 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 8252 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8253 | } |
| 8254 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8255 | // Test the request-challenge-retry sequence for basic auth, through |
| 8256 | // a SPDY proxy over a single SPDY session. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8257 | TEST_F(HttpNetworkTransactionTest, BasicAuthSpdyProxy) { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8258 | HttpRequestInfo request; |
| 8259 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8260 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8261 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 8262 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8263 | |
| 8264 | // Configure against https proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8265 | session_deps_.proxy_service = |
| 8266 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8267 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8268 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8269 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8270 | |
| 8271 | // Since we have proxy, should try to establish tunnel. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8272 | SpdySerializedFrame req(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8273 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8274 | SpdySerializedFrame rst( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 8275 | spdy_util_.ConstructSpdyRstStream(1, ERROR_CODE_CANCEL)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 8276 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8277 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8278 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8279 | // be issuing -- the final header line contains the credentials. |
| 8280 | const char* const kAuthCredentials[] = { |
| 8281 | "proxy-authorization", "Basic Zm9vOmJhcg==", |
| 8282 | }; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8283 | SpdySerializedFrame connect2(spdy_util_.ConstructSpdyConnect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 8284 | kAuthCredentials, arraysize(kAuthCredentials) / 2, 3, LOWEST, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8285 | HostPortPair("www.example.org", 443))); |
| 8286 | // fetch https://www.example.org/ via HTTP |
| 8287 | const char get[] = |
| 8288 | "GET / HTTP/1.1\r\n" |
| 8289 | "Host: www.example.org\r\n" |
| 8290 | "Connection: keep-alive\r\n\r\n"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8291 | SpdySerializedFrame wrapped_get( |
| 8292 | spdy_util_.ConstructSpdyDataFrame(3, get, strlen(get), false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8293 | |
| 8294 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8295 | CreateMockWrite(req, 0, ASYNC), CreateMockWrite(rst, 2, ASYNC), |
| 8296 | CreateMockWrite(connect2, 3), CreateMockWrite(wrapped_get, 5), |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8297 | }; |
| 8298 | |
| 8299 | // The proxy responds to the connect with a 407, using a persistent |
| 8300 | // connection. |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 8301 | const char kAuthStatus[] = "407"; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8302 | const char* const kAuthChallenge[] = { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8303 | "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 8304 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8305 | SpdySerializedFrame conn_auth_resp(spdy_util_.ConstructSpdyReplyError( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8306 | kAuthStatus, kAuthChallenge, arraysize(kAuthChallenge) / 2, 1)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8307 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8308 | SpdySerializedFrame conn_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8309 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 8310 | "Content-Length: 5\r\n\r\n"; |
| 8311 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8312 | SpdySerializedFrame wrapped_get_resp( |
| 8313 | spdy_util_.ConstructSpdyDataFrame(3, resp, strlen(resp), false)); |
| 8314 | SpdySerializedFrame wrapped_body( |
| 8315 | spdy_util_.ConstructSpdyDataFrame(3, "hello", 5, false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8316 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8317 | CreateMockRead(conn_auth_resp, 1, ASYNC), |
| 8318 | CreateMockRead(conn_resp, 4, ASYNC), |
| 8319 | CreateMockRead(wrapped_get_resp, 6, ASYNC), |
| 8320 | CreateMockRead(wrapped_body, 7, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8321 | MockRead(ASYNC, OK, 8), // EOF. May or may not be read. |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8322 | }; |
| 8323 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8324 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8325 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8326 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8327 | // Negotiate SPDY to the proxy |
| 8328 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8329 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8330 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8331 | // Vanilla SSL to the server |
| 8332 | SSLSocketDataProvider server(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8333 | session_deps_.socket_factory->AddSSLSocketDataProvider(&server); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8334 | |
| 8335 | TestCompletionCallback callback1; |
| 8336 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8337 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8338 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8339 | |
| 8340 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8341 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8342 | |
| 8343 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8344 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 8345 | TestNetLogEntry::List entries; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8346 | log.GetEntries(&entries); |
| 8347 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 8348 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 8349 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8350 | ExpectLogContainsSomewhere( |
| 8351 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 8352 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 8353 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8354 | |
| 8355 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8356 | ASSERT_TRUE(response); |
| 8357 | ASSERT_TRUE(response->headers); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8358 | EXPECT_EQ(407, response->headers->response_code()); |
| 8359 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8360 | EXPECT_TRUE(response->auth_challenge); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 8361 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8362 | |
| 8363 | TestCompletionCallback callback2; |
| 8364 | |
| 8365 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 8366 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8367 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8368 | |
| 8369 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8370 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8371 | |
| 8372 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8373 | ASSERT_TRUE(response); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8374 | |
| 8375 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8376 | EXPECT_EQ(200, response->headers->response_code()); |
| 8377 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 8378 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8379 | |
| 8380 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8381 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8382 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8383 | LoadTimingInfo load_timing_info; |
| 8384 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8385 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8386 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 8387 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8388 | trans.reset(); |
| 8389 | session->CloseAllConnections(); |
| 8390 | } |
| 8391 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8392 | // Test that an explicitly trusted SPDY proxy can push a resource from an |
| 8393 | // origin that is different from that of its associated resource. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8394 | TEST_F(HttpNetworkTransactionTest, CrossOriginSPDYProxyPush) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8395 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8396 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8397 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 8398 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8399 | HttpRequestInfo request; |
| 8400 | HttpRequestInfo push_request; |
| 8401 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8402 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8403 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8404 | push_request.method = "GET"; |
| 8405 | push_request.url = GURL("http://www.another-origin.com/foo.dat"); |
| 8406 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8407 | // Configure against https proxy server "myproxy:443". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8408 | session_deps_.proxy_service = |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8409 | ProxyService::CreateFixedFromPacResult("HTTPS myproxy:443"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8410 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8411 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8412 | |
inlinechan | 894515af | 2016-12-09 02:40:10 | [diff] [blame] | 8413 | session_deps_.proxy_delegate = std::move(proxy_delegate); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8414 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8415 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8416 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8417 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 8418 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8419 | SpdySerializedFrame stream2_priority( |
| 8420 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8421 | |
| 8422 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8423 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8424 | CreateMockWrite(stream2_priority, 3, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8425 | }; |
| 8426 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8427 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8428 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8429 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8430 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8431 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8432 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 8433 | NULL, 0, 2, 1, "http://www.another-origin.com/foo.dat")); |
[email protected] | 8a0fc82 | 2013-06-27 20:52:43 | [diff] [blame] | 8434 | const char kPushedData[] = "pushed"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8435 | SpdySerializedFrame stream2_body(spdy_util_.ConstructSpdyDataFrame( |
| 8436 | 2, kPushedData, strlen(kPushedData), true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8437 | |
| 8438 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8439 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 8440 | CreateMockRead(stream2_syn, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8441 | CreateMockRead(stream1_body, 4, ASYNC), |
| 8442 | CreateMockRead(stream2_body, 5, ASYNC), |
| 8443 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8444 | }; |
| 8445 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8446 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8447 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8448 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8449 | // Negotiate SPDY to the proxy |
| 8450 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8451 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8452 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8453 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8454 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8455 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8456 | TestCompletionCallback callback; |
| 8457 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8458 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8459 | |
| 8460 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8461 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8462 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8463 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8464 | auto push_trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8465 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8466 | rv = push_trans->Start(&push_request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8467 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8468 | |
| 8469 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8470 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8471 | const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); |
| 8472 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8473 | ASSERT_TRUE(response); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8474 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8475 | |
| 8476 | EXPECT_EQ(200, response->headers->response_code()); |
| 8477 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8478 | |
| 8479 | std::string response_data; |
| 8480 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8481 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8482 | EXPECT_EQ("hello!", response_data); |
| 8483 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8484 | LoadTimingInfo load_timing_info; |
| 8485 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 8486 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8487 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 8488 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8489 | // Verify the pushed stream. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8490 | EXPECT_TRUE(push_response->headers); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8491 | EXPECT_EQ(200, push_response->headers->response_code()); |
| 8492 | |
| 8493 | rv = ReadTransaction(push_trans.get(), &response_data); |
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 | EXPECT_EQ("pushed", response_data); |
| 8496 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8497 | LoadTimingInfo push_load_timing_info; |
| 8498 | EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); |
| 8499 | TestLoadTimingReusedWithPac(push_load_timing_info); |
| 8500 | // The transactions should share a socket ID, despite being for different |
| 8501 | // origins. |
| 8502 | EXPECT_EQ(load_timing_info.socket_log_id, |
| 8503 | push_load_timing_info.socket_log_id); |
| 8504 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 8505 | trans.reset(); |
| 8506 | push_trans.reset(); |
| 8507 | session->CloseAllConnections(); |
| 8508 | } |
| 8509 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8510 | // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8511 | TEST_F(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8512 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8513 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8514 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 8515 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8516 | HttpRequestInfo request; |
| 8517 | |
| 8518 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8519 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8520 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8521 | session_deps_.proxy_service = |
| 8522 | ProxyService::CreateFixed("https://myproxy:443"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8523 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8524 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8525 | |
| 8526 | // Enable cross-origin push. |
inlinechan | 894515af | 2016-12-09 02:40:10 | [diff] [blame] | 8527 | session_deps_.proxy_delegate = std::move(proxy_delegate); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 8528 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8529 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8530 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8531 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 8532 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8533 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8534 | SpdySerializedFrame push_rst( |
diannahu | 9904e27 | 2017-02-03 14:40:08 | [diff] [blame] | 8535 | spdy_util_.ConstructSpdyRstStream(2, ERROR_CODE_REFUSED_STREAM)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8536 | |
| 8537 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8538 | CreateMockWrite(stream1_syn, 0, ASYNC), CreateMockWrite(push_rst, 3), |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8539 | }; |
| 8540 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8541 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8542 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8543 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8544 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8545 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8546 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 8547 | NULL, 0, 2, 1, "https://www.another-origin.com/foo.dat")); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8548 | |
| 8549 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8550 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 8551 | CreateMockRead(stream2_syn, 2, ASYNC), |
| 8552 | CreateMockRead(stream1_body, 4, ASYNC), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 8553 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a hang |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8554 | }; |
| 8555 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8556 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8557 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8558 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8559 | // Negotiate SPDY to the proxy |
| 8560 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8561 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8562 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8563 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8564 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8565 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8566 | TestCompletionCallback callback; |
| 8567 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8568 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8569 | |
| 8570 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8571 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8572 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8573 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8574 | ASSERT_TRUE(response); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8575 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8576 | |
| 8577 | EXPECT_EQ(200, response->headers->response_code()); |
| 8578 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8579 | |
| 8580 | std::string response_data; |
| 8581 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8582 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 8583 | EXPECT_EQ("hello!", response_data); |
| 8584 | |
| 8585 | trans.reset(); |
| 8586 | session->CloseAllConnections(); |
| 8587 | } |
| 8588 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8589 | // Test that an explicitly trusted SPDY proxy can push same-origin HTTPS |
| 8590 | // resources. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8591 | TEST_F(HttpNetworkTransactionTest, SameOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8592 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8593 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 8594 | proxy_delegate->set_trusted_spdy_proxy( |
| 8595 | net::ProxyServer::FromURI("myproxy:70", net::ProxyServer::SCHEME_HTTP)); |
| 8596 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8597 | HttpRequestInfo request; |
| 8598 | |
| 8599 | request.method = "GET"; |
| 8600 | request.url = GURL("http://www.example.org/"); |
| 8601 | |
| 8602 | // Configure against https proxy server "myproxy:70". |
| 8603 | session_deps_.proxy_service = ProxyService::CreateFixed("https://myproxy:70"); |
| 8604 | BoundTestNetLog log; |
| 8605 | session_deps_.net_log = log.bound().net_log(); |
| 8606 | |
| 8607 | // Enable cross-origin push. |
inlinechan | 894515af | 2016-12-09 02:40:10 | [diff] [blame] | 8608 | session_deps_.proxy_delegate = std::move(proxy_delegate); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8609 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8610 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8611 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8612 | SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 8613 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8614 | SpdySerializedFrame stream2_priority( |
| 8615 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8616 | |
| 8617 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8618 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8619 | CreateMockWrite(stream2_priority, 3, ASYNC), |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8620 | }; |
| 8621 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8622 | SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8623 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8624 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8625 | SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
Bence Béky | 096cf05 | 2017-08-08 23:55:33 | [diff] [blame] | 8626 | nullptr, 0, 2, 1, "http://www.example.org/foo.dat")); |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 8627 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8628 | SpdySerializedFrame stream1_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8629 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8630 | SpdySerializedFrame stream2_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 8631 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8632 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8633 | SpdySerializedFrame stream2_body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8634 | |
| 8635 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8636 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 8637 | CreateMockRead(stream2_syn, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 8638 | CreateMockRead(stream1_body, 4, ASYNC), |
| 8639 | CreateMockRead(stream2_body, 5, ASYNC), |
| 8640 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8641 | }; |
| 8642 | |
| 8643 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 8644 | arraysize(spdy_writes)); |
| 8645 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 8646 | // Negotiate SPDY to the proxy |
| 8647 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8648 | proxy.next_proto = kProtoHTTP2; |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8649 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
| 8650 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8651 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8652 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8653 | TestCompletionCallback callback; |
| 8654 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8655 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8656 | |
| 8657 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8658 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8659 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8660 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8661 | ASSERT_TRUE(response); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8662 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8663 | |
| 8664 | EXPECT_EQ(200, response->headers->response_code()); |
| 8665 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 8666 | |
| 8667 | std::string response_data; |
| 8668 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8669 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 8670 | EXPECT_EQ("hello!", response_data); |
| 8671 | |
| 8672 | trans.reset(); |
| 8673 | session->CloseAllConnections(); |
| 8674 | } |
| 8675 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8676 | // Test HTTPS connections to a site with a bad certificate, going through an |
| 8677 | // HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8678 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8679 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8680 | |
| 8681 | HttpRequestInfo request; |
| 8682 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8683 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8684 | |
| 8685 | // Attempt to fetch the URL from a server with a bad cert |
| 8686 | MockWrite bad_cert_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8687 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8688 | "Host: www.example.org:443\r\n" |
| 8689 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8690 | }; |
| 8691 | |
| 8692 | MockRead bad_cert_reads[] = { |
| 8693 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8694 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8695 | }; |
| 8696 | |
| 8697 | // Attempt to fetch the URL with a good cert |
| 8698 | MockWrite good_data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8699 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8700 | "Host: www.example.org:443\r\n" |
| 8701 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 8702 | MockWrite("GET / HTTP/1.1\r\n" |
| 8703 | "Host: www.example.org\r\n" |
| 8704 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8705 | }; |
| 8706 | |
| 8707 | MockRead good_cert_reads[] = { |
| 8708 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 8709 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8710 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8711 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8712 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8713 | }; |
| 8714 | |
| 8715 | StaticSocketDataProvider ssl_bad_certificate( |
| 8716 | bad_cert_reads, arraysize(bad_cert_reads), |
| 8717 | bad_cert_writes, arraysize(bad_cert_writes)); |
| 8718 | StaticSocketDataProvider data(good_cert_reads, arraysize(good_cert_reads), |
| 8719 | good_data_writes, arraysize(good_data_writes)); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8720 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 8721 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8722 | |
| 8723 | // SSL to the proxy, then CONNECT request, then SSL with bad certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8724 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 8725 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 8726 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8727 | |
| 8728 | // SSL to the proxy, then CONNECT request, then valid SSL certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8729 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 8730 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8731 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8732 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8733 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8734 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8735 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8736 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8737 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8738 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8739 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8740 | |
| 8741 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8742 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8743 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8744 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8745 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8746 | |
| 8747 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8748 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8749 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8750 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8751 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8752 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8753 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8754 | } |
| 8755 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8756 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8757 | HttpRequestInfo request; |
| 8758 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8759 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8760 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 8761 | "Chromium Ultra Awesome X Edition"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8762 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8763 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8764 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8765 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8766 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8767 | MockWrite( |
| 8768 | "GET / HTTP/1.1\r\n" |
| 8769 | "Host: www.example.org\r\n" |
| 8770 | "Connection: keep-alive\r\n" |
| 8771 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8772 | }; |
| 8773 | |
| 8774 | // Lastly, the server responds with the actual content. |
| 8775 | MockRead data_reads[] = { |
| 8776 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8777 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8778 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8779 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8780 | }; |
| 8781 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8782 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8783 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8784 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8785 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8786 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8787 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8788 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8789 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8790 | |
| 8791 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8792 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8793 | } |
| 8794 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8795 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8796 | HttpRequestInfo request; |
| 8797 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8798 | request.url = GURL("https://www.example.org/"); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8799 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 8800 | "Chromium Ultra Awesome X Edition"); |
| 8801 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 8802 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8803 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8804 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8805 | |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8806 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8807 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8808 | "Host: www.example.org:443\r\n" |
| 8809 | "Proxy-Connection: keep-alive\r\n" |
| 8810 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8811 | }; |
| 8812 | MockRead data_reads[] = { |
| 8813 | // Return an error, so the transaction stops here (this test isn't |
| 8814 | // interested in the rest). |
| 8815 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 8816 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8817 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 8818 | }; |
| 8819 | |
| 8820 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8821 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8822 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8823 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8824 | TestCompletionCallback callback; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8825 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8826 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8827 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8828 | |
| 8829 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8830 | EXPECT_THAT(rv, IsOk()); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 8831 | } |
| 8832 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8833 | TEST_F(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8834 | HttpRequestInfo request; |
| 8835 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8836 | request.url = GURL("http://www.example.org/"); |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 8837 | request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 8838 | "http://the.previous.site.com/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8839 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8840 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8841 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8842 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8843 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8844 | MockWrite( |
| 8845 | "GET / HTTP/1.1\r\n" |
| 8846 | "Host: www.example.org\r\n" |
| 8847 | "Connection: keep-alive\r\n" |
| 8848 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8849 | }; |
| 8850 | |
| 8851 | // Lastly, the server responds with the actual content. |
| 8852 | MockRead data_reads[] = { |
| 8853 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8854 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8855 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8856 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8857 | }; |
| 8858 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8859 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8860 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8861 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8862 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8863 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8864 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8865 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8866 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8867 | |
| 8868 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8869 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8870 | } |
| 8871 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8872 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8873 | HttpRequestInfo request; |
| 8874 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8875 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8876 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8877 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8878 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8879 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8880 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8881 | MockWrite( |
| 8882 | "POST / HTTP/1.1\r\n" |
| 8883 | "Host: www.example.org\r\n" |
| 8884 | "Connection: keep-alive\r\n" |
| 8885 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8886 | }; |
| 8887 | |
| 8888 | // Lastly, the server responds with the actual content. |
| 8889 | MockRead data_reads[] = { |
| 8890 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8891 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8892 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8893 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8894 | }; |
| 8895 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8896 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8897 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8898 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8899 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8900 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8901 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8902 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8903 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8904 | |
| 8905 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8906 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8907 | } |
| 8908 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8909 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8910 | HttpRequestInfo request; |
| 8911 | request.method = "PUT"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8912 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8913 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8914 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8915 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8916 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8917 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8918 | MockWrite( |
| 8919 | "PUT / HTTP/1.1\r\n" |
| 8920 | "Host: www.example.org\r\n" |
| 8921 | "Connection: keep-alive\r\n" |
| 8922 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8923 | }; |
| 8924 | |
| 8925 | // Lastly, the server responds with the actual content. |
| 8926 | MockRead data_reads[] = { |
| 8927 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8928 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8929 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8930 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8931 | }; |
| 8932 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8933 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8934 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8935 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8936 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8937 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8938 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8939 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8940 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8941 | |
| 8942 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8943 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8944 | } |
| 8945 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8946 | TEST_F(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8947 | HttpRequestInfo request; |
| 8948 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8949 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8950 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8951 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8952 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8953 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8954 | MockWrite data_writes[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 8955 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 8956 | "Host: www.example.org\r\n" |
| 8957 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8958 | }; |
| 8959 | |
| 8960 | // Lastly, the server responds with the actual content. |
| 8961 | MockRead data_reads[] = { |
| 8962 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8963 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8964 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8965 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8966 | }; |
| 8967 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 8968 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 8969 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8970 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8971 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8972 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8973 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8974 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8975 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8976 | |
| 8977 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8978 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8979 | } |
| 8980 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8981 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8982 | HttpRequestInfo request; |
| 8983 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8984 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8985 | request.load_flags = LOAD_BYPASS_CACHE; |
| 8986 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8987 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8988 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8989 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8990 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8991 | MockWrite( |
| 8992 | "GET / HTTP/1.1\r\n" |
| 8993 | "Host: www.example.org\r\n" |
| 8994 | "Connection: keep-alive\r\n" |
| 8995 | "Pragma: no-cache\r\n" |
| 8996 | "Cache-Control: no-cache\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8997 | }; |
| 8998 | |
| 8999 | // Lastly, the server responds with the actual content. |
| 9000 | MockRead data_reads[] = { |
| 9001 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9002 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9003 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9004 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9005 | }; |
| 9006 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9007 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9008 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9009 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9010 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9011 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9012 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9013 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9014 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9015 | |
| 9016 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9017 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9018 | } |
| 9019 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9020 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlValidateCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9021 | HttpRequestInfo request; |
| 9022 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9023 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9024 | request.load_flags = LOAD_VALIDATE_CACHE; |
| 9025 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9026 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9027 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9028 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9029 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9030 | MockWrite( |
| 9031 | "GET / HTTP/1.1\r\n" |
| 9032 | "Host: www.example.org\r\n" |
| 9033 | "Connection: keep-alive\r\n" |
| 9034 | "Cache-Control: max-age=0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9035 | }; |
| 9036 | |
| 9037 | // Lastly, the server responds with the actual content. |
| 9038 | MockRead data_reads[] = { |
| 9039 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9040 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9041 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9042 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9043 | }; |
| 9044 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9045 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9046 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9047 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9048 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9049 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9050 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9051 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9052 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9053 | |
| 9054 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9055 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9056 | } |
| 9057 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9058 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9059 | HttpRequestInfo request; |
| 9060 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9061 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 9062 | request.extra_headers.SetHeader("FooHeader", "Bar"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9063 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9064 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9065 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9066 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9067 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9068 | MockWrite( |
| 9069 | "GET / HTTP/1.1\r\n" |
| 9070 | "Host: www.example.org\r\n" |
| 9071 | "Connection: keep-alive\r\n" |
| 9072 | "FooHeader: Bar\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9073 | }; |
| 9074 | |
| 9075 | // Lastly, the server responds with the actual content. |
| 9076 | MockRead data_reads[] = { |
| 9077 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9078 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9079 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9080 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9081 | }; |
| 9082 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9083 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9084 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9085 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9086 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9087 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9088 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9089 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9090 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9091 | |
| 9092 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9093 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9094 | } |
| 9095 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9096 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9097 | HttpRequestInfo request; |
| 9098 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9099 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 9100 | request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 9101 | request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 9102 | request.extra_headers.SetHeader("FoO", "bar"); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9103 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9104 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9105 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9106 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9107 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9108 | MockWrite( |
| 9109 | "GET / HTTP/1.1\r\n" |
| 9110 | "Host: www.example.org\r\n" |
| 9111 | "Connection: keep-alive\r\n" |
| 9112 | "referer: www.foo.com\r\n" |
| 9113 | "hEllo: Kitty\r\n" |
| 9114 | "FoO: bar\r\n\r\n"), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9115 | }; |
| 9116 | |
| 9117 | // Lastly, the server responds with the actual content. |
| 9118 | MockRead data_reads[] = { |
| 9119 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9120 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9121 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9122 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9123 | }; |
| 9124 | |
| 9125 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9126 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9127 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9128 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9129 | TestCompletionCallback callback; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9130 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9131 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9132 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9133 | |
| 9134 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9135 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9136 | } |
| 9137 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9138 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9139 | HttpRequestInfo request; |
| 9140 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9141 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9142 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9143 | session_deps_.proxy_service = |
| 9144 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9145 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9146 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9147 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9148 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9149 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9150 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9151 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 9152 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 9153 | |
| 9154 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9155 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 9156 | MockWrite( |
| 9157 | "GET / HTTP/1.1\r\n" |
| 9158 | "Host: www.example.org\r\n" |
| 9159 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9160 | |
| 9161 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9162 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9163 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9164 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9165 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9166 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9167 | }; |
| 9168 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9169 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9170 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9171 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9172 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9173 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9174 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9175 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9176 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9177 | |
| 9178 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9179 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9180 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9181 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9182 | ASSERT_TRUE(response); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9183 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9184 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9185 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9186 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9187 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9188 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 9189 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9190 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9191 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9192 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9193 | EXPECT_EQ("Payload", response_text); |
| 9194 | } |
| 9195 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9196 | TEST_F(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9197 | HttpRequestInfo request; |
| 9198 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9199 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9200 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9201 | session_deps_.proxy_service = |
| 9202 | ProxyService::CreateFixedFromPacResult("SOCKS myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9203 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9204 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9205 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9206 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9207 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9208 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9209 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 9210 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 9211 | |
| 9212 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9213 | MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), |
| 9214 | arraysize(write_buffer)), |
| 9215 | MockWrite( |
| 9216 | "GET / HTTP/1.1\r\n" |
| 9217 | "Host: www.example.org\r\n" |
| 9218 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9219 | |
| 9220 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 9221 | MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), |
| 9222 | arraysize(read_buffer)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9223 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9224 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9225 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9226 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9227 | }; |
| 9228 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9229 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9230 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9231 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9232 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9233 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9234 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9235 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9236 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9237 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9238 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9239 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9240 | |
| 9241 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9242 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9243 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9244 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9245 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9246 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9247 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 9248 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9249 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9250 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9251 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9252 | |
| 9253 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9254 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9255 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9256 | EXPECT_EQ("Payload", response_text); |
| 9257 | } |
| 9258 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9259 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9260 | HttpRequestInfo request; |
| 9261 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9262 | request.url = GURL("http://www.example.org/"); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9263 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9264 | session_deps_.proxy_service = |
| 9265 | ProxyService::CreateFixed("socks4://myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9266 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9267 | session_deps_.net_log = &net_log; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9268 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9269 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9270 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9271 | |
| 9272 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 9273 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 9274 | |
| 9275 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9276 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 9277 | MockWrite( |
| 9278 | "GET / HTTP/1.1\r\n" |
| 9279 | "Host: www.example.org\r\n" |
| 9280 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9281 | |
| 9282 | MockRead data_reads[] = { |
| 9283 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
| 9284 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9285 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9286 | MockRead("Payload"), |
| 9287 | MockRead(SYNCHRONOUS, OK) |
| 9288 | }; |
| 9289 | |
| 9290 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9291 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9292 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9293 | |
| 9294 | TestCompletionCallback callback; |
| 9295 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9296 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9297 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9298 | |
| 9299 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9300 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9301 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9302 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9303 | ASSERT_TRUE(response); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9304 | |
| 9305 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9306 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9307 | TestLoadTimingNotReused(load_timing_info, |
| 9308 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 9309 | |
| 9310 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9311 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9312 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9313 | EXPECT_EQ("Payload", response_text); |
| 9314 | } |
| 9315 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9316 | TEST_F(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9317 | HttpRequestInfo request; |
| 9318 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9319 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9320 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9321 | session_deps_.proxy_service = |
| 9322 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9323 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9324 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9325 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9326 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9327 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9328 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9329 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 9330 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9331 | const char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9332 | 0x05, // Version |
| 9333 | 0x01, // Command (CONNECT) |
| 9334 | 0x00, // Reserved. |
| 9335 | 0x03, // Address type (DOMAINNAME). |
| 9336 | 0x0F, // Length of domain (15) |
| 9337 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 9338 | '.', 'o', 'r', 'g', 0x00, 0x50, // 16-bit port (80) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9339 | }; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9340 | const char kSOCKS5OkResponse[] = |
| 9341 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 9342 | |
| 9343 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9344 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 9345 | MockWrite(ASYNC, kSOCKS5OkRequest, arraysize(kSOCKS5OkRequest)), |
| 9346 | MockWrite( |
| 9347 | "GET / HTTP/1.1\r\n" |
| 9348 | "Host: www.example.org\r\n" |
| 9349 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9350 | |
| 9351 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 9352 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 9353 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9354 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9355 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9356 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9357 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9358 | }; |
| 9359 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9360 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9361 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9362 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9363 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9364 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9365 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9366 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9367 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9368 | |
| 9369 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9370 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9371 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9372 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9373 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9374 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9375 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9376 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9377 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9378 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9379 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 9380 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9381 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9382 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9383 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9384 | EXPECT_EQ("Payload", response_text); |
| 9385 | } |
| 9386 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9387 | TEST_F(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9388 | HttpRequestInfo request; |
| 9389 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9390 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9391 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9392 | session_deps_.proxy_service = |
| 9393 | ProxyService::CreateFixedFromPacResult("SOCKS5 myproxy:1080"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9394 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9395 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9396 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9397 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9398 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9399 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9400 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 9401 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9402 | const unsigned char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9403 | 0x05, // Version |
| 9404 | 0x01, // Command (CONNECT) |
| 9405 | 0x00, // Reserved. |
| 9406 | 0x03, // Address type (DOMAINNAME). |
| 9407 | 0x0F, // Length of domain (15) |
| 9408 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 9409 | '.', 'o', 'r', 'g', 0x01, 0xBB, // 16-bit port (443) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 9410 | }; |
| 9411 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9412 | const char kSOCKS5OkResponse[] = |
| 9413 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 9414 | |
| 9415 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9416 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 9417 | MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
| 9418 | arraysize(kSOCKS5OkRequest)), |
| 9419 | MockWrite( |
| 9420 | "GET / HTTP/1.1\r\n" |
| 9421 | "Host: www.example.org\r\n" |
| 9422 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9423 | |
| 9424 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 9425 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 9426 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9427 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9428 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9429 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9430 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9431 | }; |
| 9432 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9433 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 9434 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9435 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9436 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9437 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9438 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9439 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9440 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9441 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9442 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9443 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9444 | |
| 9445 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9446 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9447 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9448 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9449 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9450 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9451 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9452 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9453 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9454 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9455 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 9456 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9457 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9458 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9459 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9460 | EXPECT_EQ("Payload", response_text); |
| 9461 | } |
| 9462 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9463 | namespace { |
| 9464 | |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9465 | // Tests that for connection endpoints the group names are correctly set. |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9466 | |
| 9467 | struct GroupNameTest { |
| 9468 | std::string proxy_server; |
| 9469 | std::string url; |
| 9470 | std::string expected_group_name; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9471 | bool ssl; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9472 | }; |
| 9473 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9474 | std::unique_ptr<HttpNetworkSession> SetupSessionForGroupNameTests( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9475 | SpdySessionDependencies* session_deps_) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9476 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9477 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 9478 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 9479 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 9480 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 9481 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 9482 | http_server_properties->SetHttp2AlternativeService( |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9483 | url::SchemeHostPort("https", "host.with.alternate", 443), |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 9484 | alternative_service, expiration); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9485 | |
| 9486 | return session; |
| 9487 | } |
| 9488 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9489 | int GroupNameTransactionHelper(const std::string& url, |
| 9490 | HttpNetworkSession* session) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9491 | HttpRequestInfo request; |
| 9492 | request.method = "GET"; |
| 9493 | request.url = GURL(url); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9494 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9495 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9496 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9497 | TestCompletionCallback callback; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9498 | |
| 9499 | // We do not complete this request, the dtor will clean the transaction up. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9500 | return trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9501 | } |
| 9502 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 9503 | } // namespace |
| 9504 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9505 | TEST_F(HttpNetworkTransactionTest, GroupNameForDirectConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9506 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9507 | { |
| 9508 | "", // unused |
| 9509 | "http://www.example.org/direct", |
| 9510 | "www.example.org:80", |
| 9511 | false, |
| 9512 | }, |
| 9513 | { |
| 9514 | "", // unused |
| 9515 | "http://[2001:1418:13:1::25]/direct", |
| 9516 | "[2001:1418:13:1::25]:80", |
| 9517 | false, |
| 9518 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9519 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9520 | // SSL Tests |
| 9521 | { |
| 9522 | "", // unused |
| 9523 | "https://www.example.org/direct_ssl", |
| 9524 | "ssl/www.example.org:443", |
| 9525 | true, |
| 9526 | }, |
| 9527 | { |
| 9528 | "", // unused |
| 9529 | "https://[2001:1418:13:1::25]/direct", |
| 9530 | "ssl/[2001:1418:13:1::25]:443", |
| 9531 | true, |
| 9532 | }, |
| 9533 | { |
| 9534 | "", // unused |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9535 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9536 | "ssl/host.with.alternate:443", |
| 9537 | true, |
| 9538 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9539 | }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 9540 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 9541 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9542 | session_deps_.proxy_service = |
| 9543 | ProxyService::CreateFixed(tests[i].proxy_server); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9544 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 9545 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9546 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9547 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9548 | CaptureGroupNameTransportSocketPool* transport_conn_pool = |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9549 | new CaptureGroupNameTransportSocketPool(nullptr, nullptr); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9550 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9551 | new CaptureGroupNameSSLSocketPool(nullptr, nullptr); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9552 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 9553 | mock_pool_manager->SetTransportSocketPool(transport_conn_pool); |
| 9554 | mock_pool_manager->SetSSLSocketPool(ssl_conn_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 9555 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9556 | |
| 9557 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9558 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9559 | if (tests[i].ssl) |
| 9560 | EXPECT_EQ(tests[i].expected_group_name, |
| 9561 | ssl_conn_pool->last_group_name_received()); |
| 9562 | else |
| 9563 | EXPECT_EQ(tests[i].expected_group_name, |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 9564 | transport_conn_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9565 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9566 | } |
| 9567 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9568 | TEST_F(HttpNetworkTransactionTest, GroupNameForHTTPProxyConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9569 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9570 | { |
| 9571 | "http_proxy", |
| 9572 | "http://www.example.org/http_proxy_normal", |
| 9573 | "www.example.org:80", |
| 9574 | false, |
| 9575 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9576 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9577 | // SSL Tests |
| 9578 | { |
| 9579 | "http_proxy", |
| 9580 | "https://www.example.org/http_connect_ssl", |
| 9581 | "ssl/www.example.org:443", |
| 9582 | true, |
| 9583 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 9584 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9585 | { |
| 9586 | "http_proxy", |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9587 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9588 | "ssl/host.with.alternate:443", |
| 9589 | true, |
| 9590 | }, |
[email protected] | 4549925 | 2013-01-23 17:12:56 | [diff] [blame] | 9591 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9592 | { |
| 9593 | "http_proxy", |
| 9594 | "ftp://ftp.google.com/http_proxy_normal", |
| 9595 | "ftp/ftp.google.com:21", |
| 9596 | false, |
| 9597 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9598 | }; |
| 9599 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 9600 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9601 | session_deps_.proxy_service = |
| 9602 | ProxyService::CreateFixed(tests[i].proxy_server); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9603 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 9604 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9605 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9606 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9607 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9608 | HostPortPair proxy_host("http_proxy", 80); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9609 | CaptureGroupNameHttpProxySocketPool* http_proxy_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9610 | new CaptureGroupNameHttpProxySocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9611 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9612 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9613 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
avi | adef344 | 2016-10-03 18:50:39 | [diff] [blame] | 9614 | mock_pool_manager->SetSocketPoolForHTTPProxy( |
| 9615 | proxy_host, base::WrapUnique(http_proxy_pool)); |
| 9616 | mock_pool_manager->SetSocketPoolForSSLWithProxy( |
| 9617 | proxy_host, base::WrapUnique(ssl_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 9618 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9619 | |
| 9620 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9621 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9622 | if (tests[i].ssl) |
| 9623 | EXPECT_EQ(tests[i].expected_group_name, |
| 9624 | ssl_conn_pool->last_group_name_received()); |
| 9625 | else |
| 9626 | EXPECT_EQ(tests[i].expected_group_name, |
| 9627 | http_proxy_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9628 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9629 | } |
| 9630 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9631 | TEST_F(HttpNetworkTransactionTest, GroupNameForSOCKSConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9632 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9633 | { |
| 9634 | "socks4://socks_proxy:1080", |
| 9635 | "http://www.example.org/socks4_direct", |
| 9636 | "socks4/www.example.org:80", |
| 9637 | false, |
| 9638 | }, |
| 9639 | { |
| 9640 | "socks5://socks_proxy:1080", |
| 9641 | "http://www.example.org/socks5_direct", |
| 9642 | "socks5/www.example.org:80", |
| 9643 | false, |
| 9644 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9645 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9646 | // SSL Tests |
| 9647 | { |
| 9648 | "socks4://socks_proxy:1080", |
| 9649 | "https://www.example.org/socks4_ssl", |
| 9650 | "socks4/ssl/www.example.org:443", |
| 9651 | true, |
| 9652 | }, |
| 9653 | { |
| 9654 | "socks5://socks_proxy:1080", |
| 9655 | "https://www.example.org/socks5_ssl", |
| 9656 | "socks5/ssl/www.example.org:443", |
| 9657 | true, |
| 9658 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 9659 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9660 | { |
| 9661 | "socks4://socks_proxy:1080", |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 9662 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9663 | "socks4/ssl/host.with.alternate:443", |
| 9664 | true, |
| 9665 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9666 | }; |
| 9667 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 9668 | for (size_t i = 0; i < arraysize(tests); ++i) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9669 | session_deps_.proxy_service = |
| 9670 | ProxyService::CreateFixed(tests[i].proxy_server); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9671 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 9672 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 9673 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9674 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9675 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9676 | HostPortPair proxy_host("socks_proxy", 1080); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9677 | CaptureGroupNameSOCKSSocketPool* socks_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9678 | new CaptureGroupNameSOCKSSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 9679 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 9680 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9681 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
avi | adef344 | 2016-10-03 18:50:39 | [diff] [blame] | 9682 | mock_pool_manager->SetSocketPoolForSOCKSProxy( |
| 9683 | proxy_host, base::WrapUnique(socks_conn_pool)); |
| 9684 | mock_pool_manager->SetSocketPoolForSSLWithProxy( |
| 9685 | proxy_host, base::WrapUnique(ssl_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 9686 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9687 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9688 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9689 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 9690 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 9691 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 9692 | if (tests[i].ssl) |
| 9693 | EXPECT_EQ(tests[i].expected_group_name, |
| 9694 | ssl_conn_pool->last_group_name_received()); |
| 9695 | else |
| 9696 | EXPECT_EQ(tests[i].expected_group_name, |
| 9697 | socks_conn_pool->last_group_name_received()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 9698 | } |
| 9699 | } |
| 9700 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9701 | TEST_F(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9702 | HttpRequestInfo request; |
| 9703 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9704 | request.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9705 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9706 | session_deps_.proxy_service = |
| 9707 | ProxyService::CreateFixed("myproxy:70;foobar:80"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 9708 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 9709 | // This simulates failure resolving all hostnames; that means we will fail |
| 9710 | // connecting to both proxies (myproxy:70 and foobar:80). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9711 | session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 9712 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9713 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9714 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9715 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9716 | TestCompletionCallback callback; |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9717 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9718 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9719 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9720 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9721 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9722 | EXPECT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 9723 | } |
| 9724 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9725 | // Base test to make sure that when the load flags for a request specify to |
| 9726 | // bypass the cache, the DNS cache is not used. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 9727 | void HttpNetworkTransactionTest::BypassHostCacheOnRefreshHelper( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9728 | int load_flags) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9729 | // Issue a request, asking to bypass the cache(s). |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9730 | HttpRequestInfo request_info; |
| 9731 | request_info.method = "GET"; |
| 9732 | request_info.load_flags = load_flags; |
| 9733 | request_info.url = GURL("http://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9734 | |
[email protected] | a2c2fb9 | 2009-07-18 07:31:04 | [diff] [blame] | 9735 | // Select a host resolver that does caching. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9736 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 9737 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9738 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9739 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9740 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9741 | // 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] | 9742 | AddressList addrlist; |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 9743 | TestCompletionCallback callback; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9744 | std::unique_ptr<HostResolver::Request> request1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9745 | int rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9746 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9747 | DEFAULT_PRIORITY, &addrlist, callback.callback(), &request1, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9748 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9749 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 9750 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9751 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9752 | |
| 9753 | // Verify that it was added to host cache, by doing a subsequent async lookup |
| 9754 | // and confirming it completes synchronously. |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9755 | std::unique_ptr<HostResolver::Request> request2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9756 | rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9757 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 9758 | DEFAULT_PRIORITY, &addrlist, callback.callback(), &request2, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9759 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9760 | ASSERT_THAT(rv, IsOk()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9761 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9762 | // 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] | 9763 | // we can tell if the next lookup hit the cache, or the "network". |
| 9764 | // (cache --> success, "network" --> failure). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9765 | session_deps_.host_resolver->rules()->AddSimulatedFailure("www.example.org"); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9766 | |
| 9767 | // Connect up a mock socket which will fail with ERR_UNEXPECTED during the |
| 9768 | // 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] | 9769 | MockRead data_reads[] = { MockRead(SYNCHRONOUS, ERR_UNEXPECTED) }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9770 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9771 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9772 | |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9773 | // Run the request. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9774 | rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9775 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9776 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9777 | |
| 9778 | // If we bypassed the cache, we would have gotten a failure while resolving |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9779 | // "www.example.org". |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9780 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 9781 | } |
| 9782 | |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9783 | // There are multiple load flags that should trigger the host cache bypass. |
| 9784 | // Test each in isolation: |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9785 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh1) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9786 | BypassHostCacheOnRefreshHelper(LOAD_BYPASS_CACHE); |
| 9787 | } |
| 9788 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9789 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh2) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9790 | BypassHostCacheOnRefreshHelper(LOAD_VALIDATE_CACHE); |
| 9791 | } |
| 9792 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9793 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh3) { |
[email protected] | 685af59 | 2010-05-11 19:31:24 | [diff] [blame] | 9794 | BypassHostCacheOnRefreshHelper(LOAD_DISABLE_CACHE); |
| 9795 | } |
| 9796 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9797 | // Make sure we can handle an error when writing the request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9798 | TEST_F(HttpNetworkTransactionTest, RequestWriteError) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9799 | HttpRequestInfo request; |
| 9800 | request.method = "GET"; |
| 9801 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9802 | |
| 9803 | MockWrite write_failure[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9804 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9805 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9806 | StaticSocketDataProvider data(NULL, 0, |
| 9807 | write_failure, arraysize(write_failure)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9808 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9809 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9810 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9811 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9812 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9813 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9814 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9815 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9816 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9817 | |
| 9818 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9819 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9820 | |
| 9821 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9822 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9823 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9824 | } |
| 9825 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9826 | // Check that a connection closed after the start of the headers finishes ok. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9827 | TEST_F(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9828 | HttpRequestInfo request; |
| 9829 | request.method = "GET"; |
| 9830 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9831 | |
| 9832 | MockRead data_reads[] = { |
| 9833 | MockRead("HTTP/1."), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9834 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9835 | }; |
| 9836 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9837 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9838 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9839 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9840 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9841 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9842 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9843 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9844 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9845 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9846 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9847 | |
| 9848 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9849 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9850 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9851 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9852 | ASSERT_TRUE(response); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9853 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9854 | EXPECT_TRUE(response->headers); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9855 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 9856 | |
| 9857 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9858 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9859 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9860 | EXPECT_EQ("", response_data); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9861 | |
| 9862 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9863 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 9864 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9865 | } |
| 9866 | |
| 9867 | // Make sure that a dropped connection while draining the body for auth |
| 9868 | // restart does the right thing. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9869 | TEST_F(HttpNetworkTransactionTest, DrainResetOK) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9870 | HttpRequestInfo request; |
| 9871 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9872 | request.url = GURL("http://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9873 | |
| 9874 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9875 | MockWrite( |
| 9876 | "GET / HTTP/1.1\r\n" |
| 9877 | "Host: www.example.org\r\n" |
| 9878 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9879 | }; |
| 9880 | |
| 9881 | MockRead data_reads1[] = { |
| 9882 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 9883 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9884 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9885 | MockRead("Content-Length: 14\r\n\r\n"), |
| 9886 | MockRead("Unauth"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9887 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9888 | }; |
| 9889 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9890 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 9891 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9892 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9893 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9894 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9895 | // be issuing -- the final header line contains the credentials. |
| 9896 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9897 | MockWrite( |
| 9898 | "GET / HTTP/1.1\r\n" |
| 9899 | "Host: www.example.org\r\n" |
| 9900 | "Connection: keep-alive\r\n" |
| 9901 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9902 | }; |
| 9903 | |
| 9904 | // Lastly, the server responds with the actual content. |
| 9905 | MockRead data_reads2[] = { |
| 9906 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9907 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9908 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9909 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9910 | }; |
| 9911 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9912 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 9913 | data_writes2, arraysize(data_writes2)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9914 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9915 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9916 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9917 | TestCompletionCallback callback1; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9918 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9919 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 9920 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9921 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9922 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9923 | |
| 9924 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9925 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9926 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9927 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9928 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9929 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9930 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9931 | TestCompletionCallback callback2; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9932 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9933 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9934 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9935 | |
| 9936 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9937 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9938 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9939 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9940 | ASSERT_TRUE(response); |
| 9941 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9942 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9943 | } |
| 9944 | |
| 9945 | // Test HTTPS connections going through a proxy that sends extra data. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9946 | TEST_F(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 9947 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9948 | |
| 9949 | HttpRequestInfo request; |
| 9950 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9951 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9952 | |
| 9953 | MockRead proxy_reads[] = { |
| 9954 | MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9955 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9956 | }; |
| 9957 | |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 9958 | StaticSocketDataProvider data(proxy_reads, arraysize(proxy_reads), NULL, 0); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9959 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9960 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9961 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9962 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9963 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9964 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9965 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9966 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9967 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9968 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9969 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9970 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9971 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9972 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9973 | |
| 9974 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9975 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9976 | } |
| 9977 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9978 | TEST_F(HttpNetworkTransactionTest, LargeContentLengthThenClose) { |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9979 | HttpRequestInfo request; |
| 9980 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9981 | request.url = GURL("http://www.example.org/"); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9982 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9983 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9984 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9985 | |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 9986 | MockRead data_reads[] = { |
| 9987 | 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] | 9988 | MockRead(SYNCHRONOUS, OK), |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 9989 | }; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9990 | |
| 9991 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9992 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9993 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9994 | TestCompletionCallback callback; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9995 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9996 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9997 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 9998 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9999 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10000 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10001 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10002 | ASSERT_TRUE(response); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10003 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10004 | EXPECT_TRUE(response->headers); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10005 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 10006 | |
| 10007 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10008 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10009 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 10010 | } |
| 10011 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10012 | TEST_F(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 10013 | base::FilePath temp_file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 10014 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path)); |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 10015 | const uint64_t kFakeSize = 100000; // file is actually blank |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 10016 | UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 10017 | overriding_content_length(kFakeSize); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10018 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10019 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10020 | element_readers.push_back(std::make_unique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 10021 | base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 10022 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 10023 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10024 | |
| 10025 | HttpRequestInfo request; |
| 10026 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10027 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10028 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10029 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10030 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10031 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10032 | |
| 10033 | MockRead data_reads[] = { |
| 10034 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 10035 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10036 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10037 | }; |
[email protected] | 31a2bfe | 2010-02-09 08:03:39 | [diff] [blame] | 10038 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10039 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10040 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10041 | TestCompletionCallback callback; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10042 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10043 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10044 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10045 | |
| 10046 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10047 | EXPECT_THAT(rv, IsError(ERR_UPLOAD_FILE_CHANGED)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10048 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10049 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10050 | ASSERT_TRUE(response); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10051 | |
maksim.sisov | e869bf5 | 2016-06-23 17:11:52 | [diff] [blame] | 10052 | EXPECT_FALSE(response->headers); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10053 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 10054 | base::DeleteFile(temp_file_path, false); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10055 | } |
| 10056 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10057 | TEST_F(HttpNetworkTransactionTest, UploadUnreadableFile) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 10058 | base::FilePath temp_file; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 10059 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10060 | std::string temp_file_content("Unreadable file."); |
lazyboy | 8df84fc | 2017-04-12 02:12:48 | [diff] [blame] | 10061 | ASSERT_EQ(static_cast<int>(temp_file_content.length()), |
| 10062 | base::WriteFile(temp_file, temp_file_content.c_str(), |
| 10063 | temp_file_content.length())); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 10064 | ASSERT_TRUE(base::MakeFileUnreadable(temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10065 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10066 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10067 | element_readers.push_back(std::make_unique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 10068 | base::ThreadTaskRunnerHandle::Get().get(), temp_file, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 10069 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 10070 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10071 | |
| 10072 | HttpRequestInfo request; |
| 10073 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10074 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10075 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10076 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 10077 | // If we try to upload an unreadable file, the transaction should fail. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10078 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10079 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10080 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 10081 | StaticSocketDataProvider data(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10082 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10083 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10084 | TestCompletionCallback callback; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10085 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10086 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10087 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10088 | |
| 10089 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10090 | EXPECT_THAT(rv, IsError(ERR_ACCESS_DENIED)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10091 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 10092 | base::DeleteFile(temp_file, false); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10093 | } |
| 10094 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10095 | TEST_F(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10096 | class FakeUploadElementReader : public UploadElementReader { |
| 10097 | public: |
| 10098 | FakeUploadElementReader() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10099 | ~FakeUploadElementReader() override {} |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10100 | |
| 10101 | const CompletionCallback& callback() const { return callback_; } |
| 10102 | |
| 10103 | // UploadElementReader overrides: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10104 | int Init(const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10105 | callback_ = callback; |
| 10106 | return ERR_IO_PENDING; |
| 10107 | } |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 10108 | uint64_t GetContentLength() const override { return 0; } |
| 10109 | uint64_t BytesRemaining() const override { return 0; } |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10110 | int Read(IOBuffer* buf, |
| 10111 | int buf_length, |
| 10112 | const CompletionCallback& callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10113 | return ERR_FAILED; |
| 10114 | } |
| 10115 | |
| 10116 | private: |
| 10117 | CompletionCallback callback_; |
| 10118 | }; |
| 10119 | |
| 10120 | FakeUploadElementReader* fake_reader = new FakeUploadElementReader; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10121 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
| 10122 | element_readers.push_back(base::WrapUnique(fake_reader)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 10123 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10124 | |
| 10125 | HttpRequestInfo request; |
| 10126 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10127 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10128 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10129 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10130 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10131 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10132 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10133 | |
| 10134 | StaticSocketDataProvider data; |
| 10135 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10136 | |
| 10137 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10138 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10139 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 10140 | base::RunLoop().RunUntilIdle(); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10141 | |
| 10142 | // Transaction is pending on request body initialization. |
| 10143 | ASSERT_FALSE(fake_reader->callback().is_null()); |
| 10144 | |
| 10145 | // Return Init()'s result after the transaction gets destroyed. |
| 10146 | trans.reset(); |
| 10147 | fake_reader->callback().Run(OK); // Should not crash. |
| 10148 | } |
| 10149 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10150 | // Tests that changes to Auth realms are treated like auth rejections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10151 | TEST_F(HttpNetworkTransactionTest, ChangeAuthRealms) { |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10152 | HttpRequestInfo request; |
| 10153 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10154 | request.url = GURL("http://www.example.org/"); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10155 | |
| 10156 | // First transaction will request a resource and receive a Basic challenge |
| 10157 | // with realm="first_realm". |
| 10158 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10159 | MockWrite( |
| 10160 | "GET / HTTP/1.1\r\n" |
| 10161 | "Host: www.example.org\r\n" |
| 10162 | "Connection: keep-alive\r\n" |
| 10163 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10164 | }; |
| 10165 | MockRead data_reads1[] = { |
| 10166 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 10167 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 10168 | "\r\n"), |
| 10169 | }; |
| 10170 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10171 | // After calling trans.RestartWithAuth(), provide an Authentication header |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10172 | // for first_realm. The server will reject and provide a challenge with |
| 10173 | // second_realm. |
| 10174 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10175 | MockWrite( |
| 10176 | "GET / HTTP/1.1\r\n" |
| 10177 | "Host: www.example.org\r\n" |
| 10178 | "Connection: keep-alive\r\n" |
| 10179 | "Authorization: Basic Zmlyc3Q6YmF6\r\n" |
| 10180 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10181 | }; |
| 10182 | MockRead data_reads2[] = { |
| 10183 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 10184 | "WWW-Authenticate: Basic realm=\"second_realm\"\r\n" |
| 10185 | "\r\n"), |
| 10186 | }; |
| 10187 | |
| 10188 | // This again fails, and goes back to first_realm. Make sure that the |
| 10189 | // entry is removed from cache. |
| 10190 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10191 | MockWrite( |
| 10192 | "GET / HTTP/1.1\r\n" |
| 10193 | "Host: www.example.org\r\n" |
| 10194 | "Connection: keep-alive\r\n" |
| 10195 | "Authorization: Basic c2Vjb25kOmZvdQ==\r\n" |
| 10196 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10197 | }; |
| 10198 | MockRead data_reads3[] = { |
| 10199 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 10200 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 10201 | "\r\n"), |
| 10202 | }; |
| 10203 | |
| 10204 | // Try one last time (with the correct password) and get the resource. |
| 10205 | MockWrite data_writes4[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10206 | MockWrite( |
| 10207 | "GET / HTTP/1.1\r\n" |
| 10208 | "Host: www.example.org\r\n" |
| 10209 | "Connection: keep-alive\r\n" |
| 10210 | "Authorization: Basic Zmlyc3Q6YmFy\r\n" |
| 10211 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10212 | }; |
| 10213 | MockRead data_reads4[] = { |
| 10214 | MockRead("HTTP/1.1 200 OK\r\n" |
| 10215 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10216 | "Content-Length: 5\r\n" |
| 10217 | "\r\n" |
| 10218 | "hello"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10219 | }; |
| 10220 | |
| 10221 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 10222 | data_writes1, arraysize(data_writes1)); |
| 10223 | StaticSocketDataProvider data2(data_reads2, arraysize(data_reads2), |
| 10224 | data_writes2, arraysize(data_writes2)); |
| 10225 | StaticSocketDataProvider data3(data_reads3, arraysize(data_reads3), |
| 10226 | data_writes3, arraysize(data_writes3)); |
| 10227 | StaticSocketDataProvider data4(data_reads4, arraysize(data_reads4), |
| 10228 | data_writes4, arraysize(data_writes4)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10229 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 10230 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 10231 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 10232 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10233 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10234 | TestCompletionCallback callback1; |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10235 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10236 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10237 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10238 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10239 | // Issue the first request with Authorize headers. There should be a |
| 10240 | // password prompt for first_realm waiting to be filled in after the |
| 10241 | // transaction completes. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10242 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10243 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10244 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10245 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10246 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10247 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10248 | const AuthChallengeInfo* challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10249 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10250 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10251 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10252 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 10253 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10254 | |
| 10255 | // Issue the second request with an incorrect password. There should be a |
| 10256 | // password prompt for second_realm waiting to be filled in after the |
| 10257 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10258 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10259 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBaz), |
| 10260 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10261 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10262 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10263 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10264 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10265 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10266 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10267 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10268 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10269 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10270 | EXPECT_EQ("second_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 10271 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10272 | |
| 10273 | // Issue the third request with another incorrect password. There should be |
| 10274 | // a password prompt for first_realm waiting to be filled in. If the password |
| 10275 | // prompt is not present, it indicates that the HttpAuthCacheEntry for |
| 10276 | // first_realm was not correctly removed. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10277 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10278 | rv = trans.RestartWithAuth(AuthCredentials(kSecond, kFou), |
| 10279 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10280 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10281 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10282 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10283 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10284 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10285 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10286 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10287 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10288 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10289 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 10290 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10291 | |
| 10292 | // Issue the fourth request with the correct password and username. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10293 | TestCompletionCallback callback4; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10294 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBar), |
| 10295 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10296 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10297 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10298 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10299 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10300 | ASSERT_TRUE(response); |
| 10301 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10302 | } |
| 10303 | |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 10304 | // Regression test for https://crbug.com/754395. |
| 10305 | TEST_F(HttpNetworkTransactionTest, IgnoreAltSvcWithInvalidCert) { |
| 10306 | MockRead data_reads[] = { |
| 10307 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10308 | MockRead(kAlternativeServiceHttpHeader), |
| 10309 | MockRead("\r\n"), |
| 10310 | MockRead("hello world"), |
| 10311 | MockRead(SYNCHRONOUS, OK), |
| 10312 | }; |
| 10313 | |
| 10314 | HttpRequestInfo request; |
| 10315 | request.method = "GET"; |
| 10316 | request.url = GURL("https://www.example.org/"); |
| 10317 | |
| 10318 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 10319 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10320 | |
| 10321 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10322 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 10323 | ASSERT_TRUE(ssl.cert); |
| 10324 | ssl.cert_status = CERT_STATUS_COMMON_NAME_INVALID; |
| 10325 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10326 | |
| 10327 | TestCompletionCallback callback; |
| 10328 | |
| 10329 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10330 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 10331 | |
| 10332 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 10333 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10334 | |
| 10335 | url::SchemeHostPort test_server(request.url); |
| 10336 | HttpServerProperties* http_server_properties = |
| 10337 | session->http_server_properties(); |
| 10338 | EXPECT_TRUE( |
| 10339 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
| 10340 | |
| 10341 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 10342 | |
| 10343 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 10344 | ASSERT_TRUE(response); |
| 10345 | ASSERT_TRUE(response->headers); |
| 10346 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10347 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 10348 | EXPECT_FALSE(response->was_alpn_negotiated); |
| 10349 | |
| 10350 | std::string response_data; |
| 10351 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 10352 | EXPECT_EQ("hello world", response_data); |
| 10353 | |
| 10354 | EXPECT_TRUE( |
| 10355 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
| 10356 | } |
| 10357 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10358 | TEST_F(HttpNetworkTransactionTest, HonorAlternativeServiceHeader) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10359 | MockRead data_reads[] = { |
| 10360 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10361 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10362 | MockRead("\r\n"), |
| 10363 | MockRead("hello world"), |
| 10364 | MockRead(SYNCHRONOUS, OK), |
| 10365 | }; |
| 10366 | |
| 10367 | HttpRequestInfo request; |
| 10368 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10369 | request.url = GURL("https://www.example.org/"); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10370 | |
| 10371 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10372 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10373 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10374 | SSLSocketDataProvider ssl(ASYNC, OK); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 10375 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 10376 | ASSERT_TRUE(ssl.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10377 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10378 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10379 | TestCompletionCallback callback; |
| 10380 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10381 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10382 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10383 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10384 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10385 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10386 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10387 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10388 | HttpServerProperties* http_server_properties = |
| 10389 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10390 | EXPECT_TRUE( |
| 10391 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10392 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10393 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10394 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10395 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10396 | ASSERT_TRUE(response); |
| 10397 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10398 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10399 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10400 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10401 | |
| 10402 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10403 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10404 | EXPECT_EQ("hello world", response_data); |
| 10405 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10406 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 10407 | http_server_properties->GetAlternativeServiceInfos(test_server); |
| 10408 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 10409 | AlternativeService alternative_service(kProtoHTTP2, "mail.example.org", 443); |
| 10410 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 10411 | alternative_service_info_vector[0].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10412 | } |
| 10413 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10414 | // Regression test for https://crbug.com/615497. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10415 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10416 | DoNotParseAlternativeServiceHeaderOnInsecureRequest) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10417 | MockRead data_reads[] = { |
| 10418 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10419 | MockRead(kAlternativeServiceHttpHeader), |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10420 | MockRead("\r\n"), |
| 10421 | MockRead("hello world"), |
| 10422 | MockRead(SYNCHRONOUS, OK), |
| 10423 | }; |
| 10424 | |
| 10425 | HttpRequestInfo request; |
| 10426 | request.method = "GET"; |
| 10427 | request.url = GURL("http://www.example.org/"); |
| 10428 | request.load_flags = 0; |
| 10429 | |
| 10430 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 10431 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10432 | |
| 10433 | TestCompletionCallback callback; |
| 10434 | |
| 10435 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10436 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10437 | |
| 10438 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10439 | HttpServerProperties* http_server_properties = |
| 10440 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10441 | EXPECT_TRUE( |
| 10442 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10443 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10444 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10445 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10446 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10447 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10448 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10449 | ASSERT_TRUE(response); |
| 10450 | ASSERT_TRUE(response->headers); |
| 10451 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10452 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10453 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10454 | |
| 10455 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10456 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10457 | EXPECT_EQ("hello world", response_data); |
| 10458 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10459 | EXPECT_TRUE( |
| 10460 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10461 | } |
| 10462 | |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 10463 | // HTTP/2 Alternative Services should be disabled by default. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10464 | // TODO(bnc): Remove when https://crbug.com/615413 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10465 | TEST_F(HttpNetworkTransactionTest, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10466 | DisableHTTP2AlternativeServicesWithDifferentHost) { |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 10467 | session_deps_.enable_http2_alternative_service = false; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10468 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10469 | HttpRequestInfo request; |
| 10470 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10471 | request.url = GURL("https://www.example.org/"); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10472 | request.load_flags = 0; |
| 10473 | |
| 10474 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10475 | StaticSocketDataProvider first_data; |
| 10476 | first_data.set_connect_data(mock_connect); |
| 10477 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10478 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10479 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10480 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10481 | |
| 10482 | MockRead data_reads[] = { |
| 10483 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 10484 | MockRead(ASYNC, OK), |
| 10485 | }; |
| 10486 | StaticSocketDataProvider second_data(data_reads, arraysize(data_reads), NULL, |
| 10487 | 0); |
| 10488 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 10489 | |
| 10490 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10491 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10492 | HttpServerProperties* http_server_properties = |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10493 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10494 | AlternativeService alternative_service(kProtoHTTP2, "different.example.org", |
| 10495 | 444); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10496 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10497 | http_server_properties->SetHttp2AlternativeService( |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10498 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 10499 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10500 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10501 | TestCompletionCallback callback; |
| 10502 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10503 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10504 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10505 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 10506 | } |
| 10507 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10508 | // Regression test for https://crbug.com/615497: |
| 10509 | // Alternative Services should be disabled for http origin. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10510 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10511 | DisableAlternativeServicesForInsecureOrigin) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10512 | HttpRequestInfo request; |
| 10513 | request.method = "GET"; |
| 10514 | request.url = GURL("http://www.example.org/"); |
| 10515 | request.load_flags = 0; |
| 10516 | |
| 10517 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10518 | StaticSocketDataProvider first_data; |
| 10519 | first_data.set_connect_data(mock_connect); |
| 10520 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
| 10521 | |
| 10522 | MockRead data_reads[] = { |
| 10523 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 10524 | MockRead(ASYNC, OK), |
| 10525 | }; |
| 10526 | StaticSocketDataProvider second_data(data_reads, arraysize(data_reads), NULL, |
| 10527 | 0); |
| 10528 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 10529 | |
| 10530 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10531 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10532 | HttpServerProperties* http_server_properties = |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10533 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10534 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10535 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10536 | http_server_properties->SetHttp2AlternativeService( |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10537 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 10538 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10539 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10540 | TestCompletionCallback callback; |
| 10541 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10542 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10543 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10544 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 10545 | } |
| 10546 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10547 | TEST_F(HttpNetworkTransactionTest, ClearAlternativeServices) { |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10548 | // Set an alternative service for origin. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10549 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10550 | HttpServerProperties* http_server_properties = |
| 10551 | session->http_server_properties(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10552 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10553 | AlternativeService alternative_service(kProtoQUIC, "", 80); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10554 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10555 | http_server_properties->SetQuicAlternativeService( |
| 10556 | test_server, alternative_service, expiration, |
| 10557 | session->params().quic_supported_versions); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10558 | EXPECT_EQ( |
| 10559 | 1u, |
| 10560 | http_server_properties->GetAlternativeServiceInfos(test_server).size()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10561 | |
| 10562 | // Send a clear header. |
| 10563 | MockRead data_reads[] = { |
| 10564 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 10565 | MockRead("Alt-Svc: clear\r\n"), |
| 10566 | MockRead("\r\n"), |
| 10567 | MockRead("hello world"), |
| 10568 | MockRead(SYNCHRONOUS, OK), |
| 10569 | }; |
| 10570 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), nullptr, 0); |
| 10571 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10572 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10573 | SSLSocketDataProvider ssl(ASYNC, OK); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 10574 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 10575 | ASSERT_TRUE(ssl.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10576 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10577 | |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10578 | HttpRequestInfo request; |
| 10579 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10580 | request.url = GURL("https://www.example.org/"); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10581 | |
| 10582 | TestCompletionCallback callback; |
| 10583 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10584 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10585 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10586 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10587 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10588 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10589 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10590 | ASSERT_TRUE(response); |
| 10591 | ASSERT_TRUE(response->headers); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10592 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10593 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10594 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10595 | |
| 10596 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10597 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10598 | EXPECT_EQ("hello world", response_data); |
| 10599 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10600 | EXPECT_TRUE( |
| 10601 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 10602 | } |
| 10603 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10604 | TEST_F(HttpNetworkTransactionTest, HonorMultipleAlternativeServiceHeaders) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10605 | MockRead data_reads[] = { |
| 10606 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 10607 | MockRead("Alt-Svc: h2=\"www.example.com:443\","), |
| 10608 | MockRead("h2=\":1234\"\r\n\r\n"), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10609 | MockRead("hello world"), |
| 10610 | MockRead(SYNCHRONOUS, OK), |
| 10611 | }; |
| 10612 | |
| 10613 | HttpRequestInfo request; |
| 10614 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10615 | request.url = GURL("https://www.example.org/"); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10616 | |
| 10617 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10618 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10619 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10620 | SSLSocketDataProvider ssl(ASYNC, OK); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 10621 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 10622 | ASSERT_TRUE(ssl.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10623 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10624 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10625 | TestCompletionCallback callback; |
| 10626 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10627 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10628 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10629 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10630 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10631 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10632 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10633 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10634 | HttpServerProperties* http_server_properties = |
| 10635 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10636 | EXPECT_TRUE( |
| 10637 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10638 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10639 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10640 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10641 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10642 | ASSERT_TRUE(response); |
| 10643 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10644 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10645 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 10646 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10647 | |
| 10648 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10649 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10650 | EXPECT_EQ("hello world", response_data); |
| 10651 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10652 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 10653 | http_server_properties->GetAlternativeServiceInfos(test_server); |
| 10654 | ASSERT_EQ(2u, alternative_service_info_vector.size()); |
| 10655 | |
| 10656 | AlternativeService alternative_service(kProtoHTTP2, "www.example.com", 443); |
| 10657 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 10658 | alternative_service_info_vector[0].alternative_service()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10659 | AlternativeService alternative_service_2(kProtoHTTP2, "www.example.org", |
| 10660 | 1234); |
| 10661 | EXPECT_EQ(alternative_service_2, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 10662 | alternative_service_info_vector[1].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 10663 | } |
| 10664 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10665 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10666 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10667 | HostPortPair alternative("alternative.example.org", 443); |
| 10668 | std::string origin_url = "https://origin.example.org:443"; |
| 10669 | std::string alternative_url = "https://alternative.example.org:443"; |
| 10670 | |
| 10671 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 10672 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10673 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10674 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10675 | |
| 10676 | // HTTP/1.1 data for request. |
| 10677 | MockWrite http_writes[] = { |
| 10678 | MockWrite("GET / HTTP/1.1\r\n" |
| 10679 | "Host: alternative.example.org\r\n" |
| 10680 | "Connection: keep-alive\r\n\r\n"), |
| 10681 | }; |
| 10682 | |
| 10683 | MockRead http_reads[] = { |
| 10684 | MockRead("HTTP/1.1 200 OK\r\n" |
| 10685 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10686 | "Content-Length: 40\r\n\r\n" |
| 10687 | "first HTTP/1.1 response from alternative"), |
| 10688 | }; |
| 10689 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 10690 | http_writes, arraysize(http_writes)); |
| 10691 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 10692 | |
| 10693 | StaticSocketDataProvider data_refused; |
| 10694 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 10695 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 10696 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10697 | // Set up a QUIC alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10698 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10699 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10700 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10701 | AlternativeService alternative_service(kProtoQUIC, alternative); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10702 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10703 | http_server_properties->SetQuicAlternativeService( |
| 10704 | server, alternative_service, expiration, |
| 10705 | HttpNetworkSession::Params().quic_supported_versions); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10706 | // Mark the QUIC alternative service as broken. |
| 10707 | http_server_properties->MarkAlternativeServiceBroken(alternative_service); |
| 10708 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10709 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 10710 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10711 | request.method = "GET"; |
| 10712 | request.url = GURL(origin_url); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10713 | TestCompletionCallback callback; |
| 10714 | NetErrorDetails details; |
| 10715 | EXPECT_FALSE(details.quic_broken); |
| 10716 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10717 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10718 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10719 | EXPECT_TRUE(details.quic_broken); |
| 10720 | } |
| 10721 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10722 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicNotBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10723 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10724 | HostPortPair alternative1("alternative1.example.org", 443); |
| 10725 | HostPortPair alternative2("alternative2.example.org", 443); |
| 10726 | std::string origin_url = "https://origin.example.org:443"; |
| 10727 | std::string alternative_url1 = "https://alternative1.example.org:443"; |
| 10728 | std::string alternative_url2 = "https://alternative2.example.org:443"; |
| 10729 | |
| 10730 | // Negotiate HTTP/1.1 with alternative1.example.org. |
| 10731 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10732 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10733 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10734 | |
| 10735 | // HTTP/1.1 data for request. |
| 10736 | MockWrite http_writes[] = { |
| 10737 | MockWrite("GET / HTTP/1.1\r\n" |
| 10738 | "Host: alternative1.example.org\r\n" |
| 10739 | "Connection: keep-alive\r\n\r\n"), |
| 10740 | }; |
| 10741 | |
| 10742 | MockRead http_reads[] = { |
| 10743 | MockRead("HTTP/1.1 200 OK\r\n" |
| 10744 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 10745 | "Content-Length: 40\r\n\r\n" |
| 10746 | "first HTTP/1.1 response from alternative1"), |
| 10747 | }; |
| 10748 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 10749 | http_writes, arraysize(http_writes)); |
| 10750 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 10751 | |
| 10752 | StaticSocketDataProvider data_refused; |
| 10753 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 10754 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 10755 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10756 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10757 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10758 | session->http_server_properties(); |
| 10759 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10760 | // Set up two QUIC alternative services for server. |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10761 | AlternativeServiceInfoVector alternative_service_info_vector; |
| 10762 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 10763 | |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10764 | AlternativeService alternative_service1(kProtoQUIC, alternative1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10765 | alternative_service_info_vector.push_back( |
| 10766 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 10767 | alternative_service1, expiration, |
| 10768 | session->params().quic_supported_versions)); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10769 | AlternativeService alternative_service2(kProtoQUIC, alternative2); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10770 | alternative_service_info_vector.push_back( |
| 10771 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 10772 | alternative_service2, expiration, |
| 10773 | session->params().quic_supported_versions)); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10774 | |
| 10775 | http_server_properties->SetAlternativeServices( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10776 | server, alternative_service_info_vector); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10777 | |
| 10778 | // Mark one of the QUIC alternative service as broken. |
| 10779 | http_server_properties->MarkAlternativeServiceBroken(alternative_service1); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10780 | EXPECT_EQ(2u, |
| 10781 | http_server_properties->GetAlternativeServiceInfos(server).size()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10782 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10783 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 10784 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10785 | request.method = "GET"; |
| 10786 | request.url = GURL(origin_url); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10787 | TestCompletionCallback callback; |
| 10788 | NetErrorDetails details; |
| 10789 | EXPECT_FALSE(details.quic_broken); |
| 10790 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10791 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10792 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 10793 | EXPECT_FALSE(details.quic_broken); |
| 10794 | } |
| 10795 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10796 | TEST_F(HttpNetworkTransactionTest, MarkBrokenAlternateProtocolAndFallback) { |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10797 | HttpRequestInfo request; |
| 10798 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10799 | request.url = GURL("https://www.example.org/"); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10800 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10801 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10802 | StaticSocketDataProvider first_data; |
| 10803 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10804 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10805 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10806 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10807 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10808 | |
| 10809 | MockRead data_reads[] = { |
| 10810 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10811 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10812 | MockRead(ASYNC, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10813 | }; |
| 10814 | StaticSocketDataProvider second_data( |
| 10815 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10816 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10817 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10818 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10819 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10820 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10821 | session->http_server_properties(); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10822 | const url::SchemeHostPort server(request.url); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10823 | // Port must be < 1024, or the header will be ignored (since initial port was |
| 10824 | // port 80 (another restricted port). |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10825 | // Port is ignored by MockConnect anyway. |
| 10826 | const AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 10827 | 666); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10828 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10829 | http_server_properties->SetHttp2AlternativeService( |
| 10830 | server, alternative_service, expiration); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10831 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10832 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10833 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10834 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10835 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10836 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10837 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10838 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10839 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10840 | ASSERT_TRUE(response); |
| 10841 | ASSERT_TRUE(response->headers); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10842 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 10843 | |
| 10844 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10845 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10846 | EXPECT_EQ("hello world", response_data); |
| 10847 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10848 | const AlternativeServiceInfoVector alternative_service_info_vector = |
| 10849 | http_server_properties->GetAlternativeServiceInfos(server); |
| 10850 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 10851 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 10852 | alternative_service_info_vector[0].alternative_service()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 10853 | EXPECT_TRUE( |
| 10854 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 10855 | } |
| 10856 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10857 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10858 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10859 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10860 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10861 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedBlocked) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10862 | HttpRequestInfo restricted_port_request; |
| 10863 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10864 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10865 | restricted_port_request.load_flags = 0; |
| 10866 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10867 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10868 | StaticSocketDataProvider first_data; |
| 10869 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10870 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10871 | |
| 10872 | MockRead data_reads[] = { |
| 10873 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10874 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10875 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10876 | }; |
| 10877 | StaticSocketDataProvider second_data( |
| 10878 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10879 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10880 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10881 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10882 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10883 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10884 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10885 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10886 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10887 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10888 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10889 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 10890 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10891 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10892 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10893 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10894 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10895 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10896 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10897 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10898 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10899 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 10900 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10901 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10902 | // Invalid change to unrestricted port should fail. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10903 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_REFUSED)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10904 | } |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10905 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10906 | // Ensure that we are allowed to redirect traffic via an alternate protocol to |
| 10907 | // an unrestricted (port >= 1024) when the original traffic was on a restricted |
| 10908 | // port (port < 1024) if we set |enable_user_alternate_protocol_ports|. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10909 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedPermitted) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10910 | session_deps_.enable_user_alternate_protocol_ports = true; |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10911 | |
| 10912 | HttpRequestInfo restricted_port_request; |
| 10913 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10914 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10915 | restricted_port_request.load_flags = 0; |
| 10916 | |
| 10917 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 10918 | StaticSocketDataProvider first_data; |
| 10919 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10920 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10921 | |
| 10922 | MockRead data_reads[] = { |
| 10923 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10924 | MockRead("hello world"), |
| 10925 | MockRead(ASYNC, OK), |
| 10926 | }; |
| 10927 | StaticSocketDataProvider second_data( |
| 10928 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10929 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10930 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10931 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10932 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10933 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10934 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10935 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10936 | HttpServerProperties* http_server_properties = |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10937 | session->http_server_properties(); |
| 10938 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10939 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 10940 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10941 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10942 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10943 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10944 | expiration); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10945 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10946 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10947 | TestCompletionCallback callback; |
| 10948 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10949 | EXPECT_EQ(ERR_IO_PENDING, |
| 10950 | trans.Start(&restricted_port_request, callback.callback(), |
| 10951 | NetLogWithSource())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 10952 | // Change to unrestricted port should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10953 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10954 | } |
| 10955 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 10956 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 10957 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 10958 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 10959 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10960 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedAllowed) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10961 | HttpRequestInfo restricted_port_request; |
| 10962 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10963 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10964 | restricted_port_request.load_flags = 0; |
| 10965 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 10966 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10967 | StaticSocketDataProvider first_data; |
| 10968 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10969 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10970 | |
| 10971 | MockRead data_reads[] = { |
| 10972 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 10973 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10974 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10975 | }; |
| 10976 | StaticSocketDataProvider second_data( |
| 10977 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10978 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10979 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10980 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 10981 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10982 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10983 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10984 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10985 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10986 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10987 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10988 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 10989 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10990 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10991 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10992 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 10993 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10994 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10995 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10996 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 10997 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10998 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 10999 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11000 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11001 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11002 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11003 | } |
| 11004 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11005 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 11006 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 11007 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 11008 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11009 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed1) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11010 | HttpRequestInfo unrestricted_port_request; |
| 11011 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11012 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11013 | unrestricted_port_request.load_flags = 0; |
| 11014 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11015 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11016 | StaticSocketDataProvider first_data; |
| 11017 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11018 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11019 | |
| 11020 | MockRead data_reads[] = { |
| 11021 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11022 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11023 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11024 | }; |
| 11025 | StaticSocketDataProvider second_data( |
| 11026 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11027 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11028 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11029 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11030 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11031 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11032 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11033 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11034 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11035 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11036 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11037 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11038 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11039 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11040 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11041 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11042 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11043 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11044 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11045 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11046 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11047 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11048 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11049 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11050 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11051 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11052 | } |
| 11053 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11054 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 11055 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 11056 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 11057 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11058 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed2) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11059 | HttpRequestInfo unrestricted_port_request; |
| 11060 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11061 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11062 | unrestricted_port_request.load_flags = 0; |
| 11063 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11064 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11065 | StaticSocketDataProvider first_data; |
| 11066 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11067 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11068 | |
| 11069 | MockRead data_reads[] = { |
| 11070 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11071 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11072 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11073 | }; |
| 11074 | StaticSocketDataProvider second_data( |
| 11075 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11076 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11077 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11078 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 11079 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11080 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11081 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11082 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11083 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11084 | session->http_server_properties(); |
bnc | 0bbb0262 | 2015-07-23 10:06:22 | [diff] [blame] | 11085 | const int kUnrestrictedAlternatePort = 1025; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11086 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11087 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11088 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11089 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11090 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11091 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11092 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11093 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11094 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11095 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11096 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11097 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11098 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11099 | // Valid change to an unrestricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11100 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11101 | } |
| 11102 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11103 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 11104 | // to an unsafe port, and that we resume the second HttpStreamFactoryImpl::Job |
| 11105 | // once the alternate protocol request fails. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11106 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) { |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11107 | HttpRequestInfo request; |
| 11108 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11109 | request.url = GURL("http://www.example.org/"); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11110 | |
| 11111 | // The alternate protocol request will error out before we attempt to connect, |
| 11112 | // so only the standard HTTP request will try to connect. |
| 11113 | MockRead data_reads[] = { |
| 11114 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11115 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11116 | MockRead(ASYNC, OK), |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11117 | }; |
| 11118 | StaticSocketDataProvider data( |
| 11119 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11120 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11121 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11122 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11123 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11124 | HttpServerProperties* http_server_properties = |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11125 | session->http_server_properties(); |
| 11126 | const int kUnsafePort = 7; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11127 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11128 | kUnsafePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11129 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11130 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11131 | url::SchemeHostPort(request.url), alternative_service, expiration); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11132 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11133 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11134 | TestCompletionCallback callback; |
| 11135 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11136 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11137 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11138 | // The HTTP request should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11139 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11140 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11141 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11142 | ASSERT_TRUE(response); |
| 11143 | ASSERT_TRUE(response->headers); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11144 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11145 | |
| 11146 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11147 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11148 | EXPECT_EQ("hello world", response_data); |
| 11149 | } |
| 11150 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11151 | TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11152 | HttpRequestInfo request; |
| 11153 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11154 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11155 | |
| 11156 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11157 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11158 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11159 | MockRead("\r\n"), |
| 11160 | MockRead("hello world"), |
| 11161 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11162 | MockRead(ASYNC, OK)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11163 | |
| 11164 | StaticSocketDataProvider first_transaction( |
| 11165 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11166 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11167 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11168 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11169 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11170 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11171 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11172 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11173 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11174 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11175 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11176 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 11177 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11178 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11179 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11180 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11181 | }; |
| 11182 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11183 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11184 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11185 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11186 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11187 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11188 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 11189 | NULL, 0, NULL, 0); |
| 11190 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 11191 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11192 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11193 | &hanging_non_alternate_protocol_socket); |
| 11194 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11195 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11196 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11197 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11198 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11199 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11200 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11201 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11202 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11203 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11204 | |
| 11205 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11206 | ASSERT_TRUE(response); |
| 11207 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11208 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11209 | |
| 11210 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11211 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11212 | EXPECT_EQ("hello world", response_data); |
| 11213 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11214 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11215 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11216 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11217 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11218 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11219 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11220 | |
| 11221 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11222 | ASSERT_TRUE(response); |
| 11223 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11224 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11225 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11226 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11227 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11228 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11229 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11230 | } |
| 11231 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11232 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11233 | HttpRequestInfo request; |
| 11234 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11235 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11236 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11237 | // First transaction receives Alt-Svc header over HTTP/1.1. |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11238 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11239 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11240 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11241 | MockRead("\r\n"), |
| 11242 | MockRead("hello world"), |
| 11243 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11244 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11245 | }; |
| 11246 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11247 | StaticSocketDataProvider http11_data(data_reads, arraysize(data_reads), NULL, |
| 11248 | 0); |
| 11249 | session_deps_.socket_factory->AddSocketDataProvider(&http11_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11250 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11251 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 11252 | ssl_http11.cert = ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11253 | ASSERT_TRUE(ssl_http11.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11254 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
| 11255 | |
| 11256 | // Second transaction starts an alternative and a non-alternative Job. |
| 11257 | // Both sockets hang. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11258 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 11259 | StaticSocketDataProvider hanging_socket1(NULL, 0, NULL, 0); |
| 11260 | hanging_socket1.set_connect_data(never_finishing_connect); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 11261 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket1); |
| 11262 | |
| 11263 | StaticSocketDataProvider hanging_socket2(NULL, 0, NULL, 0); |
| 11264 | hanging_socket2.set_connect_data(never_finishing_connect); |
| 11265 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket2); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11266 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11267 | // Third transaction starts an alternative and a non-alternative job. |
| 11268 | // The non-alternative job hangs, but the alternative one succeeds. |
| 11269 | // The second transaction, still pending, binds to this socket. |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11270 | SpdySerializedFrame req1( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11271 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11272 | SpdySerializedFrame req2( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11273 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 3, LOWEST)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11274 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11275 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 1), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11276 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 11277 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11278 | SpdySerializedFrame data1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 11279 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11280 | SpdySerializedFrame data2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11281 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11282 | CreateMockRead(resp1, 2), CreateMockRead(data1, 3), |
| 11283 | CreateMockRead(resp2, 4), CreateMockRead(data2, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11284 | MockRead(ASYNC, 0, 6), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11285 | }; |
| 11286 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11287 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11288 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11289 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11290 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11291 | AddSSLSocketData(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11292 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 11293 | StaticSocketDataProvider hanging_socket3(NULL, 0, NULL, 0); |
| 11294 | hanging_socket3.set_connect_data(never_finishing_connect); |
| 11295 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket3); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11296 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11297 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11298 | TestCompletionCallback callback1; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11299 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11300 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11301 | int rv = trans1.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11302 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11303 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11304 | |
| 11305 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11306 | ASSERT_TRUE(response); |
| 11307 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11308 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11309 | |
| 11310 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11311 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11312 | EXPECT_EQ("hello world", response_data); |
| 11313 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11314 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11315 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11316 | rv = trans2.Start(&request, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11317 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11318 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11319 | TestCompletionCallback callback3; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 11320 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11321 | rv = trans3.Start(&request, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11322 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11323 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11324 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
| 11325 | EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11326 | |
| 11327 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11328 | ASSERT_TRUE(response); |
| 11329 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11330 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11331 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11332 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11333 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11334 | EXPECT_EQ("hello!", response_data); |
| 11335 | |
| 11336 | response = trans3.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11337 | ASSERT_TRUE(response); |
| 11338 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11339 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11340 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11341 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11342 | ASSERT_THAT(ReadTransaction(&trans3, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11343 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11344 | } |
| 11345 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11346 | TEST_F(HttpNetworkTransactionTest, StallAlternativeServiceForNpnSpdy) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11347 | HttpRequestInfo request; |
| 11348 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11349 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11350 | |
| 11351 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11352 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11353 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11354 | MockRead("\r\n"), |
| 11355 | MockRead("hello world"), |
| 11356 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11357 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11358 | }; |
| 11359 | |
| 11360 | StaticSocketDataProvider first_transaction( |
| 11361 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11362 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11363 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11364 | SSLSocketDataProvider ssl(ASYNC, OK); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 11365 | ssl.cert = ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11366 | ASSERT_TRUE(ssl.cert); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11367 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11368 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11369 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11370 | StaticSocketDataProvider hanging_alternate_protocol_socket( |
| 11371 | NULL, 0, NULL, 0); |
| 11372 | hanging_alternate_protocol_socket.set_connect_data( |
| 11373 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11374 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11375 | &hanging_alternate_protocol_socket); |
| 11376 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11377 | // 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] | 11378 | StaticSocketDataProvider second_transaction(data_reads, arraysize(data_reads), |
| 11379 | NULL, 0); |
| 11380 | session_deps_.socket_factory->AddSocketDataProvider(&second_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11381 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11382 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11383 | TestCompletionCallback callback; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11384 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11385 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11386 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11387 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11388 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11389 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11390 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11391 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11392 | |
| 11393 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11394 | ASSERT_TRUE(response); |
| 11395 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11396 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11397 | |
| 11398 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11399 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11400 | EXPECT_EQ("hello world", response_data); |
| 11401 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11402 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11403 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11404 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11405 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11406 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11407 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11408 | |
| 11409 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11410 | ASSERT_TRUE(response); |
| 11411 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11412 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11413 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11414 | EXPECT_FALSE(response->was_alpn_negotiated); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11415 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11416 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11417 | EXPECT_EQ("hello world", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11418 | } |
| 11419 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11420 | class CapturingProxyResolver : public ProxyResolver { |
| 11421 | public: |
sammc | e90c921 | 2015-05-27 23:43:35 | [diff] [blame] | 11422 | CapturingProxyResolver() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11423 | ~CapturingProxyResolver() override {} |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11424 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11425 | int GetProxyForURL(const GURL& url, |
| 11426 | ProxyInfo* results, |
| 11427 | const CompletionCallback& callback, |
maksim.sisov | 7e15726 | 2016-10-20 11:19:55 | [diff] [blame] | 11428 | std::unique_ptr<Request>* request, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11429 | const NetLogWithSource& net_log) override { |
[email protected] | fae7669f | 2010-08-02 21:49:40 | [diff] [blame] | 11430 | ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, |
| 11431 | HostPortPair("myproxy", 80)); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11432 | results->UseProxyServer(proxy_server); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11433 | resolved_.push_back(url); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11434 | return OK; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11435 | } |
| 11436 | |
[email protected] | 2447640 | 2010-07-20 20:55:17 | [diff] [blame] | 11437 | const std::vector<GURL>& resolved() const { return resolved_; } |
| 11438 | |
| 11439 | private: |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11440 | std::vector<GURL> resolved_; |
| 11441 | |
| 11442 | DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); |
| 11443 | }; |
| 11444 | |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 11445 | class CapturingProxyResolverFactory : public ProxyResolverFactory { |
| 11446 | public: |
| 11447 | explicit CapturingProxyResolverFactory(CapturingProxyResolver* resolver) |
| 11448 | : ProxyResolverFactory(false), resolver_(resolver) {} |
| 11449 | |
| 11450 | int CreateProxyResolver( |
| 11451 | const scoped_refptr<ProxyResolverScriptData>& pac_script, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11452 | std::unique_ptr<ProxyResolver>* resolver, |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 11453 | const net::CompletionCallback& callback, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11454 | std::unique_ptr<Request>* request) override { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11455 | *resolver = std::make_unique<ForwardingProxyResolver>(resolver_); |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 11456 | return OK; |
| 11457 | } |
| 11458 | |
| 11459 | private: |
| 11460 | ProxyResolver* resolver_; |
| 11461 | }; |
| 11462 | |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11463 | // Test that proxy is resolved using the origin url, |
| 11464 | // regardless of the alternative server. |
| 11465 | TEST_F(HttpNetworkTransactionTest, UseOriginNotAlternativeForProxy) { |
| 11466 | // Configure proxy to bypass www.example.org, which is the origin URL. |
| 11467 | ProxyConfig proxy_config; |
| 11468 | proxy_config.proxy_rules().ParseFromString("myproxy:70"); |
| 11469 | proxy_config.proxy_rules().bypass_rules.AddRuleFromString("www.example.org"); |
| 11470 | auto proxy_config_service = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11471 | std::make_unique<ProxyConfigServiceFixed>(proxy_config); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11472 | |
| 11473 | CapturingProxyResolver capturing_proxy_resolver; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11474 | auto proxy_resolver_factory = std::make_unique<CapturingProxyResolverFactory>( |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11475 | &capturing_proxy_resolver); |
| 11476 | |
| 11477 | TestNetLog net_log; |
| 11478 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11479 | session_deps_.proxy_service = std::make_unique<ProxyService>( |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11480 | std::move(proxy_config_service), std::move(proxy_resolver_factory), |
| 11481 | &net_log); |
| 11482 | |
| 11483 | session_deps_.net_log = &net_log; |
| 11484 | |
| 11485 | // Configure alternative service with a hostname that is not bypassed by the |
| 11486 | // proxy. |
| 11487 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11488 | HttpServerProperties* http_server_properties = |
| 11489 | session->http_server_properties(); |
| 11490 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 11491 | HostPortPair alternative("www.example.com", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11492 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11493 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11494 | http_server_properties->SetHttp2AlternativeService( |
| 11495 | server, alternative_service, expiration); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11496 | |
| 11497 | // Non-alternative job should hang. |
| 11498 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
| 11499 | StaticSocketDataProvider hanging_alternate_protocol_socket(nullptr, 0, |
| 11500 | nullptr, 0); |
| 11501 | hanging_alternate_protocol_socket.set_connect_data(never_finishing_connect); |
| 11502 | session_deps_.socket_factory->AddSocketDataProvider( |
| 11503 | &hanging_alternate_protocol_socket); |
| 11504 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11505 | AddSSLSocketData(); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11506 | |
| 11507 | HttpRequestInfo request; |
| 11508 | request.method = "GET"; |
| 11509 | request.url = GURL("https://www.example.org/"); |
| 11510 | request.load_flags = 0; |
| 11511 | |
| 11512 | SpdySerializedFrame req( |
| 11513 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
| 11514 | |
| 11515 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
| 11516 | |
| 11517 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 11518 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 11519 | MockRead spdy_reads[] = { |
| 11520 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
| 11521 | }; |
| 11522 | |
| 11523 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11524 | arraysize(spdy_writes)); |
| 11525 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 11526 | |
| 11527 | TestCompletionCallback callback; |
| 11528 | |
| 11529 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 11530 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11531 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11532 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 11533 | |
| 11534 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 11535 | ASSERT_TRUE(response); |
| 11536 | ASSERT_TRUE(response->headers); |
| 11537 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 11538 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11539 | EXPECT_TRUE(response->was_alpn_negotiated); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 11540 | |
| 11541 | std::string response_data; |
| 11542 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 11543 | EXPECT_EQ("hello!", response_data); |
| 11544 | |
| 11545 | // Origin host bypasses proxy, no resolution should have happened. |
| 11546 | ASSERT_TRUE(capturing_proxy_resolver.resolved().empty()); |
| 11547 | } |
| 11548 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11549 | TEST_F(HttpNetworkTransactionTest, UseAlternativeServiceForTunneledNpnSpdy) { |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11550 | ProxyConfig proxy_config; |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11551 | proxy_config.set_auto_detect(true); |
| 11552 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 11553 | |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11554 | CapturingProxyResolver capturing_proxy_resolver; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11555 | session_deps_.proxy_service = std::make_unique<ProxyService>( |
| 11556 | std::make_unique<ProxyConfigServiceFixed>(proxy_config), |
| 11557 | std::make_unique<CapturingProxyResolverFactory>( |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11558 | &capturing_proxy_resolver), |
| 11559 | nullptr); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11560 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11561 | session_deps_.net_log = &net_log; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11562 | |
| 11563 | HttpRequestInfo request; |
| 11564 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11565 | request.url = GURL("https://www.example.org/"); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11566 | |
| 11567 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11568 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11569 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11570 | MockRead("\r\n"), |
| 11571 | MockRead("hello world"), |
| 11572 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11573 | MockRead(ASYNC, OK), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11574 | }; |
| 11575 | |
| 11576 | StaticSocketDataProvider first_transaction( |
| 11577 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11578 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11579 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11580 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11581 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11582 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11583 | AddSSLSocketData(); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11584 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11585 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11586 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11587 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11588 | MockWrite(ASYNC, 0, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11589 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 11590 | "Host: www.example.org:443\r\n" |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11591 | "Proxy-Connection: keep-alive\r\n\r\n"), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11592 | CreateMockWrite(req, 2), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11593 | }; |
| 11594 | |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 11595 | const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 11596 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 11597 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11598 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11599 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11600 | MockRead(ASYNC, 1, kCONNECTResponse), CreateMockRead(resp, 3), |
| 11601 | CreateMockRead(data, 4), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11602 | }; |
| 11603 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11604 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11605 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11606 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11607 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11608 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11609 | StaticSocketDataProvider hanging_non_alternate_protocol_socket( |
| 11610 | NULL, 0, NULL, 0); |
| 11611 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 11612 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11613 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11614 | &hanging_non_alternate_protocol_socket); |
| 11615 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11616 | TestCompletionCallback callback; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11617 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11618 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11619 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11620 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11621 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11622 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 11623 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11624 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 11625 | |
| 11626 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 11627 | ASSERT_TRUE(response); |
| 11628 | ASSERT_TRUE(response->headers); |
| 11629 | EXPECT_EQ("HTTP/0.9 200 OK", response->headers->GetStatusLine()); |
| 11630 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11631 | EXPECT_TRUE(response->was_alpn_negotiated); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 11632 | |
| 11633 | std::string response_data; |
| 11634 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 11635 | EXPECT_EQ("hello world", response_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11636 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11637 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11638 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11639 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11640 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11641 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11642 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11643 | |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 11644 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11645 | ASSERT_TRUE(response); |
| 11646 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11647 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11648 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11649 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11650 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11651 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11652 | EXPECT_EQ("hello!", response_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11653 | ASSERT_EQ(2u, capturing_proxy_resolver.resolved().size()); |
| 11654 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11655 | capturing_proxy_resolver.resolved()[0].spec()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11656 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 11657 | capturing_proxy_resolver.resolved()[1].spec()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11658 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11659 | LoadTimingInfo load_timing_info; |
| 11660 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 11661 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11662 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11663 | } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 11664 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11665 | TEST_F(HttpNetworkTransactionTest, |
bnc | 1c196c6e | 2016-05-28 13:51:48 | [diff] [blame] | 11666 | UseAlternativeServiceForNpnSpdyWithExistingSpdySession) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11667 | HttpRequestInfo request; |
| 11668 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11669 | request.url = GURL("https://www.example.org/"); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11670 | |
| 11671 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11672 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11673 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11674 | MockRead("\r\n"), |
| 11675 | MockRead("hello world"), |
| 11676 | MockRead(ASYNC, OK), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11677 | }; |
| 11678 | |
| 11679 | StaticSocketDataProvider first_transaction( |
| 11680 | data_reads, arraysize(data_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11681 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11682 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11683 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11684 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11685 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11686 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11687 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11688 | SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11689 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11690 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11691 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 11692 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11693 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11694 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11695 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11696 | }; |
| 11697 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 11698 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 11699 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11700 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11701 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 11702 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11703 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11704 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11705 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11706 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11707 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11708 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11709 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11710 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11711 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11712 | |
| 11713 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11714 | ASSERT_TRUE(response); |
| 11715 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11716 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11717 | |
| 11718 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11719 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11720 | EXPECT_EQ("hello world", response_data); |
| 11721 | |
| 11722 | // Set up an initial SpdySession in the pool to reuse. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11723 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 11724 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 11725 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 11726 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 11727 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 11728 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11729 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11730 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11731 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11732 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11733 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11734 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11735 | |
| 11736 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11737 | ASSERT_TRUE(response); |
| 11738 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11739 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11740 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11741 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11742 | |
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!", response_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11745 | } |
| 11746 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11747 | // GenerateAuthToken is a mighty big test. |
| 11748 | // It tests all permutation of GenerateAuthToken behavior: |
| 11749 | // - Synchronous and Asynchronous completion. |
| 11750 | // - OK or error on completion. |
| 11751 | // - Direct connection, non-authenticating proxy, and authenticating proxy. |
| 11752 | // - HTTP or HTTPS backend (to include proxy tunneling). |
| 11753 | // - Non-authenticating and authenticating backend. |
| 11754 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 11755 | // In all, there are 44 reasonable permuations (for example, if there are |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11756 | // problems generating an auth token for an authenticating proxy, we don't |
| 11757 | // need to test all permutations of the backend server). |
| 11758 | // |
| 11759 | // The test proceeds by going over each of the configuration cases, and |
| 11760 | // potentially running up to three rounds in each of the tests. The TestConfig |
| 11761 | // specifies both the configuration for the test as well as the expectations |
| 11762 | // for the results. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11763 | TEST_F(HttpNetworkTransactionTest, GenerateAuthToken) { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11764 | static const char kServer[] = "http://www.example.com"; |
| 11765 | static const char kSecureServer[] = "https://www.example.com"; |
| 11766 | static const char kProxy[] = "myproxy:70"; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11767 | |
| 11768 | enum AuthTiming { |
| 11769 | AUTH_NONE, |
| 11770 | AUTH_SYNC, |
| 11771 | AUTH_ASYNC, |
| 11772 | }; |
| 11773 | |
| 11774 | const MockWrite kGet( |
| 11775 | "GET / HTTP/1.1\r\n" |
| 11776 | "Host: www.example.com\r\n" |
| 11777 | "Connection: keep-alive\r\n\r\n"); |
| 11778 | const MockWrite kGetProxy( |
| 11779 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11780 | "Host: www.example.com\r\n" |
| 11781 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 11782 | const MockWrite kGetAuth( |
| 11783 | "GET / HTTP/1.1\r\n" |
| 11784 | "Host: www.example.com\r\n" |
| 11785 | "Connection: keep-alive\r\n" |
| 11786 | "Authorization: auth_token\r\n\r\n"); |
| 11787 | const MockWrite kGetProxyAuth( |
| 11788 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11789 | "Host: www.example.com\r\n" |
| 11790 | "Proxy-Connection: keep-alive\r\n" |
| 11791 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 11792 | const MockWrite kGetAuthThroughProxy( |
| 11793 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11794 | "Host: www.example.com\r\n" |
| 11795 | "Proxy-Connection: keep-alive\r\n" |
| 11796 | "Authorization: auth_token\r\n\r\n"); |
| 11797 | const MockWrite kGetAuthWithProxyAuth( |
| 11798 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 11799 | "Host: www.example.com\r\n" |
| 11800 | "Proxy-Connection: keep-alive\r\n" |
| 11801 | "Proxy-Authorization: auth_token\r\n" |
| 11802 | "Authorization: auth_token\r\n\r\n"); |
| 11803 | const MockWrite kConnect( |
| 11804 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 11805 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11806 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 11807 | const MockWrite kConnectProxyAuth( |
| 11808 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 11809 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11810 | "Proxy-Connection: keep-alive\r\n" |
| 11811 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 11812 | |
| 11813 | const MockRead kSuccess( |
| 11814 | "HTTP/1.1 200 OK\r\n" |
| 11815 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11816 | "Content-Length: 3\r\n\r\n" |
| 11817 | "Yes"); |
| 11818 | const MockRead kFailure( |
| 11819 | "Should not be called."); |
| 11820 | const MockRead kServerChallenge( |
| 11821 | "HTTP/1.1 401 Unauthorized\r\n" |
| 11822 | "WWW-Authenticate: Mock realm=server\r\n" |
| 11823 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11824 | "Content-Length: 14\r\n\r\n" |
| 11825 | "Unauthorized\r\n"); |
| 11826 | const MockRead kProxyChallenge( |
| 11827 | "HTTP/1.1 407 Unauthorized\r\n" |
| 11828 | "Proxy-Authenticate: Mock realm=proxy\r\n" |
| 11829 | "Proxy-Connection: close\r\n" |
| 11830 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11831 | "Content-Length: 14\r\n\r\n" |
| 11832 | "Unauthorized\r\n"); |
| 11833 | const MockRead kProxyConnected( |
| 11834 | "HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 11835 | |
| 11836 | // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with |
| 11837 | // no constructors, but the C++ compiler on Windows warns about |
| 11838 | // unspecified data in compound literals. So, moved to using constructors, |
| 11839 | // and TestRound's created with the default constructor should not be used. |
| 11840 | struct TestRound { |
| 11841 | TestRound() |
| 11842 | : expected_rv(ERR_UNEXPECTED), |
| 11843 | extra_write(NULL), |
| 11844 | extra_read(NULL) { |
| 11845 | } |
| 11846 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 11847 | int expected_rv_arg) |
| 11848 | : write(write_arg), |
| 11849 | read(read_arg), |
| 11850 | expected_rv(expected_rv_arg), |
| 11851 | extra_write(NULL), |
| 11852 | extra_read(NULL) { |
| 11853 | } |
| 11854 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 11855 | int expected_rv_arg, const MockWrite* extra_write_arg, |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 11856 | const MockRead* extra_read_arg) |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11857 | : write(write_arg), |
| 11858 | read(read_arg), |
| 11859 | expected_rv(expected_rv_arg), |
| 11860 | extra_write(extra_write_arg), |
| 11861 | extra_read(extra_read_arg) { |
| 11862 | } |
| 11863 | MockWrite write; |
| 11864 | MockRead read; |
| 11865 | int expected_rv; |
| 11866 | const MockWrite* extra_write; |
| 11867 | const MockRead* extra_read; |
| 11868 | }; |
| 11869 | |
| 11870 | static const int kNoSSL = 500; |
| 11871 | |
| 11872 | struct TestConfig { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11873 | int line_number; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 11874 | const char* const proxy_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11875 | AuthTiming proxy_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11876 | int first_generate_proxy_token_rv; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 11877 | const char* const server_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11878 | AuthTiming server_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11879 | int first_generate_server_token_rv; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11880 | int num_auth_rounds; |
| 11881 | int first_ssl_round; |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11882 | TestRound rounds[4]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11883 | } test_configs[] = { |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11884 | // Non-authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11885 | {__LINE__, |
| 11886 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11887 | AUTH_NONE, |
| 11888 | OK, |
| 11889 | kServer, |
| 11890 | AUTH_NONE, |
| 11891 | OK, |
| 11892 | 1, |
| 11893 | kNoSSL, |
| 11894 | {TestRound(kGet, kSuccess, OK)}}, |
| 11895 | // Authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11896 | {__LINE__, |
| 11897 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11898 | AUTH_NONE, |
| 11899 | OK, |
| 11900 | kServer, |
| 11901 | AUTH_SYNC, |
| 11902 | OK, |
| 11903 | 2, |
| 11904 | kNoSSL, |
| 11905 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11906 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11907 | {__LINE__, |
| 11908 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11909 | AUTH_NONE, |
| 11910 | OK, |
| 11911 | kServer, |
| 11912 | AUTH_SYNC, |
| 11913 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11914 | 3, |
| 11915 | kNoSSL, |
| 11916 | {TestRound(kGet, kServerChallenge, OK), |
| 11917 | TestRound(kGet, kServerChallenge, OK), |
| 11918 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11919 | {__LINE__, |
| 11920 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11921 | AUTH_NONE, |
| 11922 | OK, |
| 11923 | kServer, |
| 11924 | AUTH_SYNC, |
| 11925 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 11926 | 2, |
| 11927 | kNoSSL, |
| 11928 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11929 | {__LINE__, |
| 11930 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11931 | AUTH_NONE, |
| 11932 | OK, |
| 11933 | kServer, |
| 11934 | AUTH_SYNC, |
| 11935 | ERR_UNDOCUMENTED_SECURITY_LIBRARY_STATUS, |
| 11936 | 2, |
| 11937 | kNoSSL, |
| 11938 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11939 | {__LINE__, |
| 11940 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11941 | AUTH_SYNC, |
| 11942 | ERR_FAILED, |
| 11943 | kServer, |
| 11944 | AUTH_NONE, |
| 11945 | OK, |
| 11946 | 2, |
| 11947 | kNoSSL, |
| 11948 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 11949 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11950 | {__LINE__, |
| 11951 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11952 | AUTH_ASYNC, |
| 11953 | ERR_FAILED, |
| 11954 | kServer, |
| 11955 | AUTH_NONE, |
| 11956 | OK, |
| 11957 | 2, |
| 11958 | kNoSSL, |
| 11959 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 11960 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11961 | {__LINE__, |
| 11962 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11963 | AUTH_NONE, |
| 11964 | OK, |
| 11965 | kServer, |
| 11966 | AUTH_SYNC, |
| 11967 | ERR_FAILED, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11968 | 2, |
| 11969 | kNoSSL, |
| 11970 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11971 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11972 | {__LINE__, |
| 11973 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 11974 | AUTH_NONE, |
| 11975 | OK, |
| 11976 | kServer, |
| 11977 | AUTH_ASYNC, |
| 11978 | ERR_FAILED, |
| 11979 | 2, |
| 11980 | kNoSSL, |
| 11981 | {TestRound(kGet, kServerChallenge, OK), |
| 11982 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11983 | {__LINE__, |
| 11984 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11985 | AUTH_NONE, |
| 11986 | OK, |
| 11987 | kServer, |
| 11988 | AUTH_ASYNC, |
| 11989 | OK, |
| 11990 | 2, |
| 11991 | kNoSSL, |
| 11992 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 11993 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 11994 | {__LINE__, |
| 11995 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 11996 | AUTH_NONE, |
| 11997 | OK, |
| 11998 | kServer, |
| 11999 | AUTH_ASYNC, |
| 12000 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12001 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12002 | kNoSSL, |
| 12003 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12004 | // The second round uses a HttpAuthHandlerMock that always succeeds. |
| 12005 | TestRound(kGet, kServerChallenge, OK), |
| 12006 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12007 | // Non-authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12008 | {__LINE__, |
| 12009 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12010 | AUTH_NONE, |
| 12011 | OK, |
| 12012 | kServer, |
| 12013 | AUTH_NONE, |
| 12014 | OK, |
| 12015 | 1, |
| 12016 | kNoSSL, |
| 12017 | {TestRound(kGetProxy, kSuccess, OK)}}, |
| 12018 | // Authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12019 | {__LINE__, |
| 12020 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12021 | AUTH_NONE, |
| 12022 | OK, |
| 12023 | kServer, |
| 12024 | AUTH_SYNC, |
| 12025 | OK, |
| 12026 | 2, |
| 12027 | kNoSSL, |
| 12028 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12029 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12030 | {__LINE__, |
| 12031 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12032 | AUTH_NONE, |
| 12033 | OK, |
| 12034 | kServer, |
| 12035 | AUTH_SYNC, |
| 12036 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12037 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12038 | kNoSSL, |
| 12039 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12040 | TestRound(kGetProxy, kServerChallenge, OK), |
| 12041 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12042 | {__LINE__, |
| 12043 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12044 | AUTH_NONE, |
| 12045 | OK, |
| 12046 | kServer, |
| 12047 | AUTH_ASYNC, |
| 12048 | OK, |
| 12049 | 2, |
| 12050 | kNoSSL, |
| 12051 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12052 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12053 | {__LINE__, |
| 12054 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12055 | AUTH_NONE, |
| 12056 | OK, |
| 12057 | kServer, |
| 12058 | AUTH_ASYNC, |
| 12059 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12060 | 2, |
| 12061 | kNoSSL, |
| 12062 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12063 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12064 | // Non-authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12065 | {__LINE__, |
| 12066 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12067 | AUTH_SYNC, |
| 12068 | OK, |
| 12069 | kServer, |
| 12070 | AUTH_NONE, |
| 12071 | OK, |
| 12072 | 2, |
| 12073 | kNoSSL, |
| 12074 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12075 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12076 | {__LINE__, |
| 12077 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12078 | AUTH_SYNC, |
| 12079 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12080 | kServer, |
| 12081 | AUTH_NONE, |
| 12082 | OK, |
| 12083 | 2, |
| 12084 | kNoSSL, |
| 12085 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12086 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12087 | {__LINE__, |
| 12088 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12089 | AUTH_ASYNC, |
| 12090 | OK, |
| 12091 | kServer, |
| 12092 | AUTH_NONE, |
| 12093 | OK, |
| 12094 | 2, |
| 12095 | kNoSSL, |
| 12096 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12097 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12098 | {__LINE__, |
| 12099 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12100 | AUTH_ASYNC, |
| 12101 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12102 | kServer, |
| 12103 | AUTH_NONE, |
| 12104 | OK, |
| 12105 | 2, |
| 12106 | kNoSSL, |
| 12107 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12108 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12109 | {__LINE__, |
| 12110 | kProxy, |
| 12111 | AUTH_ASYNC, |
| 12112 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12113 | kServer, |
| 12114 | AUTH_NONE, |
| 12115 | OK, |
| 12116 | 3, |
| 12117 | kNoSSL, |
| 12118 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12119 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 12120 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12121 | // Authenticating HTTP server through an authenticating proxy. |
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_SYNC, |
| 12125 | OK, |
| 12126 | kServer, |
| 12127 | AUTH_SYNC, |
| 12128 | OK, |
| 12129 | 3, |
| 12130 | kNoSSL, |
| 12131 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12132 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12133 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12134 | {__LINE__, |
| 12135 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12136 | AUTH_SYNC, |
| 12137 | OK, |
| 12138 | kServer, |
| 12139 | AUTH_SYNC, |
| 12140 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12141 | 3, |
| 12142 | kNoSSL, |
| 12143 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12144 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12145 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
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_ASYNC, |
| 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_ASYNC, |
| 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_SYNC, |
| 12173 | OK, |
| 12174 | kServer, |
| 12175 | AUTH_ASYNC, |
| 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, |
| 12184 | AUTH_SYNC, |
| 12185 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12186 | kServer, |
| 12187 | AUTH_ASYNC, |
| 12188 | OK, |
| 12189 | 4, |
| 12190 | kNoSSL, |
| 12191 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12192 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 12193 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12194 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 12195 | {__LINE__, |
| 12196 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12197 | AUTH_SYNC, |
| 12198 | OK, |
| 12199 | kServer, |
| 12200 | AUTH_ASYNC, |
| 12201 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12202 | 3, |
| 12203 | kNoSSL, |
| 12204 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12205 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12206 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12207 | {__LINE__, |
| 12208 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12209 | AUTH_ASYNC, |
| 12210 | OK, |
| 12211 | kServer, |
| 12212 | AUTH_ASYNC, |
| 12213 | OK, |
| 12214 | 3, |
| 12215 | kNoSSL, |
| 12216 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12217 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12218 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12219 | {__LINE__, |
| 12220 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12221 | AUTH_ASYNC, |
| 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, |
| 12233 | AUTH_ASYNC, |
| 12234 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12235 | kServer, |
| 12236 | AUTH_ASYNC, |
| 12237 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12238 | 4, |
| 12239 | kNoSSL, |
| 12240 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12241 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 12242 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12243 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12244 | // Non-authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12245 | {__LINE__, |
| 12246 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12247 | AUTH_NONE, |
| 12248 | OK, |
| 12249 | kSecureServer, |
| 12250 | AUTH_NONE, |
| 12251 | OK, |
| 12252 | 1, |
| 12253 | 0, |
| 12254 | {TestRound(kGet, kSuccess, OK)}}, |
| 12255 | // Authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12256 | {__LINE__, |
| 12257 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12258 | AUTH_NONE, |
| 12259 | OK, |
| 12260 | kSecureServer, |
| 12261 | AUTH_SYNC, |
| 12262 | OK, |
| 12263 | 2, |
| 12264 | 0, |
| 12265 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12266 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12267 | {__LINE__, |
| 12268 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12269 | AUTH_NONE, |
| 12270 | OK, |
| 12271 | kSecureServer, |
| 12272 | AUTH_SYNC, |
| 12273 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12274 | 2, |
| 12275 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12276 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12277 | {__LINE__, |
| 12278 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12279 | AUTH_NONE, |
| 12280 | OK, |
| 12281 | kSecureServer, |
| 12282 | AUTH_ASYNC, |
| 12283 | OK, |
| 12284 | 2, |
| 12285 | 0, |
| 12286 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12287 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12288 | {__LINE__, |
| 12289 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12290 | AUTH_NONE, |
| 12291 | OK, |
| 12292 | kSecureServer, |
| 12293 | AUTH_ASYNC, |
| 12294 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12295 | 2, |
| 12296 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12297 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12298 | // Non-authenticating HTTPS server with a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12299 | {__LINE__, |
| 12300 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12301 | AUTH_NONE, |
| 12302 | OK, |
| 12303 | kSecureServer, |
| 12304 | AUTH_NONE, |
| 12305 | OK, |
| 12306 | 1, |
| 12307 | 0, |
| 12308 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 12309 | // Authenticating HTTPS server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12310 | {__LINE__, |
| 12311 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12312 | AUTH_NONE, |
| 12313 | OK, |
| 12314 | kSecureServer, |
| 12315 | AUTH_SYNC, |
| 12316 | OK, |
| 12317 | 2, |
| 12318 | 0, |
| 12319 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12320 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12321 | {__LINE__, |
| 12322 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12323 | AUTH_NONE, |
| 12324 | OK, |
| 12325 | kSecureServer, |
| 12326 | AUTH_SYNC, |
| 12327 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12328 | 2, |
| 12329 | 0, |
| 12330 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12331 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12332 | {__LINE__, |
| 12333 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12334 | AUTH_NONE, |
| 12335 | OK, |
| 12336 | kSecureServer, |
| 12337 | AUTH_ASYNC, |
| 12338 | OK, |
| 12339 | 2, |
| 12340 | 0, |
| 12341 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12342 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12343 | {__LINE__, |
| 12344 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12345 | AUTH_NONE, |
| 12346 | OK, |
| 12347 | kSecureServer, |
| 12348 | AUTH_ASYNC, |
| 12349 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12350 | 2, |
| 12351 | 0, |
| 12352 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12353 | TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12354 | // Non-Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12355 | {__LINE__, |
| 12356 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12357 | AUTH_SYNC, |
| 12358 | OK, |
| 12359 | kSecureServer, |
| 12360 | AUTH_NONE, |
| 12361 | OK, |
| 12362 | 2, |
| 12363 | 1, |
| 12364 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12365 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12366 | {__LINE__, |
| 12367 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12368 | AUTH_SYNC, |
| 12369 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12370 | kSecureServer, |
| 12371 | AUTH_NONE, |
| 12372 | OK, |
| 12373 | 2, |
| 12374 | kNoSSL, |
| 12375 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12376 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12377 | {__LINE__, |
| 12378 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12379 | AUTH_SYNC, |
| 12380 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 12381 | kSecureServer, |
| 12382 | AUTH_NONE, |
| 12383 | OK, |
| 12384 | 2, |
| 12385 | kNoSSL, |
| 12386 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12387 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12388 | {__LINE__, |
| 12389 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12390 | AUTH_SYNC, |
| 12391 | ERR_UNEXPECTED, |
| 12392 | kSecureServer, |
| 12393 | AUTH_NONE, |
| 12394 | OK, |
| 12395 | 2, |
| 12396 | kNoSSL, |
| 12397 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12398 | TestRound(kConnect, kProxyConnected, ERR_UNEXPECTED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12399 | {__LINE__, |
| 12400 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12401 | AUTH_ASYNC, |
| 12402 | OK, |
| 12403 | kSecureServer, |
| 12404 | AUTH_NONE, |
| 12405 | OK, |
| 12406 | 2, |
| 12407 | 1, |
| 12408 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12409 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12410 | {__LINE__, |
| 12411 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12412 | AUTH_ASYNC, |
| 12413 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12414 | kSecureServer, |
| 12415 | AUTH_NONE, |
| 12416 | OK, |
| 12417 | 2, |
| 12418 | kNoSSL, |
| 12419 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12420 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12421 | // Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12422 | {__LINE__, |
| 12423 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12424 | AUTH_SYNC, |
| 12425 | OK, |
| 12426 | kSecureServer, |
| 12427 | AUTH_SYNC, |
| 12428 | OK, |
| 12429 | 3, |
| 12430 | 1, |
| 12431 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12432 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12433 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12434 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12435 | {__LINE__, |
| 12436 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12437 | AUTH_SYNC, |
| 12438 | OK, |
| 12439 | kSecureServer, |
| 12440 | AUTH_SYNC, |
| 12441 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12442 | 3, |
| 12443 | 1, |
| 12444 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12445 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12446 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12447 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12448 | {__LINE__, |
| 12449 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12450 | AUTH_ASYNC, |
| 12451 | OK, |
| 12452 | kSecureServer, |
| 12453 | AUTH_SYNC, |
| 12454 | OK, |
| 12455 | 3, |
| 12456 | 1, |
| 12457 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12458 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12459 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12460 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12461 | {__LINE__, |
| 12462 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12463 | AUTH_ASYNC, |
| 12464 | OK, |
| 12465 | kSecureServer, |
| 12466 | AUTH_SYNC, |
| 12467 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12468 | 3, |
| 12469 | 1, |
| 12470 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12471 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12472 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12473 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12474 | {__LINE__, |
| 12475 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12476 | AUTH_SYNC, |
| 12477 | OK, |
| 12478 | kSecureServer, |
| 12479 | AUTH_ASYNC, |
| 12480 | OK, |
| 12481 | 3, |
| 12482 | 1, |
| 12483 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12484 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12485 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12486 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12487 | {__LINE__, |
| 12488 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12489 | AUTH_SYNC, |
| 12490 | OK, |
| 12491 | kSecureServer, |
| 12492 | AUTH_ASYNC, |
| 12493 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12494 | 3, |
| 12495 | 1, |
| 12496 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12497 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12498 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12499 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12500 | {__LINE__, |
| 12501 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12502 | AUTH_ASYNC, |
| 12503 | OK, |
| 12504 | kSecureServer, |
| 12505 | AUTH_ASYNC, |
| 12506 | OK, |
| 12507 | 3, |
| 12508 | 1, |
| 12509 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12510 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12511 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12512 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12513 | {__LINE__, |
| 12514 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12515 | AUTH_ASYNC, |
| 12516 | OK, |
| 12517 | kSecureServer, |
| 12518 | AUTH_ASYNC, |
| 12519 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12520 | 3, |
| 12521 | 1, |
| 12522 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12523 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12524 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12525 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12526 | {__LINE__, |
| 12527 | kProxy, |
| 12528 | AUTH_ASYNC, |
| 12529 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12530 | kSecureServer, |
| 12531 | AUTH_ASYNC, |
| 12532 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12533 | 4, |
| 12534 | 2, |
| 12535 | {TestRound(kConnect, kProxyChallenge, OK), |
| 12536 | TestRound(kConnect, kProxyChallenge, OK), |
| 12537 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 12538 | &kServerChallenge), |
| 12539 | TestRound(kGet, kSuccess, OK)}}, |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12540 | }; |
| 12541 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12542 | for (const auto& test_config : test_configs) { |
| 12543 | SCOPED_TRACE(::testing::Message() << "Test config at " |
| 12544 | << test_config.line_number); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12545 | HttpAuthHandlerMock::Factory* auth_factory( |
| 12546 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12547 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 12548 | SSLInfo empty_ssl_info; |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 12549 | |
| 12550 | // Set up authentication handlers as necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12551 | if (test_config.proxy_auth_timing != AUTH_NONE) { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12552 | for (int n = 0; n < 3; n++) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12553 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 12554 | std::string auth_challenge = "Mock realm=proxy"; |
| 12555 | GURL origin(test_config.proxy_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 12556 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 12557 | auth_challenge.end()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12558 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12559 | empty_ssl_info, origin, |
| 12560 | NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12561 | auth_handler->SetGenerateExpectation( |
| 12562 | test_config.proxy_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12563 | n == 0 ? test_config.first_generate_proxy_token_rv : OK); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12564 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 12565 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12566 | } |
| 12567 | if (test_config.server_auth_timing != AUTH_NONE) { |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 12568 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12569 | std::string auth_challenge = "Mock realm=server"; |
| 12570 | GURL origin(test_config.server_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 12571 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 12572 | auth_challenge.end()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12573 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12574 | empty_ssl_info, origin, |
| 12575 | NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12576 | auth_handler->SetGenerateExpectation( |
| 12577 | test_config.server_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12578 | test_config.first_generate_server_token_rv); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12579 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12580 | |
| 12581 | // The second handler always succeeds. It should only be used where there |
| 12582 | // are multiple auth sessions for server auth in the same network |
| 12583 | // transaction using the same auth scheme. |
| 12584 | std::unique_ptr<HttpAuthHandlerMock> second_handler = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12585 | std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12586 | second_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 12587 | empty_ssl_info, origin, |
| 12588 | NetLogWithSource()); |
| 12589 | second_handler->SetGenerateExpectation(true, OK); |
| 12590 | auth_factory->AddMockHandler(second_handler.release(), |
| 12591 | HttpAuth::AUTH_SERVER); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12592 | } |
| 12593 | if (test_config.proxy_url) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12594 | session_deps_.proxy_service = |
| 12595 | ProxyService::CreateFixed(test_config.proxy_url); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12596 | } else { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12597 | session_deps_.proxy_service = ProxyService::CreateDirect(); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12598 | } |
| 12599 | |
| 12600 | HttpRequestInfo request; |
| 12601 | request.method = "GET"; |
| 12602 | request.url = GURL(test_config.server_url); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12603 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12604 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12605 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12606 | SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
| 12607 | |
| 12608 | std::vector<std::vector<MockRead>> mock_reads(1); |
| 12609 | std::vector<std::vector<MockWrite>> mock_writes(1); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12610 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 12611 | SCOPED_TRACE(round); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12612 | const TestRound& read_write_round = test_config.rounds[round]; |
| 12613 | |
| 12614 | // Set up expected reads and writes. |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12615 | mock_reads.back().push_back(read_write_round.read); |
| 12616 | mock_writes.back().push_back(read_write_round.write); |
| 12617 | |
| 12618 | // kProxyChallenge uses Proxy-Connection: close which means that the |
| 12619 | // socket is closed and a new one will be created for the next request. |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 12620 | if (read_write_round.read.data == kProxyChallenge.data) { |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12621 | mock_reads.push_back(std::vector<MockRead>()); |
| 12622 | mock_writes.push_back(std::vector<MockWrite>()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12623 | } |
| 12624 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12625 | if (read_write_round.extra_read) { |
| 12626 | mock_reads.back().push_back(*read_write_round.extra_read); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12627 | } |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12628 | if (read_write_round.extra_write) { |
| 12629 | mock_writes.back().push_back(*read_write_round.extra_write); |
| 12630 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12631 | |
| 12632 | // Add an SSL sequence if necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12633 | if (round >= test_config.first_ssl_round) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12634 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12635 | &ssl_socket_data_provider); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12636 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12637 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12638 | std::vector<std::unique_ptr<StaticSocketDataProvider>> data_providers; |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12639 | for (size_t i = 0; i < mock_reads.size(); ++i) { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12640 | data_providers.push_back(std::make_unique<StaticSocketDataProvider>( |
davidben | 5f8b6bc | 2015-11-25 03:19:54 | [diff] [blame] | 12641 | mock_reads[i].data(), mock_reads[i].size(), mock_writes[i].data(), |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12642 | mock_writes[i].size())); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12643 | session_deps_.socket_factory->AddSocketDataProvider( |
olli.raula | 525048c | 2015-12-10 07:38:32 | [diff] [blame] | 12644 | data_providers.back().get()); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12645 | } |
| 12646 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12647 | // Transaction must be created after DataProviders, so it's destroyed before |
| 12648 | // they are as well. |
| 12649 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 12650 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12651 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 12652 | SCOPED_TRACE(round); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 12653 | const TestRound& read_write_round = test_config.rounds[round]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12654 | // Start or restart the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12655 | TestCompletionCallback callback; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12656 | int rv; |
| 12657 | if (round == 0) { |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12658 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12659 | } else { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12660 | rv = trans.RestartWithAuth( |
| 12661 | AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12662 | } |
| 12663 | if (rv == ERR_IO_PENDING) |
| 12664 | rv = callback.WaitForResult(); |
| 12665 | |
| 12666 | // Compare results with expected data. |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12667 | EXPECT_THAT(rv, IsError(read_write_round.expected_rv)); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12668 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | c0c82849 | 2015-05-15 01:25:55 | [diff] [blame] | 12669 | if (read_write_round.expected_rv != OK) { |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12670 | EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
| 12671 | continue; |
| 12672 | } |
| 12673 | if (round + 1 < test_config.num_auth_rounds) { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12674 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12675 | } else { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12676 | EXPECT_FALSE(response->auth_challenge); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12677 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12678 | } |
| 12679 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 12680 | } |
| 12681 | } |
| 12682 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12683 | TEST_F(HttpNetworkTransactionTest, MultiRoundAuth) { |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12684 | // Do multi-round authentication and make sure it works correctly. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12685 | HttpAuthHandlerMock::Factory* auth_factory( |
| 12686 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12687 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 12688 | session_deps_.proxy_service = ProxyService::CreateDirect(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12689 | session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
| 12690 | session_deps_.host_resolver->set_synchronous_mode(true); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12691 | |
| 12692 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 12693 | auth_handler->set_connection_based(true); |
| 12694 | std::string auth_challenge = "Mock realm=server"; |
| 12695 | GURL origin("http://www.example.com"); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 12696 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 12697 | auth_challenge.end()); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 12698 | SSLInfo empty_ssl_info; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12699 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12700 | empty_ssl_info, origin, NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 12701 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12702 | |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12703 | int rv = OK; |
| 12704 | const HttpResponseInfo* response = NULL; |
| 12705 | HttpRequestInfo request; |
| 12706 | request.method = "GET"; |
| 12707 | request.url = origin; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 12708 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12709 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12710 | |
| 12711 | // Use a TCP Socket Pool with only one connection per group. This is used |
| 12712 | // to validate that the TCP socket is not released to the pool between |
| 12713 | // each round of multi-round authentication. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 12714 | HttpNetworkSessionPeer session_peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12715 | TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12716 | 50, // Max sockets for pool |
| 12717 | 1, // Max sockets per group |
tbansal | 7b403bcc | 2016-04-13 22:33:21 | [diff] [blame] | 12718 | session_deps_.host_resolver.get(), session_deps_.socket_factory.get(), |
| 12719 | NULL, session_deps_.net_log); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12720 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 12721 | mock_pool_manager->SetTransportSocketPool(transport_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 12722 | session_peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12723 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12724 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12725 | TestCompletionCallback callback; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12726 | |
| 12727 | const MockWrite kGet( |
| 12728 | "GET / HTTP/1.1\r\n" |
| 12729 | "Host: www.example.com\r\n" |
| 12730 | "Connection: keep-alive\r\n\r\n"); |
| 12731 | const MockWrite kGetAuth( |
| 12732 | "GET / HTTP/1.1\r\n" |
| 12733 | "Host: www.example.com\r\n" |
| 12734 | "Connection: keep-alive\r\n" |
| 12735 | "Authorization: auth_token\r\n\r\n"); |
| 12736 | |
| 12737 | const MockRead kServerChallenge( |
| 12738 | "HTTP/1.1 401 Unauthorized\r\n" |
| 12739 | "WWW-Authenticate: Mock realm=server\r\n" |
| 12740 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12741 | "Content-Length: 14\r\n\r\n" |
| 12742 | "Unauthorized\r\n"); |
| 12743 | const MockRead kSuccess( |
| 12744 | "HTTP/1.1 200 OK\r\n" |
| 12745 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12746 | "Content-Length: 3\r\n\r\n" |
| 12747 | "Yes"); |
| 12748 | |
| 12749 | MockWrite writes[] = { |
| 12750 | // First round |
| 12751 | kGet, |
| 12752 | // Second round |
| 12753 | kGetAuth, |
| 12754 | // Third round |
| 12755 | kGetAuth, |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 12756 | // Fourth round |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12757 | kGetAuth, |
| 12758 | // Competing request |
| 12759 | kGet, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12760 | }; |
| 12761 | MockRead reads[] = { |
| 12762 | // First round |
| 12763 | kServerChallenge, |
| 12764 | // Second round |
| 12765 | kServerChallenge, |
| 12766 | // Third round |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 12767 | kServerChallenge, |
| 12768 | // Fourth round |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12769 | kSuccess, |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12770 | // Competing response |
| 12771 | kSuccess, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12772 | }; |
| 12773 | StaticSocketDataProvider data_provider(reads, arraysize(reads), |
| 12774 | writes, arraysize(writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12775 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12776 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 12777 | const char kSocketGroup[] = "www.example.com:80"; |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12778 | |
| 12779 | // First round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12780 | auth_handler->SetGenerateExpectation(false, OK); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12781 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12782 | if (rv == ERR_IO_PENDING) |
| 12783 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12784 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12785 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12786 | ASSERT_TRUE(response); |
| 12787 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12788 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12789 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 12790 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12791 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12792 | // In between rounds, another request comes in for the same domain. |
| 12793 | // It should not be able to grab the TCP socket that trans has already |
| 12794 | // claimed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12795 | HttpNetworkTransaction trans_compete(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12796 | TestCompletionCallback callback_compete; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12797 | rv = trans_compete.Start(&request, callback_compete.callback(), |
| 12798 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12799 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12800 | // callback_compete.WaitForResult at this point would stall forever, |
| 12801 | // since the HttpNetworkTransaction does not release the request back to |
| 12802 | // the pool until after authentication completes. |
| 12803 | |
| 12804 | // Second round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12805 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12806 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12807 | if (rv == ERR_IO_PENDING) |
| 12808 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12809 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12810 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12811 | ASSERT_TRUE(response); |
| 12812 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12813 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12814 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 12815 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12816 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12817 | // Third round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12818 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12819 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12820 | if (rv == ERR_IO_PENDING) |
| 12821 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12822 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12823 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12824 | ASSERT_TRUE(response); |
| 12825 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12826 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12827 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 12828 | auth_handler->state()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 12829 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12830 | // Fourth round of authentication, which completes successfully. |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 12831 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12832 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 12833 | if (rv == ERR_IO_PENDING) |
| 12834 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12835 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12836 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12837 | ASSERT_TRUE(response); |
| 12838 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12839 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12840 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12841 | // In WAIT_FOR_CHALLENGE, although in reality the auth handler is done. A real |
| 12842 | // auth handler should transition to a DONE state in concert with the remote |
| 12843 | // server. But that's not something we can test here with a mock handler. |
| 12844 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_CHALLENGE, |
| 12845 | auth_handler->state()); |
| 12846 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12847 | // Read the body since the fourth round was successful. This will also |
| 12848 | // release the socket back to the pool. |
| 12849 | scoped_refptr<IOBufferWithSize> io_buf(new IOBufferWithSize(50)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12850 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12851 | if (rv == ERR_IO_PENDING) |
| 12852 | rv = callback.WaitForResult(); |
| 12853 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12854 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12855 | EXPECT_EQ(0, rv); |
| 12856 | // There are still 0 idle sockets, since the trans_compete transaction |
| 12857 | // will be handed it immediately after trans releases it to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12858 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12859 | |
| 12860 | // The competing request can now finish. Wait for the headers and then |
| 12861 | // read the body. |
| 12862 | rv = callback_compete.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12863 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12864 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12865 | if (rv == ERR_IO_PENDING) |
| 12866 | rv = callback.WaitForResult(); |
| 12867 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12868 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 12869 | EXPECT_EQ(0, rv); |
| 12870 | |
| 12871 | // Finally, the socket is released to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 12872 | EXPECT_EQ(1, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 12873 | } |
| 12874 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12875 | // This tests the case that a request is issued via http instead of spdy after |
| 12876 | // npn is negotiated. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12877 | TEST_F(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12878 | HttpRequestInfo request; |
| 12879 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12880 | request.url = GURL("https://www.example.org/"); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12881 | |
| 12882 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12883 | MockWrite( |
| 12884 | "GET / HTTP/1.1\r\n" |
| 12885 | "Host: www.example.org\r\n" |
| 12886 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12887 | }; |
| 12888 | |
| 12889 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12890 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12891 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12892 | MockRead("\r\n"), |
| 12893 | MockRead("hello world"), |
| 12894 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12895 | }; |
| 12896 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12897 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12898 | ssl.next_proto = kProtoHTTP11; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12899 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12900 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12901 | |
| 12902 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 12903 | data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12904 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12905 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12906 | TestCompletionCallback callback; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12907 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12908 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12909 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12910 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12911 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12912 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12913 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12914 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12915 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12916 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12917 | ASSERT_TRUE(response); |
| 12918 | ASSERT_TRUE(response->headers); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12919 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12920 | |
| 12921 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12922 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12923 | EXPECT_EQ("hello world", response_data); |
| 12924 | |
| 12925 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12926 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12927 | } |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12928 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12929 | // Simulate the SSL handshake completing with an NPN negotiation followed by an |
| 12930 | // immediate server closing of the socket. |
| 12931 | // Regression test for https://crbug.com/46369. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12932 | TEST_F(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12933 | HttpRequestInfo request; |
| 12934 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12935 | request.url = GURL("https://www.example.org/"); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12936 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12937 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12938 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12939 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12940 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12941 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 12942 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12943 | MockWrite spdy_writes[] = {CreateMockWrite(req, 1)}; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12944 | |
| 12945 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12946 | MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12947 | }; |
| 12948 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12949 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 12950 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12951 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12952 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12953 | TestCompletionCallback callback; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12954 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12955 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12956 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12957 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12958 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12959 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12960 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 12961 | } |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 12962 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 12963 | // A subclass of HttpAuthHandlerMock that records the request URL when |
| 12964 | // it gets it. This is needed since the auth handler may get destroyed |
| 12965 | // before we get a chance to query it. |
| 12966 | class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock { |
| 12967 | public: |
| 12968 | explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {} |
| 12969 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12970 | ~UrlRecordingHttpAuthHandlerMock() override {} |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 12971 | |
| 12972 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12973 | int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 12974 | const HttpRequestInfo* request, |
| 12975 | const CompletionCallback& callback, |
| 12976 | std::string* auth_token) override { |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 12977 | *url_ = request->url; |
| 12978 | return HttpAuthHandlerMock::GenerateAuthTokenImpl( |
| 12979 | credentials, request, callback, auth_token); |
| 12980 | } |
| 12981 | |
| 12982 | private: |
| 12983 | GURL* url_; |
| 12984 | }; |
| 12985 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12986 | // Test that if we cancel the transaction as the connection is completing, that |
| 12987 | // everything tears down correctly. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12988 | TEST_F(HttpNetworkTransactionTest, SimpleCancel) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12989 | // Setup everything about the connection to complete synchronously, so that |
| 12990 | // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
| 12991 | // for is the callback from the HttpStreamRequest. |
| 12992 | // Then cancel the transaction. |
| 12993 | // Verify that we don't crash. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12994 | MockConnect mock_connect(SYNCHRONOUS, OK); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12995 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12996 | MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), |
| 12997 | MockRead(SYNCHRONOUS, "hello world"), |
| 12998 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 12999 | }; |
| 13000 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13001 | HttpRequestInfo request; |
| 13002 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13003 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13004 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13005 | session_deps_.host_resolver->set_synchronous_mode(true); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13006 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13007 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13008 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13009 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13010 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 13011 | data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13012 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13013 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13014 | TestCompletionCallback callback; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13015 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13016 | BoundTestNetLog log; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13017 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13018 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13019 | trans.reset(); // Cancel the transaction here. |
| 13020 | |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 13021 | base::RunLoop().RunUntilIdle(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 13022 | } |
| 13023 | |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13024 | // Test that if a transaction is cancelled after receiving the headers, the |
| 13025 | // stream is drained properly and added back to the socket pool. The main |
| 13026 | // purpose of this test is to make sure that an HttpStreamParser can be read |
| 13027 | // from after the HttpNetworkTransaction and the objects it owns have been |
| 13028 | // deleted. |
| 13029 | // See http://crbug.com/368418 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13030 | TEST_F(HttpNetworkTransactionTest, CancelAfterHeaders) { |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13031 | MockRead data_reads[] = { |
| 13032 | MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"), |
| 13033 | MockRead(ASYNC, "Content-Length: 2\r\n"), |
| 13034 | MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"), |
| 13035 | MockRead(ASYNC, "1"), |
| 13036 | // 2 async reads are necessary to trigger a ReadResponseBody call after the |
| 13037 | // HttpNetworkTransaction has been deleted. |
| 13038 | MockRead(ASYNC, "2"), |
| 13039 | MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this. |
| 13040 | }; |
| 13041 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 13042 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13043 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13044 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13045 | |
| 13046 | { |
| 13047 | HttpRequestInfo request; |
| 13048 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13049 | request.url = GURL("http://www.example.org/"); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13050 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13051 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13052 | TestCompletionCallback callback; |
| 13053 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13054 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13055 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13056 | callback.WaitForResult(); |
| 13057 | |
| 13058 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13059 | ASSERT_TRUE(response); |
| 13060 | EXPECT_TRUE(response->headers); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13061 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13062 | |
| 13063 | // The transaction and HttpRequestInfo are deleted. |
| 13064 | } |
| 13065 | |
| 13066 | // Let the HttpResponseBodyDrainer drain the socket. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 13067 | base::RunLoop().RunUntilIdle(); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13068 | |
| 13069 | // Socket should now be idle, waiting to be reused. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13070 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13071 | } |
| 13072 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13073 | // Test a basic GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13074 | TEST_F(HttpNetworkTransactionTest, ProxyGet) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 13075 | session_deps_.proxy_service = |
| 13076 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13077 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13078 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13079 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13080 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13081 | HttpRequestInfo request; |
| 13082 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13083 | request.url = GURL("http://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13084 | |
| 13085 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13086 | MockWrite( |
| 13087 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 13088 | "Host: www.example.org\r\n" |
| 13089 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13090 | }; |
| 13091 | |
| 13092 | MockRead data_reads1[] = { |
| 13093 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13094 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 13095 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13096 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13097 | }; |
| 13098 | |
| 13099 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 13100 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13101 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13102 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13103 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13104 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13105 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13106 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13107 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13108 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 13109 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13110 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13111 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13112 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13113 | |
| 13114 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13115 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13116 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13117 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13118 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13119 | |
| 13120 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 13121 | EXPECT_EQ(200, response->headers->response_code()); |
| 13122 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 13123 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 13124 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 13125 | HostPortPair::FromString("myproxy:70")), |
| 13126 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13127 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 13128 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 13129 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13130 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13131 | |
| 13132 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13133 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13134 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 13135 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13136 | } |
| 13137 | |
| 13138 | // Test a basic HTTPS GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13139 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGet) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 13140 | session_deps_.proxy_service = |
| 13141 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13142 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13143 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13144 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13145 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13146 | HttpRequestInfo request; |
| 13147 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13148 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13149 | |
| 13150 | // Since we have proxy, should try to establish tunnel. |
| 13151 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13152 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 13153 | "Host: www.example.org:443\r\n" |
| 13154 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13155 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13156 | MockWrite("GET / HTTP/1.1\r\n" |
| 13157 | "Host: www.example.org\r\n" |
| 13158 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13159 | }; |
| 13160 | |
| 13161 | MockRead data_reads1[] = { |
| 13162 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 13163 | |
| 13164 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13165 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 13166 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13167 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13168 | }; |
| 13169 | |
| 13170 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 13171 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13172 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13173 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13174 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13175 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13176 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13177 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13178 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13179 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13180 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13181 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 13182 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13183 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13184 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13185 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13186 | |
| 13187 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13188 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 13189 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 13190 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13191 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13192 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 13193 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13194 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 13195 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13196 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 13197 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13198 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13199 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13200 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13201 | |
| 13202 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 13203 | EXPECT_EQ(200, response->headers->response_code()); |
| 13204 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 13205 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 13206 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 13207 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 13208 | HostPortPair::FromString("myproxy:70")), |
| 13209 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13210 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 13211 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 13212 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13213 | |
| 13214 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13215 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13216 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 13217 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13218 | } |
| 13219 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13220 | // Test a basic HTTPS GET request through a proxy, connecting to an IPv6 |
| 13221 | // literal host. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13222 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetIPv6) { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13223 | session_deps_.proxy_service = |
| 13224 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
| 13225 | BoundTestNetLog log; |
| 13226 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13227 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13228 | |
| 13229 | HttpRequestInfo request; |
| 13230 | request.method = "GET"; |
| 13231 | request.url = GURL("https://[::1]:443/"); |
| 13232 | |
| 13233 | // Since we have proxy, should try to establish tunnel. |
| 13234 | MockWrite data_writes1[] = { |
| 13235 | MockWrite("CONNECT [::1]:443 HTTP/1.1\r\n" |
| 13236 | "Host: [::1]:443\r\n" |
| 13237 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 13238 | |
| 13239 | MockWrite("GET / HTTP/1.1\r\n" |
| 13240 | "Host: [::1]\r\n" |
| 13241 | "Connection: keep-alive\r\n\r\n"), |
| 13242 | }; |
| 13243 | |
| 13244 | MockRead data_reads1[] = { |
| 13245 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 13246 | |
| 13247 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13248 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 13249 | MockRead("Content-Length: 100\r\n\r\n"), |
| 13250 | MockRead(SYNCHRONOUS, OK), |
| 13251 | }; |
| 13252 | |
| 13253 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 13254 | data_writes1, arraysize(data_writes1)); |
| 13255 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 13256 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 13257 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 13258 | |
| 13259 | TestCompletionCallback callback1; |
| 13260 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13261 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13262 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13263 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13264 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13265 | |
| 13266 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13267 | EXPECT_THAT(rv, IsOk()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13268 | TestNetLogEntry::List entries; |
| 13269 | log.GetEntries(&entries); |
| 13270 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13271 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 13272 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13273 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13274 | entries, pos, |
| 13275 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 13276 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13277 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13278 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13279 | ASSERT_TRUE(response); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13280 | |
| 13281 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 13282 | EXPECT_EQ(200, response->headers->response_code()); |
| 13283 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 13284 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 13285 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 13286 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 13287 | HostPortPair::FromString("myproxy:70")), |
| 13288 | response->proxy_server); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13289 | |
| 13290 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13291 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13292 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 13293 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 13294 | } |
| 13295 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13296 | // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 13297 | // while establishing the tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13298 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 13299 | session_deps_.proxy_service = ProxyService::CreateFixed("myproxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13300 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13301 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13302 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13303 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13304 | HttpRequestInfo request; |
| 13305 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13306 | request.url = GURL("https://www.example.org/"); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13307 | |
| 13308 | // Since we have proxy, should try to establish tunnel. |
| 13309 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13310 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 13311 | "Host: www.example.org:443\r\n" |
| 13312 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13313 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13314 | MockWrite("GET / HTTP/1.1\r\n" |
| 13315 | "Host: www.example.org\r\n" |
| 13316 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13317 | }; |
| 13318 | |
| 13319 | MockRead data_reads1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13320 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13321 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13322 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13323 | }; |
| 13324 | |
| 13325 | StaticSocketDataProvider data1(data_reads1, arraysize(data_reads1), |
| 13326 | data_writes1, arraysize(data_writes1)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13327 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13328 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13329 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13330 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13331 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13332 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13333 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13334 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13335 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13336 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13337 | |
| 13338 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13339 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 13340 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 13341 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13342 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13343 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 13344 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13345 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 13346 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13347 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 13348 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13349 | } |
| 13350 | |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13351 | // Test for crbug.com/55424. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13352 | TEST_F(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13353 | SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13354 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13355 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13356 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13357 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13358 | SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13359 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13360 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13361 | }; |
| 13362 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13363 | SequencedSocketData spdy_data(spdy_reads, arraysize(spdy_reads), spdy_writes, |
| 13364 | arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13365 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13366 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13367 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13368 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13369 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13370 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13371 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13372 | |
| 13373 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13374 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 13375 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 13376 | PRIVACY_MODE_DISABLED); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13377 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 13378 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13379 | |
| 13380 | HttpRequestInfo request; |
| 13381 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13382 | request.url = GURL("https://www.example.org/"); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13383 | |
| 13384 | // This is the important line that marks this as a preconnect. |
| 13385 | request.motivation = HttpRequestInfo::PRECONNECT_MOTIVATED; |
| 13386 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13387 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13388 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 13389 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13390 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13391 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13392 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 13393 | } |
| 13394 | |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13395 | // Given a net error, cause that error to be returned from the first Write() |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13396 | // call and verify that the HttpNetworkTransaction fails with that error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 13397 | void HttpNetworkTransactionTest::CheckErrorIsPassedBack( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13398 | int error, IoMode mode) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13399 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13400 | request_info.url = GURL("https://www.example.com/"); |
| 13401 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13402 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13403 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13404 | SSLSocketDataProvider ssl_data(mode, OK); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13405 | MockWrite data_writes[] = { |
| 13406 | MockWrite(mode, error), |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13407 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13408 | StaticSocketDataProvider data(NULL, 0, data_writes, arraysize(data_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13409 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13410 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13411 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13412 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13413 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13414 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13415 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13416 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13417 | if (rv == ERR_IO_PENDING) |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13418 | rv = callback.WaitForResult(); |
| 13419 | ASSERT_EQ(error, rv); |
| 13420 | } |
| 13421 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13422 | TEST_F(HttpNetworkTransactionTest, SSLWriteCertError) { |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13423 | // Just check a grab bag of cert errors. |
| 13424 | static const int kErrors[] = { |
| 13425 | ERR_CERT_COMMON_NAME_INVALID, |
| 13426 | ERR_CERT_AUTHORITY_INVALID, |
| 13427 | ERR_CERT_DATE_INVALID, |
| 13428 | }; |
| 13429 | for (size_t i = 0; i < arraysize(kErrors); i++) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13430 | CheckErrorIsPassedBack(kErrors[i], ASYNC); |
| 13431 | CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 13432 | } |
| 13433 | } |
| 13434 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13435 | // Ensure that a client certificate is removed from the SSL client auth |
| 13436 | // cache when: |
| 13437 | // 1) No proxy is involved. |
| 13438 | // 2) TLS False Start is disabled. |
| 13439 | // 3) The initial TLS handshake requests a client certificate. |
| 13440 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13441 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_NoFalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13442 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13443 | request_info.url = GURL("https://www.example.com/"); |
| 13444 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13445 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13446 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13447 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13448 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13449 | |
| 13450 | // [ssl_]data1 contains the data for the first SSL handshake. When a |
| 13451 | // CertificateRequest is received for the first time, the handshake will |
| 13452 | // be aborted to allow the caller to provide a certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13453 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13454 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13455 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13456 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13457 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13458 | |
| 13459 | // [ssl_]data2 contains the data for the second SSL handshake. When TLS |
| 13460 | // False Start is not being used, the result of the SSL handshake will be |
| 13461 | // returned as part of the SSLClientSocket::Connect() call. This test |
| 13462 | // matches the result of a server sending a handshake_failure alert, |
| 13463 | // rather than a Finished message, because it requires a client |
| 13464 | // certificate and none was supplied. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13465 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13466 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13467 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13468 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13469 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13470 | |
| 13471 | // [ssl_]data3 contains the data for the third SSL handshake. When a |
| 13472 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 13473 | // HttpNetworkTransaction will attempt to fallback to TLSv1.1 if the previous |
| 13474 | // connection was attempted with TLSv1.2. This is transparent to the caller |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13475 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 13476 | // requiring a client certificate, this fallback handshake should also |
| 13477 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13478 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13479 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13480 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13481 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13482 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13483 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13484 | // [ssl_]data4 contains the data for the fourth SSL handshake. When a |
| 13485 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 13486 | // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous |
| 13487 | // connection was attempted with TLSv1.1. This is transparent to the caller |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13488 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 13489 | // requiring a client certificate, this fallback handshake should also |
| 13490 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13491 | SSLSocketDataProvider ssl_data4(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13492 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13493 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13494 | StaticSocketDataProvider data4(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13495 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13496 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13497 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13498 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13499 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13500 | // Begin the SSL handshake with the peer. This consumes ssl_data1. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13501 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13502 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13503 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13504 | |
| 13505 | // Complete the SSL handshake, which should abort due to requiring a |
| 13506 | // client certificate. |
| 13507 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13508 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13509 | |
| 13510 | // Indicate that no certificate should be supplied. From the perspective |
| 13511 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 13512 | // certificate, so this is the same as supply a |
| 13513 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13514 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13515 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13516 | |
| 13517 | // Ensure the certificate was added to the client auth cache before |
| 13518 | // allowing the connection to continue restarting. |
| 13519 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13520 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13521 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13522 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13523 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13524 | |
| 13525 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13526 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 13527 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13528 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13529 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13530 | |
| 13531 | // Ensure that the client certificate is removed from the cache on a |
| 13532 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13533 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13534 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13535 | } |
| 13536 | |
| 13537 | // Ensure that a client certificate is removed from the SSL client auth |
| 13538 | // cache when: |
| 13539 | // 1) No proxy is involved. |
| 13540 | // 2) TLS False Start is enabled. |
| 13541 | // 3) The initial TLS handshake requests a client certificate. |
| 13542 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13543 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_FalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13544 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13545 | request_info.url = GURL("https://www.example.com/"); |
| 13546 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13547 | request_info.load_flags = LOAD_NORMAL; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13548 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13549 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13550 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13551 | |
| 13552 | // When TLS False Start is used, SSLClientSocket::Connect() calls will |
| 13553 | // return successfully after reading up to the peer's Certificate message. |
| 13554 | // This is to allow the caller to call SSLClientSocket::Write(), which can |
| 13555 | // enqueue application data to be sent in the same packet as the |
| 13556 | // ChangeCipherSpec and Finished messages. |
| 13557 | // The actual handshake will be finished when SSLClientSocket::Read() is |
| 13558 | // called, which expects to process the peer's ChangeCipherSpec and |
| 13559 | // Finished messages. If there was an error negotiating with the peer, |
| 13560 | // such as due to the peer requiring a client certificate when none was |
| 13561 | // supplied, the alert sent by the peer won't be processed until Read() is |
| 13562 | // called. |
| 13563 | |
| 13564 | // Like the non-False Start case, when a client certificate is requested by |
| 13565 | // the peer, the handshake is aborted during the Connect() call. |
| 13566 | // [ssl_]data1 represents the initial SSL handshake with the peer. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13567 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13568 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13569 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13570 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13571 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13572 | |
| 13573 | // When a client certificate is supplied, Connect() will not be aborted |
| 13574 | // when the peer requests the certificate. Instead, the handshake will |
| 13575 | // artificially succeed, allowing the caller to write the HTTP request to |
| 13576 | // the socket. The handshake messages are not processed until Read() is |
| 13577 | // called, which then detects that the handshake was aborted, due to the |
| 13578 | // peer sending a handshake_failure because it requires a client |
| 13579 | // certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13580 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13581 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13582 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13583 | MockRead data2_reads[] = { |
| 13584 | MockRead(ASYNC /* async */, ERR_SSL_PROTOCOL_ERROR), |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13585 | }; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13586 | StaticSocketDataProvider data2(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13587 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13588 | |
| 13589 | // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13590 | // the data for the SSL handshake once the TLSv1.1 connection falls back to |
| 13591 | // TLSv1. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13592 | SSLSocketDataProvider ssl_data3(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13593 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13594 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13595 | StaticSocketDataProvider data3(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13596 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13597 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13598 | // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection |
| 13599 | // falls back to SSLv3. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13600 | SSLSocketDataProvider ssl_data4(ASYNC, OK); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13601 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13602 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13603 | StaticSocketDataProvider data4(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13604 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13605 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 13606 | // Need one more if TLSv1.2 is enabled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13607 | SSLSocketDataProvider ssl_data5(ASYNC, OK); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 13608 | ssl_data5.cert_request_info = cert_request.get(); |
| 13609 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13610 | StaticSocketDataProvider data5(data2_reads, arraysize(data2_reads), NULL, 0); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 13611 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 13612 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13613 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13614 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13615 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13616 | // Begin the initial SSL handshake. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13617 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13618 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13619 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13620 | |
| 13621 | // Complete the SSL handshake, which should abort due to requiring a |
| 13622 | // client certificate. |
| 13623 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13624 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13625 | |
| 13626 | // Indicate that no certificate should be supplied. From the perspective |
| 13627 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 13628 | // certificate, so this is the same as supply a |
| 13629 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13630 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13631 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13632 | |
| 13633 | // Ensure the certificate was added to the client auth cache before |
| 13634 | // allowing the connection to continue restarting. |
| 13635 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13636 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13637 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13638 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13639 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13640 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13641 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13642 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 13643 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13644 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13645 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13646 | |
| 13647 | // Ensure that the client certificate is removed from the cache on a |
| 13648 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13649 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13650 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 13651 | } |
| 13652 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13653 | // Ensure that a client certificate is removed from the SSL client auth |
| 13654 | // cache when: |
| 13655 | // 1) An HTTPS proxy is involved. |
| 13656 | // 3) The HTTPS proxy requests a client certificate. |
| 13657 | // 4) The client supplies an invalid/unacceptable certificate for the |
| 13658 | // proxy. |
| 13659 | // The test is repeated twice, first for connecting to an HTTPS endpoint, |
| 13660 | // then for connecting to an HTTP endpoint. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13661 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) { |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 13662 | session_deps_.proxy_service = ProxyService::CreateFixed("https://proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13663 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13664 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13665 | |
| 13666 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13667 | cert_request->host_and_port = HostPortPair("proxy", 70); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13668 | |
| 13669 | // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of |
| 13670 | // [ssl_]data[1-3]. Rather than represending the endpoint |
| 13671 | // (www.example.com:443), they represent failures with the HTTPS proxy |
| 13672 | // (proxy:70). |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13673 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13674 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13675 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13676 | StaticSocketDataProvider data1(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13677 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13678 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13679 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13680 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13681 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13682 | StaticSocketDataProvider data2(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13683 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13684 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13685 | // TODO(wtc): find out why this unit test doesn't need [ssl_]data3. |
| 13686 | #if 0 |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13687 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13688 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13689 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13690 | StaticSocketDataProvider data3(NULL, 0, NULL, 0); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13691 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 13692 | #endif |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13693 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13694 | HttpRequestInfo requests[2]; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13695 | requests[0].url = GURL("https://www.example.com/"); |
| 13696 | requests[0].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13697 | requests[0].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13698 | |
| 13699 | requests[1].url = GURL("http://www.example.com/"); |
| 13700 | requests[1].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 13701 | requests[1].load_flags = LOAD_NORMAL; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13702 | |
| 13703 | for (size_t i = 0; i < arraysize(requests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13704 | session_deps_.socket_factory->ResetNextMockIndexes(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13705 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13706 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13707 | |
| 13708 | // Begin the SSL handshake with the proxy. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13709 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13710 | int rv = trans.Start(&requests[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13711 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13712 | |
| 13713 | // Complete the SSL handshake, which should abort due to requiring a |
| 13714 | // client certificate. |
| 13715 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13716 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13717 | |
| 13718 | // Indicate that no certificate should be supplied. From the perspective |
| 13719 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 13720 | // certificate, so this is the same as supply a |
| 13721 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13722 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13723 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13724 | |
| 13725 | // Ensure the certificate was added to the client auth cache before |
| 13726 | // allowing the connection to continue restarting. |
| 13727 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13728 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13729 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13730 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13731 | ASSERT_FALSE(client_cert); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13732 | // Ensure the certificate was NOT cached for the endpoint. This only |
| 13733 | // applies to HTTPS requests, but is fine to check for HTTP requests. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13734 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13735 | HostPortPair("www.example.com", 443), &client_cert, |
| 13736 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13737 | |
| 13738 | // Restart the handshake. This will consume ssl_data2, which fails, and |
| 13739 | // then consume ssl_data3, which should also fail. The result code is |
| 13740 | // checked against what ssl_data3 should return. |
| 13741 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13742 | ASSERT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13743 | |
| 13744 | // Now that the new handshake has failed, ensure that the client |
| 13745 | // certificate was removed from the client auth cache. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13746 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13747 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 13748 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 13749 | HostPortPair("www.example.com", 443), &client_cert, |
| 13750 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 13751 | } |
| 13752 | } |
| 13753 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13754 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPooling) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13755 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13756 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13757 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13758 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13759 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13760 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13761 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13762 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13763 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13764 | SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13765 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13766 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13767 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13768 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13769 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13770 | SpdySerializedFrame host1_resp_body( |
| 13771 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13772 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13773 | SpdySerializedFrame host2_resp_body( |
| 13774 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13775 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13776 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 13777 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13778 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13779 | }; |
| 13780 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 13781 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13782 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13783 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 13784 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13785 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13786 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 13787 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13788 | HttpRequestInfo request1; |
| 13789 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13790 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13791 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13792 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13793 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13794 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13795 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13796 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13797 | |
| 13798 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13799 | ASSERT_TRUE(response); |
| 13800 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13801 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13802 | |
| 13803 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13804 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13805 | EXPECT_EQ("hello!", response_data); |
| 13806 | |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13807 | // Preload mail.example.com into HostCache. |
| 13808 | HostPortPair host_port("mail.example.com", 443); |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 13809 | HostResolver::RequestInfo resolve_info(host_port); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13810 | AddressList ignored; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 13811 | std::unique_ptr<HostResolver::Request> request; |
| 13812 | rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 13813 | &ignored, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13814 | &request, NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13815 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 13816 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13817 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13818 | |
| 13819 | HttpRequestInfo request2; |
| 13820 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13821 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13822 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13823 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13824 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13825 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13826 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13827 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13828 | |
| 13829 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13830 | ASSERT_TRUE(response); |
| 13831 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13832 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13833 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13834 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13835 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13836 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 13837 | } |
| 13838 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13839 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) { |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13840 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13841 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13842 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13843 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13844 | AddSSLSocketData(); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13845 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13846 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 13847 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 13848 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13849 | SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13850 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13851 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13852 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13853 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13854 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13855 | SpdySerializedFrame host1_resp_body( |
| 13856 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 13857 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13858 | SpdySerializedFrame host2_resp_body( |
| 13859 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13860 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13861 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 13862 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13863 | MockRead(ASYNC, 0, 6), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13864 | }; |
| 13865 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 13866 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13867 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13868 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 13869 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13870 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13871 | |
| 13872 | TestCompletionCallback callback; |
| 13873 | HttpRequestInfo request1; |
| 13874 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13875 | request1.url = GURL("https://www.example.org/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13876 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13877 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13878 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13879 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13880 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13881 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13882 | |
| 13883 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13884 | ASSERT_TRUE(response); |
| 13885 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13886 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13887 | |
| 13888 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13889 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13890 | EXPECT_EQ("hello!", response_data); |
| 13891 | |
| 13892 | HttpRequestInfo request2; |
| 13893 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 13894 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13895 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13896 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13897 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13898 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13899 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13900 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13901 | |
| 13902 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13903 | ASSERT_TRUE(response); |
| 13904 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13905 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13906 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13907 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13908 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13909 | EXPECT_EQ("hello!", response_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 13910 | } |
| 13911 | |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 13912 | // Regression test for https://crbug.com/546991. |
| 13913 | // The server might not be able to serve an IP pooled request, and might send a |
| 13914 | // 421 Misdirected Request response status to indicate this. |
| 13915 | // HttpNetworkTransaction should reset the request and retry without IP pooling. |
| 13916 | TEST_F(HttpNetworkTransactionTest, RetryWithoutConnectionPooling) { |
| 13917 | // Two hosts resolve to the same IP address. |
| 13918 | const std::string ip_addr = "1.2.3.4"; |
| 13919 | IPAddress ip; |
| 13920 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 13921 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 13922 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13923 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 13924 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 13925 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 13926 | |
| 13927 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13928 | |
| 13929 | // Two requests on the first connection. |
| 13930 | SpdySerializedFrame req1( |
| 13931 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 13932 | spdy_util_.UpdateWithStreamDestruction(1); |
| 13933 | SpdySerializedFrame req2( |
| 13934 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
| 13935 | SpdySerializedFrame rst( |
| 13936 | spdy_util_.ConstructSpdyRstStream(3, ERROR_CODE_CANCEL)); |
| 13937 | MockWrite writes1[] = { |
| 13938 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 13939 | CreateMockWrite(rst, 6), |
| 13940 | }; |
| 13941 | |
| 13942 | // The first one succeeds, the second gets error 421 Misdirected Request. |
| 13943 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 13944 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 13945 | SpdyHeaderBlock response_headers; |
| 13946 | response_headers[SpdyTestUtil::GetStatusKey()] = "421"; |
| 13947 | SpdySerializedFrame resp2( |
| 13948 | spdy_util_.ConstructSpdyReply(3, std::move(response_headers))); |
| 13949 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 13950 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 13951 | |
| 13952 | MockConnect connect1(ASYNC, OK, peer_addr); |
| 13953 | SequencedSocketData data1(connect1, reads1, arraysize(reads1), writes1, |
| 13954 | arraysize(writes1)); |
| 13955 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 13956 | |
| 13957 | AddSSLSocketData(); |
| 13958 | |
| 13959 | // Retry the second request on a second connection. |
| 13960 | SpdyTestUtil spdy_util2; |
| 13961 | SpdySerializedFrame req3( |
| 13962 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 13963 | MockWrite writes2[] = { |
| 13964 | CreateMockWrite(req3, 0), |
| 13965 | }; |
| 13966 | |
| 13967 | SpdySerializedFrame resp3(spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 13968 | SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 13969 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 13970 | MockRead(ASYNC, 0, 3)}; |
| 13971 | |
| 13972 | MockConnect connect2(ASYNC, OK, peer_addr); |
| 13973 | SequencedSocketData data2(connect2, reads2, arraysize(reads2), writes2, |
| 13974 | arraysize(writes2)); |
| 13975 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 13976 | |
| 13977 | AddSSLSocketData(); |
| 13978 | |
| 13979 | // Preload mail.example.org into HostCache. |
| 13980 | HostPortPair host_port("mail.example.org", 443); |
| 13981 | HostResolver::RequestInfo resolve_info(host_port); |
| 13982 | AddressList ignored; |
| 13983 | std::unique_ptr<HostResolver::Request> request; |
| 13984 | TestCompletionCallback callback; |
| 13985 | int rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 13986 | &ignored, callback.callback(), |
| 13987 | &request, NetLogWithSource()); |
| 13988 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13989 | rv = callback.WaitForResult(); |
| 13990 | EXPECT_THAT(rv, IsOk()); |
| 13991 | |
| 13992 | HttpRequestInfo request1; |
| 13993 | request1.method = "GET"; |
| 13994 | request1.url = GURL("https://www.example.org/"); |
| 13995 | request1.load_flags = 0; |
| 13996 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 13997 | |
| 13998 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 13999 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14000 | rv = callback.WaitForResult(); |
| 14001 | EXPECT_THAT(rv, IsOk()); |
| 14002 | |
| 14003 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 14004 | ASSERT_TRUE(response); |
| 14005 | ASSERT_TRUE(response->headers); |
| 14006 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 14007 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 14008 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 14009 | std::string response_data; |
| 14010 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 14011 | EXPECT_EQ("hello!", response_data); |
| 14012 | |
| 14013 | HttpRequestInfo request2; |
| 14014 | request2.method = "GET"; |
| 14015 | request2.url = GURL("https://mail.example.org/"); |
| 14016 | request2.load_flags = 0; |
| 14017 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 14018 | |
| 14019 | BoundTestNetLog log; |
| 14020 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 14021 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14022 | rv = callback.WaitForResult(); |
| 14023 | EXPECT_THAT(rv, IsOk()); |
| 14024 | |
| 14025 | response = trans2.GetResponseInfo(); |
| 14026 | ASSERT_TRUE(response); |
| 14027 | ASSERT_TRUE(response->headers); |
| 14028 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 14029 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 14030 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 14031 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 14032 | EXPECT_EQ("hello!", response_data); |
| 14033 | |
| 14034 | TestNetLogEntry::List entries; |
| 14035 | log.GetEntries(&entries); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14036 | ExpectLogContainsSomewhere( |
| 14037 | entries, 0, NetLogEventType::HTTP_TRANSACTION_RESTART_MISDIRECTED_REQUEST, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14038 | NetLogEventPhase::NONE); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14039 | } |
| 14040 | |
| 14041 | // Test that HTTP 421 responses are properly returned to the caller if received |
| 14042 | // on the retry as well. HttpNetworkTransaction should not infinite loop or lose |
| 14043 | // portions of the response. |
| 14044 | TEST_F(HttpNetworkTransactionTest, ReturnHTTP421OnRetry) { |
| 14045 | // Two hosts resolve to the same IP address. |
| 14046 | const std::string ip_addr = "1.2.3.4"; |
| 14047 | IPAddress ip; |
| 14048 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 14049 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 14050 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14051 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14052 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 14053 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 14054 | |
| 14055 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14056 | |
| 14057 | // Two requests on the first connection. |
| 14058 | SpdySerializedFrame req1( |
| 14059 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 14060 | spdy_util_.UpdateWithStreamDestruction(1); |
| 14061 | SpdySerializedFrame req2( |
| 14062 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
| 14063 | SpdySerializedFrame rst( |
| 14064 | spdy_util_.ConstructSpdyRstStream(3, ERROR_CODE_CANCEL)); |
| 14065 | MockWrite writes1[] = { |
| 14066 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 14067 | CreateMockWrite(rst, 6), |
| 14068 | }; |
| 14069 | |
| 14070 | // The first one succeeds, the second gets error 421 Misdirected Request. |
| 14071 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 14072 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 14073 | SpdyHeaderBlock response_headers; |
| 14074 | response_headers[SpdyTestUtil::GetStatusKey()] = "421"; |
| 14075 | SpdySerializedFrame resp2( |
| 14076 | spdy_util_.ConstructSpdyReply(3, response_headers.Clone())); |
| 14077 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 14078 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 14079 | |
| 14080 | MockConnect connect1(ASYNC, OK, peer_addr); |
| 14081 | SequencedSocketData data1(connect1, reads1, arraysize(reads1), writes1, |
| 14082 | arraysize(writes1)); |
| 14083 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 14084 | |
| 14085 | AddSSLSocketData(); |
| 14086 | |
| 14087 | // Retry the second request on a second connection. It returns 421 Misdirected |
| 14088 | // Retry again. |
| 14089 | SpdyTestUtil spdy_util2; |
| 14090 | SpdySerializedFrame req3( |
| 14091 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 14092 | MockWrite writes2[] = { |
| 14093 | CreateMockWrite(req3, 0), |
| 14094 | }; |
| 14095 | |
| 14096 | SpdySerializedFrame resp3( |
| 14097 | spdy_util2.ConstructSpdyReply(1, std::move(response_headers))); |
| 14098 | SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 14099 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 14100 | MockRead(ASYNC, 0, 3)}; |
| 14101 | |
| 14102 | MockConnect connect2(ASYNC, OK, peer_addr); |
| 14103 | SequencedSocketData data2(connect2, reads2, arraysize(reads2), writes2, |
| 14104 | arraysize(writes2)); |
| 14105 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 14106 | |
| 14107 | AddSSLSocketData(); |
| 14108 | |
| 14109 | // Preload mail.example.org into HostCache. |
| 14110 | HostPortPair host_port("mail.example.org", 443); |
| 14111 | HostResolver::RequestInfo resolve_info(host_port); |
| 14112 | AddressList ignored; |
| 14113 | std::unique_ptr<HostResolver::Request> request; |
| 14114 | TestCompletionCallback callback; |
| 14115 | int rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 14116 | &ignored, callback.callback(), |
| 14117 | &request, NetLogWithSource()); |
| 14118 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14119 | rv = callback.WaitForResult(); |
| 14120 | EXPECT_THAT(rv, IsOk()); |
| 14121 | |
| 14122 | HttpRequestInfo request1; |
| 14123 | request1.method = "GET"; |
| 14124 | request1.url = GURL("https://www.example.org/"); |
| 14125 | request1.load_flags = 0; |
| 14126 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 14127 | |
| 14128 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 14129 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14130 | rv = callback.WaitForResult(); |
| 14131 | EXPECT_THAT(rv, IsOk()); |
| 14132 | |
| 14133 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 14134 | ASSERT_TRUE(response); |
| 14135 | ASSERT_TRUE(response->headers); |
| 14136 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 14137 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 14138 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 14139 | std::string response_data; |
| 14140 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 14141 | EXPECT_EQ("hello!", response_data); |
| 14142 | |
| 14143 | HttpRequestInfo request2; |
| 14144 | request2.method = "GET"; |
| 14145 | request2.url = GURL("https://mail.example.org/"); |
| 14146 | request2.load_flags = 0; |
| 14147 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 14148 | |
| 14149 | BoundTestNetLog log; |
| 14150 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 14151 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14152 | rv = callback.WaitForResult(); |
| 14153 | EXPECT_THAT(rv, IsOk()); |
| 14154 | |
| 14155 | // After a retry, the 421 Misdirected Request is reported back up to the |
| 14156 | // caller. |
| 14157 | response = trans2.GetResponseInfo(); |
| 14158 | ASSERT_TRUE(response); |
| 14159 | ASSERT_TRUE(response->headers); |
| 14160 | EXPECT_EQ("HTTP/1.1 421", response->headers->GetStatusLine()); |
| 14161 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 14162 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 14163 | EXPECT_TRUE(response->ssl_info.cert); |
| 14164 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 14165 | EXPECT_EQ("hello!", response_data); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14166 | } |
| 14167 | |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 14168 | class OneTimeCachingHostResolver : public MockHostResolverBase { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14169 | public: |
| 14170 | explicit OneTimeCachingHostResolver(const HostPortPair& host_port) |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 14171 | : MockHostResolverBase(/* use_caching = */ true), host_port_(host_port) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14172 | ~OneTimeCachingHostResolver() override {} |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14173 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14174 | int ResolveFromCache(const RequestInfo& info, |
| 14175 | AddressList* addresses, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14176 | const NetLogWithSource& net_log) override { |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 14177 | int rv = MockHostResolverBase::ResolveFromCache(info, addresses, net_log); |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 14178 | if (rv == OK && info.host_port_pair().Equals(host_port_)) |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 14179 | GetHostCache()->clear(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14180 | return rv; |
| 14181 | } |
| 14182 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14183 | private: |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14184 | const HostPortPair host_port_; |
| 14185 | }; |
| 14186 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14187 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 14188 | UseIPConnectionPoolingWithHostCacheExpiration) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14189 | // Set up a special HttpNetworkSession with a OneTimeCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14190 | session_deps_.host_resolver = std::make_unique<OneTimeCachingHostResolver>( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14191 | HostPortPair("mail.example.com", 443)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14192 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14193 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 14194 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14195 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14196 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14197 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14198 | spdy_util_.UpdateWithStreamDestruction(1); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14199 | SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14200 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14201 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14202 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14203 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14204 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14205 | SpdySerializedFrame host1_resp_body( |
| 14206 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14207 | SpdySerializedFrame host2_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14208 | SpdySerializedFrame host2_resp_body( |
| 14209 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14210 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14211 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 14212 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14213 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14214 | }; |
| 14215 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 14216 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14217 | MockConnect connect(ASYNC, OK, peer_addr); |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14218 | SequencedSocketData spdy_data(connect, spdy_reads, arraysize(spdy_reads), |
| 14219 | spdy_writes, arraysize(spdy_writes)); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14220 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14221 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 14222 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14223 | HttpRequestInfo request1; |
| 14224 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14225 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14226 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14227 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14228 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14229 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14230 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14231 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14232 | |
| 14233 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14234 | ASSERT_TRUE(response); |
| 14235 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14236 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14237 | |
| 14238 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14239 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14240 | EXPECT_EQ("hello!", response_data); |
| 14241 | |
| 14242 | // Preload cache entries into HostCache. |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14243 | HostResolver::RequestInfo resolve_info(HostPortPair("mail.example.com", 443)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14244 | AddressList ignored; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 14245 | std::unique_ptr<HostResolver::Request> request; |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 14246 | rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 14247 | &ignored, callback.callback(), |
| 14248 | &request, NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14249 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 14250 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14251 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14252 | |
| 14253 | HttpRequestInfo request2; |
| 14254 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14255 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14256 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14257 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14258 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14259 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14260 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14261 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14262 | |
| 14263 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14264 | ASSERT_TRUE(response); |
| 14265 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14266 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14267 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14268 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14269 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14270 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14271 | } |
| 14272 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14273 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14274 | const std::string https_url = "https://www.example.org:8080/"; |
| 14275 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14276 | |
| 14277 | // SPDY GET for HTTPS URL |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14278 | SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14279 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14280 | |
| 14281 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14282 | CreateMockWrite(req1, 0), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14283 | }; |
| 14284 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14285 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14286 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 14287 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 14288 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3)}; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14289 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14290 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 14291 | arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14292 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 14293 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14294 | |
| 14295 | // HTTP GET for the HTTP URL |
| 14296 | MockWrite writes2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14297 | MockWrite(ASYNC, 0, |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 14298 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14299 | "Host: www.example.org:8080\r\n" |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 14300 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14301 | }; |
| 14302 | |
| 14303 | MockRead reads2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14304 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 14305 | MockRead(ASYNC, 2, "hello"), |
| 14306 | MockRead(ASYNC, OK, 3), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14307 | }; |
| 14308 | |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14309 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 14310 | arraysize(writes2)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14311 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14312 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14313 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14314 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14315 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 14316 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14317 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14318 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14319 | |
| 14320 | // Start the first transaction to set up the SpdySession |
| 14321 | HttpRequestInfo request1; |
| 14322 | request1.method = "GET"; |
| 14323 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14324 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14325 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14326 | TestCompletionCallback callback1; |
| 14327 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14328 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 14329 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14330 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14331 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14332 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 14333 | |
| 14334 | // Now, start the HTTP request |
| 14335 | HttpRequestInfo request2; |
| 14336 | request2.method = "GET"; |
| 14337 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14338 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14339 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14340 | TestCompletionCallback callback2; |
| 14341 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14342 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 14343 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14344 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14345 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14346 | EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 14347 | } |
| 14348 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14349 | // Alternative service requires HTTP/2 (or SPDY), but HTTP/1.1 is negotiated |
| 14350 | // with the alternative server. That connection should not be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14351 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceNotOnHttp11) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14352 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 14353 | HostPortPair alternative("www.example.org", 444); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14354 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14355 | // Negotiate HTTP/1.1 with alternative. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14356 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14357 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14358 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14359 | |
| 14360 | // No data should be read from the alternative, because HTTP/1.1 is |
| 14361 | // negotiated. |
| 14362 | StaticSocketDataProvider data; |
| 14363 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14364 | |
| 14365 | // 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] | 14366 | // negotiated. In order to test this, a failed connection to the server is |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14367 | // mocked. This way the request relies on the alternate Job. |
| 14368 | StaticSocketDataProvider data_refused; |
| 14369 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 14370 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 14371 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14372 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14373 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 14374 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14375 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 14376 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 14377 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 14378 | http_server_properties->SetHttp2AlternativeService( |
| 14379 | server, alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14380 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14381 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 14382 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14383 | request.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14384 | request.url = GURL("https://www.example.org:443"); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14385 | TestCompletionCallback callback; |
| 14386 | |
| 14387 | // HTTP/2 (or SPDY) is required for alternative service, if HTTP/1.1 is |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14388 | // negotiated, the alternate Job should fail with ERR_ALPN_NEGOTIATION_FAILED. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14389 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14390 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_ALPN_NEGOTIATION_FAILED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14391 | } |
| 14392 | |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14393 | // 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] | 14394 | // server, and an alternate one to the alternative server. If the former |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14395 | // succeeds, the request should succeed, even if the latter fails because |
| 14396 | // HTTP/1.1 is negotiated which is insufficient for alternative service. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14397 | TEST_F(HttpNetworkTransactionTest, FailedAlternativeServiceIsNotUserVisible) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14398 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 14399 | HostPortPair alternative("www.example.org", 444); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14400 | |
| 14401 | // Negotiate HTTP/1.1 with alternative. |
| 14402 | SSLSocketDataProvider alternative_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14403 | alternative_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14404 | session_deps_.socket_factory->AddSSLSocketDataProvider(&alternative_ssl); |
| 14405 | |
| 14406 | // No data should be read from the alternative, because HTTP/1.1 is |
| 14407 | // negotiated. |
| 14408 | StaticSocketDataProvider data; |
| 14409 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14410 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14411 | // Negotiate HTTP/1.1 with server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14412 | SSLSocketDataProvider origin_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14413 | origin_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14414 | session_deps_.socket_factory->AddSSLSocketDataProvider(&origin_ssl); |
| 14415 | |
| 14416 | MockWrite http_writes[] = { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14417 | MockWrite("GET / HTTP/1.1\r\n" |
| 14418 | "Host: www.example.org\r\n" |
| 14419 | "Connection: keep-alive\r\n\r\n"), |
| 14420 | MockWrite("GET /second HTTP/1.1\r\n" |
| 14421 | "Host: www.example.org\r\n" |
| 14422 | "Connection: keep-alive\r\n\r\n"), |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14423 | }; |
| 14424 | |
| 14425 | MockRead http_reads[] = { |
| 14426 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14427 | MockRead("Content-Type: text/html\r\n"), |
| 14428 | MockRead("Content-Length: 6\r\n\r\n"), |
| 14429 | MockRead("foobar"), |
| 14430 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14431 | MockRead("Content-Type: text/html\r\n"), |
| 14432 | MockRead("Content-Length: 7\r\n\r\n"), |
| 14433 | MockRead("another"), |
| 14434 | }; |
| 14435 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 14436 | http_writes, arraysize(http_writes)); |
| 14437 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 14438 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14439 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14440 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 14441 | HttpServerProperties* http_server_properties = |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14442 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 14443 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 14444 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 14445 | http_server_properties->SetHttp2AlternativeService( |
| 14446 | server, alternative_service, expiration); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14447 | |
| 14448 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 14449 | HttpRequestInfo request1; |
| 14450 | request1.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14451 | request1.url = GURL("https://www.example.org:443"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14452 | request1.load_flags = 0; |
| 14453 | TestCompletionCallback callback1; |
| 14454 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14455 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14456 | rv = callback1.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14457 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14458 | |
| 14459 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14460 | ASSERT_TRUE(response1); |
| 14461 | ASSERT_TRUE(response1->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14462 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 14463 | |
| 14464 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14465 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14466 | EXPECT_EQ("foobar", response_data1); |
| 14467 | |
| 14468 | // Alternative should be marked as broken, because HTTP/1.1 is not sufficient |
| 14469 | // for alternative service. |
| 14470 | EXPECT_TRUE( |
| 14471 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
| 14472 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14473 | // Since |alternative_service| is broken, a second transaction to server |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14474 | // should not start an alternate Job. It should pool to existing connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14475 | // to server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14476 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 14477 | HttpRequestInfo request2; |
| 14478 | request2.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 14479 | request2.url = GURL("https://www.example.org:443/second"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14480 | request2.load_flags = 0; |
| 14481 | TestCompletionCallback callback2; |
| 14482 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14483 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14484 | rv = callback2.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14485 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14486 | |
| 14487 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14488 | ASSERT_TRUE(response2); |
| 14489 | ASSERT_TRUE(response2->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14490 | EXPECT_EQ("HTTP/1.1 200 OK", response2->headers->GetStatusLine()); |
| 14491 | |
| 14492 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14493 | ASSERT_THAT(ReadTransaction(&trans2, &response_data2), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 14494 | EXPECT_EQ("another", response_data2); |
| 14495 | } |
| 14496 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14497 | // Alternative service requires HTTP/2 (or SPDY), but there is already a |
| 14498 | // HTTP/1.1 socket open to the alternative server. That socket should not be |
| 14499 | // used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14500 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceShouldNotPoolToHttp11) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14501 | url::SchemeHostPort server("https", "origin.example.org", 443); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14502 | HostPortPair alternative("alternative.example.org", 443); |
| 14503 | std::string origin_url = "https://origin.example.org:443"; |
| 14504 | std::string alternative_url = "https://alternative.example.org:443"; |
| 14505 | |
| 14506 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 14507 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14508 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14509 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14510 | |
| 14511 | // HTTP/1.1 data for |request1| and |request2|. |
| 14512 | MockWrite http_writes[] = { |
| 14513 | MockWrite( |
| 14514 | "GET / HTTP/1.1\r\n" |
| 14515 | "Host: alternative.example.org\r\n" |
| 14516 | "Connection: keep-alive\r\n\r\n"), |
| 14517 | MockWrite( |
| 14518 | "GET / HTTP/1.1\r\n" |
| 14519 | "Host: alternative.example.org\r\n" |
| 14520 | "Connection: keep-alive\r\n\r\n"), |
| 14521 | }; |
| 14522 | |
| 14523 | MockRead http_reads[] = { |
| 14524 | MockRead( |
| 14525 | "HTTP/1.1 200 OK\r\n" |
| 14526 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 14527 | "Content-Length: 40\r\n\r\n" |
| 14528 | "first HTTP/1.1 response from alternative"), |
| 14529 | MockRead( |
| 14530 | "HTTP/1.1 200 OK\r\n" |
| 14531 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 14532 | "Content-Length: 41\r\n\r\n" |
| 14533 | "second HTTP/1.1 response from alternative"), |
| 14534 | }; |
| 14535 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 14536 | http_writes, arraysize(http_writes)); |
| 14537 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 14538 | |
| 14539 | // This test documents that an alternate Job should not pool to an already |
| 14540 | // existing HTTP/1.1 connection. In order to test this, a failed connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14541 | // to the server is mocked. This way |request2| relies on the alternate Job. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14542 | StaticSocketDataProvider data_refused; |
| 14543 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 14544 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 14545 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 14546 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14547 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 14548 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14549 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 14550 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 14551 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 14552 | http_server_properties->SetHttp2AlternativeService( |
| 14553 | server, alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14554 | |
| 14555 | // First transaction to alternative to open an HTTP/1.1 socket. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14556 | HttpRequestInfo request1; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 14557 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14558 | request1.method = "GET"; |
| 14559 | request1.url = GURL(alternative_url); |
| 14560 | request1.load_flags = 0; |
| 14561 | TestCompletionCallback callback1; |
| 14562 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14563 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14564 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14565 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14566 | ASSERT_TRUE(response1); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14567 | ASSERT_TRUE(response1->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14568 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14569 | EXPECT_TRUE(response1->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14570 | EXPECT_FALSE(response1->was_fetched_via_spdy); |
| 14571 | std::string response_data1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14572 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14573 | EXPECT_EQ("first HTTP/1.1 response from alternative", response_data1); |
| 14574 | |
| 14575 | // Request for origin.example.org, which has an alternative service. This |
| 14576 | // will start two Jobs: the alternative looks for connections to pool to, |
| 14577 | // 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] | 14578 | // open other connections to alternative server. The Job to server fails, so |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14579 | // this request fails. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14580 | HttpRequestInfo request2; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 14581 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14582 | request2.method = "GET"; |
| 14583 | request2.url = GURL(origin_url); |
| 14584 | request2.load_flags = 0; |
| 14585 | TestCompletionCallback callback2; |
| 14586 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14587 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14588 | EXPECT_THAT(callback2.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14589 | |
| 14590 | // Another transaction to alternative. This is to test that the HTTP/1.1 |
| 14591 | // socket is still open and in the pool. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14592 | HttpRequestInfo request3; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 14593 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14594 | request3.method = "GET"; |
| 14595 | request3.url = GURL(alternative_url); |
| 14596 | request3.load_flags = 0; |
| 14597 | TestCompletionCallback callback3; |
| 14598 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14599 | rv = trans3.Start(&request3, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14600 | EXPECT_THAT(callback3.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14601 | const HttpResponseInfo* response3 = trans3.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14602 | ASSERT_TRUE(response3); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14603 | ASSERT_TRUE(response3->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14604 | EXPECT_EQ("HTTP/1.1 200 OK", response3->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14605 | EXPECT_TRUE(response3->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14606 | EXPECT_FALSE(response3->was_fetched_via_spdy); |
| 14607 | std::string response_data3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14608 | ASSERT_THAT(ReadTransaction(&trans3, &response_data3), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 14609 | EXPECT_EQ("second HTTP/1.1 response from alternative", response_data3); |
| 14610 | } |
| 14611 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14612 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14613 | const std::string https_url = "https://www.example.org:8080/"; |
| 14614 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14615 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14616 | // Separate SPDY util instance for naked and wrapped requests. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14617 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14618 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14619 | // SPDY GET for HTTPS URL (through CONNECT tunnel) |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14620 | const HostPortPair host_port_pair("www.example.org", 8080); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14621 | SpdySerializedFrame connect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 14622 | spdy_util_.ConstructSpdyConnect(NULL, 0, 1, LOWEST, host_port_pair)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14623 | SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14624 | spdy_util_wrapped.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14625 | SpdySerializedFrame wrapped_req1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 14626 | spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 14627 | |
| 14628 | // SPDY GET for HTTP URL (through the proxy, but not the tunnel). |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 14629 | SpdyHeaderBlock req2_block; |
| 14630 | req2_block[spdy_util_.GetMethodKey()] = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14631 | req2_block[spdy_util_.GetHostKey()] = "www.example.org:8080"; |
[email protected] | 745aa9c | 2014-06-27 02:21:29 | [diff] [blame] | 14632 | req2_block[spdy_util_.GetSchemeKey()] = "http"; |
bnc | 7ecc112 | 2015-09-28 13:22:49 | [diff] [blame] | 14633 | req2_block[spdy_util_.GetPathKey()] = "/"; |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14634 | SpdySerializedFrame req2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14635 | spdy_util_.ConstructSpdyHeaders(3, std::move(req2_block), MEDIUM, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14636 | |
| 14637 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14638 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_req1, 2), |
| 14639 | CreateMockWrite(req2, 6), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14640 | }; |
| 14641 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14642 | SpdySerializedFrame conn_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14643 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14644 | SpdySerializedFrame resp1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14645 | spdy_util_wrapped.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14646 | SpdySerializedFrame body1(spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 14647 | SpdySerializedFrame wrapped_resp1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14648 | spdy_util_wrapped.ConstructWrappedSpdyFrame(resp1, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14649 | SpdySerializedFrame wrapped_body1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14650 | spdy_util_wrapped.ConstructWrappedSpdyFrame(body1, 1)); |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14651 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14652 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14653 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14654 | CreateMockRead(conn_resp, 1), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14655 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14656 | CreateMockRead(wrapped_resp1, 4), |
| 14657 | CreateMockRead(wrapped_body1, 5), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14658 | MockRead(ASYNC, ERR_IO_PENDING, 7), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14659 | CreateMockRead(resp2, 8), |
| 14660 | CreateMockRead(body2, 9), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14661 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 10), |
| 14662 | }; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14663 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14664 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 14665 | arraysize(writes1)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14666 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 14667 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14668 | |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 14669 | session_deps_.proxy_service = |
| 14670 | ProxyService::CreateFixedFromPacResult("HTTPS proxy:70"); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14671 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14672 | session_deps_.net_log = &log; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14673 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14674 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14675 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14676 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14677 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14678 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 14679 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14680 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14681 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14682 | |
| 14683 | // Start the first transaction to set up the SpdySession |
| 14684 | HttpRequestInfo request1; |
| 14685 | request1.method = "GET"; |
| 14686 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14687 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14688 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14689 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14690 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14691 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14692 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 14693 | data1.RunUntilPaused(); |
| 14694 | base::RunLoop().RunUntilIdle(); |
| 14695 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14696 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14697 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 14698 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 14699 | LoadTimingInfo load_timing_info1; |
| 14700 | EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); |
| 14701 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 14702 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 14703 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14704 | // Now, start the HTTP request. |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14705 | HttpRequestInfo request2; |
| 14706 | request2.method = "GET"; |
| 14707 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14708 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14709 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14710 | TestCompletionCallback callback2; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14711 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14712 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14713 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 14714 | data1.RunUntilPaused(); |
| 14715 | base::RunLoop().RunUntilIdle(); |
| 14716 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14717 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14718 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 14719 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 14720 | |
| 14721 | LoadTimingInfo load_timing_info2; |
| 14722 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
| 14723 | // The established SPDY sessions is considered reused by the HTTP request. |
| 14724 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 14725 | // HTTP requests over a SPDY session should have a different connection |
| 14726 | // socket_log_id than requests over a tunnel. |
| 14727 | 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] | 14728 | } |
| 14729 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14730 | // Test that in the case where we have a SPDY session to a SPDY proxy |
| 14731 | // that we do not pool other origins that resolve to the same IP when |
| 14732 | // the certificate does not match the new origin. |
| 14733 | // http://crbug.com/134690 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14734 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14735 | const std::string url1 = "http://www.example.org/"; |
| 14736 | const std::string url2 = "https://news.example.org/"; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14737 | const std::string ip_addr = "1.2.3.4"; |
| 14738 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14739 | // Second SpdyTestUtil instance for the second socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14740 | SpdyTestUtil spdy_util_secure; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14741 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14742 | // SPDY GET for HTTP URL (through SPDY proxy) |
bnc | 086b39e1 | 2016-06-24 13:05:26 | [diff] [blame] | 14743 | SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14744 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14745 | SpdySerializedFrame req1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14746 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14747 | |
| 14748 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14749 | CreateMockWrite(req1, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14750 | }; |
| 14751 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14752 | SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14753 | SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14754 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14755 | MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(resp1, 2), |
| 14756 | CreateMockRead(body1, 3), MockRead(ASYNC, OK, 4), // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14757 | }; |
| 14758 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14759 | SequencedSocketData data1(reads1, arraysize(reads1), writes1, |
| 14760 | arraysize(writes1)); |
martijn | fe9636e | 2016-02-06 14:33:32 | [diff] [blame] | 14761 | IPAddress ip; |
martijn | 654c8c4 | 2016-02-10 22:10:59 | [diff] [blame] | 14762 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14763 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 14764 | MockConnect connect_data1(ASYNC, OK, peer_addr); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14765 | data1.set_connect_data(connect_data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14766 | |
| 14767 | // SPDY GET for HTTPS URL (direct) |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14768 | SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14769 | spdy_util_secure.ConstructSpdyGet(url2.c_str(), 1, MEDIUM)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14770 | |
| 14771 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14772 | CreateMockWrite(req2, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14773 | }; |
| 14774 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14775 | SpdySerializedFrame resp2(spdy_util_secure.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14776 | SpdySerializedFrame body2(spdy_util_secure.ConstructSpdyDataFrame(1, true)); |
| 14777 | MockRead reads2[] = {CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14778 | MockRead(ASYNC, OK, 3)}; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14779 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14780 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 14781 | arraysize(writes2)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14782 | MockConnect connect_data2(ASYNC, OK); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14783 | data2.set_connect_data(connect_data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14784 | |
| 14785 | // Set up a proxy config that sends HTTP requests to a proxy, and |
| 14786 | // all others direct. |
| 14787 | ProxyConfig proxy_config; |
| 14788 | proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14789 | session_deps_.proxy_service = std::make_unique<ProxyService>( |
| 14790 | std::make_unique<ProxyConfigServiceFixed>(proxy_config), nullptr, |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14791 | nullptr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14792 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14793 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14794 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14795 | // Load a valid cert. Note, that this does not need to |
| 14796 | // be valid for proxy because the MockSSLClientSocket does |
| 14797 | // not actually verify it. But SpdySession will use this |
| 14798 | // to see if it is valid for the new origin |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14799 | ssl1.cert = ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem"); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14800 | ASSERT_TRUE(ssl1.cert); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14801 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 14802 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14803 | |
| 14804 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14805 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14806 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 14807 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14808 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14809 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14810 | session_deps_.host_resolver->rules()->AddRule("news.example.org", ip_addr); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14811 | session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14812 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14813 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14814 | |
| 14815 | // Start the first transaction to set up the SpdySession |
| 14816 | HttpRequestInfo request1; |
| 14817 | request1.method = "GET"; |
| 14818 | request1.url = GURL(url1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14819 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14820 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14821 | TestCompletionCallback callback1; |
| 14822 | ASSERT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14823 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 14824 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 14825 | data1.RunUntilPaused(); |
| 14826 | base::RunLoop().RunUntilIdle(); |
| 14827 | data1.Resume(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14828 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14829 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14830 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 14831 | |
| 14832 | // Now, start the HTTP request |
| 14833 | HttpRequestInfo request2; |
| 14834 | request2.method = "GET"; |
| 14835 | request2.url = GURL(url2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14836 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14837 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14838 | TestCompletionCallback callback2; |
| 14839 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14840 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 14841 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14842 | |
| 14843 | ASSERT_TRUE(callback2.have_result()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14844 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 14845 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 14846 | } |
| 14847 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14848 | // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 14849 | // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 14850 | // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 14851 | // SpdySession) do work. http://crbug.com/224701 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14852 | TEST_F(HttpNetworkTransactionTest, ErrorSocketNotConnected) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14853 | const std::string https_url = "https://www.example.org/"; |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14854 | |
| 14855 | MockRead reads1[] = { |
| 14856 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 14857 | }; |
| 14858 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14859 | SequencedSocketData data1(reads1, arraysize(reads1), NULL, 0); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14860 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14861 | SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14862 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, MEDIUM)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14863 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14864 | CreateMockWrite(req2, 0), |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14865 | }; |
| 14866 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14867 | SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14868 | SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14869 | MockRead reads2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14870 | CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
| 14871 | MockRead(ASYNC, OK, 3) // EOF |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14872 | }; |
| 14873 | |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14874 | SequencedSocketData data2(reads2, arraysize(reads2), writes2, |
| 14875 | arraysize(writes2)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14876 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14877 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14878 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14879 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 14880 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14881 | |
| 14882 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14883 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14884 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 14885 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14886 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14887 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 14888 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14889 | |
| 14890 | // Start the first transaction to set up the SpdySession and verify that |
| 14891 | // connection was closed. |
| 14892 | HttpRequestInfo request1; |
| 14893 | request1.method = "GET"; |
| 14894 | request1.url = GURL(https_url); |
| 14895 | request1.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14896 | HttpNetworkTransaction trans1(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14897 | TestCompletionCallback callback1; |
| 14898 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14899 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14900 | EXPECT_THAT(callback1.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14901 | |
| 14902 | // Now, start the second request and make sure it succeeds. |
| 14903 | HttpRequestInfo request2; |
| 14904 | request2.method = "GET"; |
| 14905 | request2.url = GURL(https_url); |
| 14906 | request2.load_flags = 0; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14907 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14908 | TestCompletionCallback callback2; |
| 14909 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14910 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14911 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14912 | ASSERT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 14913 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 14914 | } |
| 14915 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14916 | TEST_F(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14917 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 14918 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14919 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 14920 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 14921 | |
| 14922 | // Use two different hosts with different IPs so they don't get pooled. |
| 14923 | session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); |
| 14924 | session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14925 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14926 | |
| 14927 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14928 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14929 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14930 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14931 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 14932 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 14933 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14934 | SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14935 | spdy_util_.ConstructSpdyGet("https://www.a.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14936 | MockWrite spdy1_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14937 | CreateMockWrite(host1_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14938 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14939 | SpdySerializedFrame host1_resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14940 | SpdySerializedFrame host1_resp_body( |
| 14941 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14942 | MockRead spdy1_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14943 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 14944 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14945 | }; |
| 14946 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14947 | // Use a separate test instance for the separate SpdySession that will be |
| 14948 | // created. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14949 | SpdyTestUtil spdy_util_2; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14950 | auto spdy1_data = std::make_unique<SequencedSocketData>( |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14951 | spdy1_reads, arraysize(spdy1_reads), spdy1_writes, |
| 14952 | arraysize(spdy1_writes)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14953 | session_deps_.socket_factory->AddSocketDataProvider(spdy1_data.get()); |
| 14954 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14955 | SpdySerializedFrame host2_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14956 | spdy_util_2.ConstructSpdyGet("https://www.b.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14957 | MockWrite spdy2_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14958 | CreateMockWrite(host2_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14959 | }; |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 14960 | SpdySerializedFrame host2_resp(spdy_util_2.ConstructSpdyGetReply(NULL, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14961 | SpdySerializedFrame host2_resp_body( |
| 14962 | spdy_util_2.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14963 | MockRead spdy2_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14964 | CreateMockRead(host2_resp, 1), CreateMockRead(host2_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 14965 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14966 | }; |
| 14967 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14968 | auto spdy2_data = std::make_unique<SequencedSocketData>( |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14969 | spdy2_reads, arraysize(spdy2_reads), spdy2_writes, |
| 14970 | arraysize(spdy2_writes)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14971 | session_deps_.socket_factory->AddSocketDataProvider(spdy2_data.get()); |
| 14972 | |
| 14973 | MockWrite http_write[] = { |
| 14974 | MockWrite("GET / HTTP/1.1\r\n" |
| 14975 | "Host: www.a.com\r\n" |
| 14976 | "Connection: keep-alive\r\n\r\n"), |
| 14977 | }; |
| 14978 | |
| 14979 | MockRead http_read[] = { |
| 14980 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14981 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 14982 | MockRead("Content-Length: 6\r\n\r\n"), |
| 14983 | MockRead("hello!"), |
| 14984 | }; |
| 14985 | StaticSocketDataProvider http_data(http_read, arraysize(http_read), |
| 14986 | http_write, arraysize(http_write)); |
| 14987 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 14988 | |
| 14989 | HostPortPair host_port_pair_a("www.a.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 14990 | SpdySessionKey spdy_session_key_a( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 14991 | host_port_pair_a, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14992 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14993 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 14994 | |
| 14995 | TestCompletionCallback callback; |
| 14996 | HttpRequestInfo request1; |
| 14997 | request1.method = "GET"; |
| 14998 | request1.url = GURL("https://www.a.com/"); |
| 14999 | request1.load_flags = 0; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15000 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15001 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15002 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15003 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15004 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15005 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15006 | |
| 15007 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15008 | ASSERT_TRUE(response); |
| 15009 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15010 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15011 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15012 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15013 | |
| 15014 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15015 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15016 | EXPECT_EQ("hello!", response_data); |
| 15017 | trans.reset(); |
| 15018 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15019 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15020 | |
| 15021 | HostPortPair host_port_pair_b("www.b.com", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 15022 | SpdySessionKey spdy_session_key_b( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 15023 | host_port_pair_b, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15024 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15025 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15026 | HttpRequestInfo request2; |
| 15027 | request2.method = "GET"; |
| 15028 | request2.url = GURL("https://www.b.com/"); |
| 15029 | request2.load_flags = 0; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15030 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15031 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15032 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15033 | rv = trans->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15034 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15035 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15036 | |
| 15037 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15038 | ASSERT_TRUE(response); |
| 15039 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15040 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15041 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15042 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15043 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15044 | EXPECT_EQ("hello!", response_data); |
| 15045 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15046 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15047 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15048 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15049 | |
| 15050 | HostPortPair host_port_pair_a1("www.a.com", 80); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 15051 | SpdySessionKey spdy_session_key_a1( |
[email protected] | 314b0399 | 2014-04-01 01:28:53 | [diff] [blame] | 15052 | host_port_pair_a1, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15053 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15054 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15055 | HttpRequestInfo request3; |
| 15056 | request3.method = "GET"; |
| 15057 | request3.url = GURL("http://www.a.com/"); |
| 15058 | request3.load_flags = 0; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15059 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15060 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15061 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15062 | rv = trans->Start(&request3, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15063 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15064 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15065 | |
| 15066 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15067 | ASSERT_TRUE(response); |
| 15068 | ASSERT_TRUE(response->headers); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15069 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 15070 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15071 | EXPECT_FALSE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15072 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15073 | EXPECT_EQ("hello!", response_data); |
| 15074 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15075 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15076 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15077 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15078 | } |
| 15079 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15080 | TEST_F(HttpNetworkTransactionTest, HttpSyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15081 | HttpRequestInfo request; |
| 15082 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15083 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15084 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15085 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15086 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15087 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15088 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15089 | StaticSocketDataProvider data; |
| 15090 | data.set_connect_data(mock_connect); |
| 15091 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15092 | |
| 15093 | TestCompletionCallback callback; |
| 15094 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15095 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15096 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15097 | |
| 15098 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15099 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15100 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15101 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 15102 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15103 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 15104 | |
| 15105 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15106 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 15107 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15108 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15109 | |
| 15110 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15111 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15112 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15113 | } |
| 15114 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15115 | TEST_F(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15116 | HttpRequestInfo request; |
| 15117 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15118 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15119 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15120 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15121 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15122 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15123 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15124 | StaticSocketDataProvider data; |
| 15125 | data.set_connect_data(mock_connect); |
| 15126 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15127 | |
| 15128 | TestCompletionCallback callback; |
| 15129 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15130 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15131 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15132 | |
| 15133 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15134 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15135 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15136 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 15137 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15138 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 15139 | |
| 15140 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15141 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 15142 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15143 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15144 | |
| 15145 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15146 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15147 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15148 | } |
| 15149 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15150 | TEST_F(HttpNetworkTransactionTest, HttpSyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15151 | HttpRequestInfo request; |
| 15152 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15153 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15154 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15155 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15156 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15157 | |
| 15158 | MockWrite data_writes[] = { |
| 15159 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15160 | }; |
| 15161 | MockRead data_reads[] = { |
| 15162 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 15163 | }; |
| 15164 | |
| 15165 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 15166 | data_writes, arraysize(data_writes)); |
| 15167 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15168 | |
| 15169 | TestCompletionCallback callback; |
| 15170 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15171 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15172 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15173 | |
| 15174 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15175 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15176 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15177 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15178 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15179 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 15180 | } |
| 15181 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15182 | TEST_F(HttpNetworkTransactionTest, HttpAsyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15183 | HttpRequestInfo request; |
| 15184 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15185 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15186 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15187 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15188 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15189 | |
| 15190 | MockWrite data_writes[] = { |
| 15191 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
| 15192 | }; |
| 15193 | MockRead data_reads[] = { |
| 15194 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 15195 | }; |
| 15196 | |
| 15197 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 15198 | data_writes, arraysize(data_writes)); |
| 15199 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15200 | |
| 15201 | TestCompletionCallback callback; |
| 15202 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15203 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15204 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15205 | |
| 15206 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15207 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15208 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15209 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15210 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15211 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 15212 | } |
| 15213 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15214 | TEST_F(HttpNetworkTransactionTest, HttpSyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15215 | HttpRequestInfo request; |
| 15216 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15217 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15218 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15219 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15220 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15221 | |
| 15222 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15223 | MockWrite( |
| 15224 | "GET / HTTP/1.1\r\n" |
| 15225 | "Host: www.example.org\r\n" |
| 15226 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15227 | }; |
| 15228 | MockRead data_reads[] = { |
| 15229 | MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15230 | }; |
| 15231 | |
| 15232 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 15233 | data_writes, arraysize(data_writes)); |
| 15234 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15235 | |
| 15236 | TestCompletionCallback callback; |
| 15237 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15238 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15239 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15240 | |
| 15241 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15242 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15243 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15244 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15245 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15246 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 15247 | } |
| 15248 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15249 | TEST_F(HttpNetworkTransactionTest, HttpAsyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15250 | HttpRequestInfo request; |
| 15251 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15252 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15253 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15254 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15255 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15256 | |
| 15257 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15258 | MockWrite( |
| 15259 | "GET / HTTP/1.1\r\n" |
| 15260 | "Host: www.example.org\r\n" |
| 15261 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15262 | }; |
| 15263 | MockRead data_reads[] = { |
| 15264 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 15265 | }; |
| 15266 | |
| 15267 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 15268 | data_writes, arraysize(data_writes)); |
| 15269 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15270 | |
| 15271 | TestCompletionCallback callback; |
| 15272 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15273 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15274 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15275 | |
| 15276 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15277 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15278 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15279 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15280 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15281 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 15282 | } |
| 15283 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15284 | TEST_F(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15285 | HttpRequestInfo request; |
| 15286 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15287 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15288 | request.extra_headers.SetHeader("X-Foo", "bar"); |
| 15289 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15290 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15291 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15292 | |
| 15293 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15294 | MockWrite( |
| 15295 | "GET / HTTP/1.1\r\n" |
| 15296 | "Host: www.example.org\r\n" |
| 15297 | "Connection: keep-alive\r\n" |
| 15298 | "X-Foo: bar\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15299 | }; |
| 15300 | MockRead data_reads[] = { |
| 15301 | MockRead("HTTP/1.1 200 OK\r\n" |
| 15302 | "Content-Length: 5\r\n\r\n" |
| 15303 | "hello"), |
| 15304 | MockRead(ASYNC, ERR_UNEXPECTED), |
| 15305 | }; |
| 15306 | |
| 15307 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), |
| 15308 | data_writes, arraysize(data_writes)); |
| 15309 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15310 | |
| 15311 | TestCompletionCallback callback; |
| 15312 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15313 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15314 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15315 | |
| 15316 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15317 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15318 | |
| 15319 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15320 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15321 | std::string foo; |
| 15322 | EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo)); |
| 15323 | EXPECT_EQ("bar", foo); |
| 15324 | } |
| 15325 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15326 | namespace { |
| 15327 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 15328 | // Fake HttpStream that simply records calls to SetPriority(). |
| 15329 | class FakeStream : public HttpStream, |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15330 | public base::SupportsWeakPtr<FakeStream> { |
| 15331 | public: |
| 15332 | explicit FakeStream(RequestPriority priority) : priority_(priority) {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15333 | ~FakeStream() override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15334 | |
| 15335 | RequestPriority priority() const { return priority_; } |
| 15336 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15337 | int InitializeStream(const HttpRequestInfo* request_info, |
| 15338 | RequestPriority priority, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15339 | const NetLogWithSource& net_log, |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15340 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15341 | return ERR_IO_PENDING; |
| 15342 | } |
| 15343 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15344 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 15345 | HttpResponseInfo* response, |
| 15346 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15347 | ADD_FAILURE(); |
| 15348 | return ERR_UNEXPECTED; |
| 15349 | } |
| 15350 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15351 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15352 | ADD_FAILURE(); |
| 15353 | return ERR_UNEXPECTED; |
| 15354 | } |
| 15355 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15356 | int ReadResponseBody(IOBuffer* buf, |
| 15357 | int buf_len, |
| 15358 | const CompletionCallback& callback) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15359 | ADD_FAILURE(); |
| 15360 | return ERR_UNEXPECTED; |
| 15361 | } |
| 15362 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15363 | void Close(bool not_reusable) override {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15364 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15365 | bool IsResponseBodyComplete() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15366 | ADD_FAILURE(); |
| 15367 | return false; |
| 15368 | } |
| 15369 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15370 | bool IsConnectionReused() const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15371 | ADD_FAILURE(); |
| 15372 | return false; |
| 15373 | } |
| 15374 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15375 | void SetConnectionReused() override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15376 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 15377 | bool CanReuseConnection() const override { return false; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15378 | |
sclittle | 4de1bab9 | 2015-09-22 21:28:24 | [diff] [blame] | 15379 | int64_t GetTotalReceivedBytes() const override { |
[email protected] | bc92bc97 | 2013-12-13 08:32:59 | [diff] [blame] | 15380 | ADD_FAILURE(); |
| 15381 | return 0; |
| 15382 | } |
| 15383 | |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 15384 | int64_t GetTotalSentBytes() const override { |
| 15385 | ADD_FAILURE(); |
| 15386 | return 0; |
| 15387 | } |
| 15388 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15389 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15390 | ADD_FAILURE(); |
| 15391 | return false; |
| 15392 | } |
| 15393 | |
rch | cd37901 | 2017-04-12 21:53:32 | [diff] [blame] | 15394 | bool GetAlternativeService( |
| 15395 | AlternativeService* alternative_service) const override { |
| 15396 | ADD_FAILURE(); |
| 15397 | return false; |
| 15398 | } |
| 15399 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15400 | void GetSSLInfo(SSLInfo* ssl_info) override { ADD_FAILURE(); } |
| 15401 | |
| 15402 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15403 | ADD_FAILURE(); |
| 15404 | } |
| 15405 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15406 | bool GetRemoteEndpoint(IPEndPoint* endpoint) override { return false; } |
| 15407 | |
nharper | 78e6d2b | 2016-09-21 05:42:35 | [diff] [blame] | 15408 | Error GetTokenBindingSignature(crypto::ECPrivateKey* key, |
| 15409 | TokenBindingType tb_type, |
| 15410 | std::vector<uint8_t>* out) override { |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 15411 | ADD_FAILURE(); |
| 15412 | return ERR_NOT_IMPLEMENTED; |
| 15413 | } |
| 15414 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15415 | void Drain(HttpNetworkSession* session) override { ADD_FAILURE(); } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15416 | |
zhongyi | ca364fbb | 2015-12-12 03:39:12 | [diff] [blame] | 15417 | void PopulateNetErrorDetails(NetErrorDetails* details) override { return; } |
| 15418 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15419 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15420 | |
yhirano | a7e05bb | 2014-11-06 05:40:39 | [diff] [blame] | 15421 | HttpStream* RenewStreamForAuth() override { return NULL; } |
| 15422 | |
Andrey Kosyakov | 83a6eee | 2017-08-14 19:20:04 | [diff] [blame] | 15423 | void SetRequestHeadersCallback(RequestHeadersCallback callback) override {} |
| 15424 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15425 | private: |
| 15426 | RequestPriority priority_; |
| 15427 | |
| 15428 | DISALLOW_COPY_AND_ASSIGN(FakeStream); |
| 15429 | }; |
| 15430 | |
| 15431 | // Fake HttpStreamRequest that simply records calls to SetPriority() |
| 15432 | // and vends FakeStreams with its current priority. |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15433 | class FakeStreamRequest : public HttpStreamRequest, |
| 15434 | public base::SupportsWeakPtr<FakeStreamRequest> { |
| 15435 | public: |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15436 | FakeStreamRequest(RequestPriority priority, |
| 15437 | HttpStreamRequest::Delegate* delegate) |
| 15438 | : priority_(priority), |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15439 | delegate_(delegate), |
| 15440 | websocket_stream_create_helper_(NULL) {} |
| 15441 | |
| 15442 | FakeStreamRequest(RequestPriority priority, |
| 15443 | HttpStreamRequest::Delegate* delegate, |
| 15444 | WebSocketHandshakeStreamBase::CreateHelper* create_helper) |
| 15445 | : priority_(priority), |
| 15446 | delegate_(delegate), |
| 15447 | websocket_stream_create_helper_(create_helper) {} |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15448 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15449 | ~FakeStreamRequest() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15450 | |
| 15451 | RequestPriority priority() const { return priority_; } |
| 15452 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15453 | const WebSocketHandshakeStreamBase::CreateHelper* |
| 15454 | websocket_stream_create_helper() const { |
| 15455 | return websocket_stream_create_helper_; |
| 15456 | } |
| 15457 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15458 | // Create a new FakeStream and pass it to the request's |
| 15459 | // delegate. Returns a weak pointer to the FakeStream. |
| 15460 | base::WeakPtr<FakeStream> FinishStreamRequest() { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15461 | auto fake_stream = std::make_unique<FakeStream>(priority_); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15462 | // Do this before calling OnStreamReady() as OnStreamReady() may |
| 15463 | // immediately delete |fake_stream|. |
| 15464 | base::WeakPtr<FakeStream> weak_stream = fake_stream->AsWeakPtr(); |
bnc | 5029f463 | 2017-06-08 16:19:00 | [diff] [blame] | 15465 | delegate_->OnStreamReady(SSLConfig(), ProxyInfo(), std::move(fake_stream)); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15466 | return weak_stream; |
| 15467 | } |
| 15468 | |
asanka | 681f02d | 2017-02-22 17:06:39 | [diff] [blame] | 15469 | int RestartTunnelWithProxyAuth() override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15470 | ADD_FAILURE(); |
| 15471 | return ERR_UNEXPECTED; |
| 15472 | } |
| 15473 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15474 | LoadState GetLoadState() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15475 | ADD_FAILURE(); |
| 15476 | return LoadState(); |
| 15477 | } |
| 15478 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15479 | void SetPriority(RequestPriority priority) override { priority_ = priority; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15480 | |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15481 | bool was_alpn_negotiated() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15482 | |
bnc | 6227b26e | 2016-08-12 02:00:43 | [diff] [blame] | 15483 | NextProto negotiated_protocol() const override { return kProtoUnknown; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15484 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15485 | bool using_spdy() const override { return false; } |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15486 | |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 15487 | const ConnectionAttempts& connection_attempts() const override { |
| 15488 | static ConnectionAttempts no_attempts; |
| 15489 | return no_attempts; |
| 15490 | } |
| 15491 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15492 | private: |
| 15493 | RequestPriority priority_; |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15494 | HttpStreamRequest::Delegate* const delegate_; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15495 | WebSocketHandshakeStreamBase::CreateHelper* websocket_stream_create_helper_; |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15496 | |
| 15497 | DISALLOW_COPY_AND_ASSIGN(FakeStreamRequest); |
| 15498 | }; |
| 15499 | |
| 15500 | // Fake HttpStreamFactory that vends FakeStreamRequests. |
| 15501 | class FakeStreamFactory : public HttpStreamFactory { |
| 15502 | public: |
| 15503 | FakeStreamFactory() {} |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15504 | ~FakeStreamFactory() override {} |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15505 | |
| 15506 | // Returns a WeakPtr<> to the last HttpStreamRequest returned by |
| 15507 | // RequestStream() (which may be NULL if it was destroyed already). |
| 15508 | base::WeakPtr<FakeStreamRequest> last_stream_request() { |
| 15509 | return last_stream_request_; |
| 15510 | } |
| 15511 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15512 | std::unique_ptr<HttpStreamRequest> RequestStream( |
| 15513 | const HttpRequestInfo& info, |
| 15514 | RequestPriority priority, |
| 15515 | const SSLConfig& server_ssl_config, |
| 15516 | const SSLConfig& proxy_ssl_config, |
| 15517 | HttpStreamRequest::Delegate* delegate, |
| 15518 | bool enable_ip_based_pooling, |
| 15519 | bool enable_alternative_services, |
| 15520 | const NetLogWithSource& net_log) override { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15521 | auto fake_request = std::make_unique<FakeStreamRequest>(priority, delegate); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15522 | last_stream_request_ = fake_request->AsWeakPtr(); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15523 | return std::move(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15524 | } |
| 15525 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15526 | std::unique_ptr<HttpStreamRequest> RequestBidirectionalStreamImpl( |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 15527 | const HttpRequestInfo& info, |
| 15528 | RequestPriority priority, |
| 15529 | const SSLConfig& server_ssl_config, |
| 15530 | const SSLConfig& proxy_ssl_config, |
| 15531 | HttpStreamRequest::Delegate* delegate, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15532 | bool enable_ip_based_pooling, |
bnc | accd496 | 2017-04-06 21:00:26 | [diff] [blame] | 15533 | bool enable_alternative_services, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15534 | const NetLogWithSource& net_log) override { |
xunjieli | 11834f0 | 2015-12-22 04:27:08 | [diff] [blame] | 15535 | NOTREACHED(); |
| 15536 | return nullptr; |
| 15537 | } |
| 15538 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15539 | std::unique_ptr<HttpStreamRequest> RequestWebSocketHandshakeStream( |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15540 | const HttpRequestInfo& info, |
| 15541 | RequestPriority priority, |
| 15542 | const SSLConfig& server_ssl_config, |
| 15543 | const SSLConfig& proxy_ssl_config, |
| 15544 | HttpStreamRequest::Delegate* delegate, |
[email protected] | 467086b | 2013-11-12 08:19:46 | [diff] [blame] | 15545 | WebSocketHandshakeStreamBase::CreateHelper* create_helper, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15546 | bool enable_ip_based_pooling, |
bnc | accd496 | 2017-04-06 21:00:26 | [diff] [blame] | 15547 | bool enable_alternative_services, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15548 | const NetLogWithSource& net_log) override { |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15549 | auto fake_request = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15550 | std::make_unique<FakeStreamRequest>(priority, delegate, create_helper); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15551 | last_stream_request_ = fake_request->AsWeakPtr(); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 15552 | return std::move(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15553 | } |
| 15554 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15555 | void PreconnectStreams(int num_streams, |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 15556 | const HttpRequestInfo& info) override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15557 | ADD_FAILURE(); |
| 15558 | } |
| 15559 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15560 | const HostMappingRules* GetHostMappingRules() const override { |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15561 | ADD_FAILURE(); |
| 15562 | return NULL; |
| 15563 | } |
| 15564 | |
xunjieli | f5267de | 2017-01-20 21:18:57 | [diff] [blame] | 15565 | void DumpMemoryStats(base::trace_event::ProcessMemoryDump* pmd, |
| 15566 | const std::string& parent_absolute_name) const override { |
| 15567 | ADD_FAILURE(); |
| 15568 | } |
| 15569 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15570 | private: |
| 15571 | base::WeakPtr<FakeStreamRequest> last_stream_request_; |
| 15572 | |
| 15573 | DISALLOW_COPY_AND_ASSIGN(FakeStreamFactory); |
| 15574 | }; |
| 15575 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15576 | // TODO(ricea): Maybe unify this with the one in |
| 15577 | // url_request_http_job_unittest.cc ? |
| 15578 | class FakeWebSocketBasicHandshakeStream : public WebSocketHandshakeStreamBase { |
| 15579 | public: |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15580 | FakeWebSocketBasicHandshakeStream( |
| 15581 | std::unique_ptr<ClientSocketHandle> connection, |
| 15582 | bool using_proxy) |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 15583 | : state_(std::move(connection), using_proxy, false) {} |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15584 | |
| 15585 | // Fake implementation of HttpStreamBase methods. |
| 15586 | // This ends up being quite "real" because this object has to really send data |
| 15587 | // on the mock socket. It might be easier to use the real implementation, but |
| 15588 | // the fact that the WebSocket code is not compiled on iOS makes that |
| 15589 | // difficult. |
| 15590 | int InitializeStream(const HttpRequestInfo* request_info, |
| 15591 | RequestPriority priority, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15592 | const NetLogWithSource& net_log, |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15593 | const CompletionCallback& callback) override { |
| 15594 | state_.Initialize(request_info, priority, net_log, callback); |
| 15595 | return OK; |
| 15596 | } |
| 15597 | |
| 15598 | int SendRequest(const HttpRequestHeaders& request_headers, |
| 15599 | HttpResponseInfo* response, |
| 15600 | const CompletionCallback& callback) override { |
| 15601 | return parser()->SendRequest(state_.GenerateRequestLine(), request_headers, |
| 15602 | response, callback); |
| 15603 | } |
| 15604 | |
| 15605 | int ReadResponseHeaders(const CompletionCallback& callback) override { |
| 15606 | return parser()->ReadResponseHeaders(callback); |
| 15607 | } |
| 15608 | |
| 15609 | int ReadResponseBody(IOBuffer* buf, |
| 15610 | int buf_len, |
| 15611 | const CompletionCallback& callback) override { |
| 15612 | NOTREACHED(); |
| 15613 | return ERR_IO_PENDING; |
| 15614 | } |
| 15615 | |
| 15616 | void Close(bool not_reusable) override { |
| 15617 | if (parser()) |
| 15618 | parser()->Close(true); |
| 15619 | } |
| 15620 | |
| 15621 | bool IsResponseBodyComplete() const override { |
| 15622 | NOTREACHED(); |
| 15623 | return false; |
| 15624 | } |
| 15625 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15626 | bool IsConnectionReused() const override { |
| 15627 | NOTREACHED(); |
| 15628 | return false; |
| 15629 | } |
| 15630 | void SetConnectionReused() override { NOTREACHED(); } |
| 15631 | |
mmenke | bd84c39 | 2015-09-02 14:12:34 | [diff] [blame] | 15632 | bool CanReuseConnection() const override { return false; } |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15633 | |
sclittle | 4de1bab9 | 2015-09-22 21:28:24 | [diff] [blame] | 15634 | int64_t GetTotalReceivedBytes() const override { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15635 | NOTREACHED(); |
| 15636 | return 0; |
| 15637 | } |
| 15638 | |
sclittle | be1ccf6 | 2015-09-02 19:40:36 | [diff] [blame] | 15639 | int64_t GetTotalSentBytes() const override { |
| 15640 | NOTREACHED(); |
| 15641 | return 0; |
| 15642 | } |
| 15643 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15644 | bool GetLoadTimingInfo(LoadTimingInfo* load_timing_info) const override { |
| 15645 | NOTREACHED(); |
| 15646 | return false; |
| 15647 | } |
| 15648 | |
rch | cd37901 | 2017-04-12 21:53:32 | [diff] [blame] | 15649 | bool GetAlternativeService( |
| 15650 | AlternativeService* alternative_service) const override { |
| 15651 | ADD_FAILURE(); |
| 15652 | return false; |
| 15653 | } |
| 15654 | |
Adam Rice | cb76ac6 | 2015-02-20 05:33:25 | [diff] [blame] | 15655 | void GetSSLInfo(SSLInfo* ssl_info) override {} |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15656 | |
| 15657 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override { |
| 15658 | NOTREACHED(); |
| 15659 | } |
| 15660 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15661 | bool GetRemoteEndpoint(IPEndPoint* endpoint) override { return false; } |
| 15662 | |
nharper | 78e6d2b | 2016-09-21 05:42:35 | [diff] [blame] | 15663 | Error GetTokenBindingSignature(crypto::ECPrivateKey* key, |
| 15664 | TokenBindingType tb_type, |
| 15665 | std::vector<uint8_t>* out) override { |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 15666 | ADD_FAILURE(); |
| 15667 | return ERR_NOT_IMPLEMENTED; |
| 15668 | } |
| 15669 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15670 | void Drain(HttpNetworkSession* session) override { NOTREACHED(); } |
| 15671 | |
zhongyi | ca364fbb | 2015-12-12 03:39:12 | [diff] [blame] | 15672 | void PopulateNetErrorDetails(NetErrorDetails* details) override { return; } |
| 15673 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15674 | void SetPriority(RequestPriority priority) override { NOTREACHED(); } |
| 15675 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15676 | HttpStream* RenewStreamForAuth() override { |
| 15677 | NOTREACHED(); |
| 15678 | return nullptr; |
| 15679 | } |
| 15680 | |
| 15681 | // Fake implementation of WebSocketHandshakeStreamBase method(s) |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15682 | std::unique_ptr<WebSocketStream> Upgrade() override { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15683 | NOTREACHED(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15684 | return std::unique_ptr<WebSocketStream>(); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 15685 | } |
| 15686 | |
| 15687 | private: |
| 15688 | HttpStreamParser* parser() const { return state_.parser(); } |
| 15689 | HttpBasicState state_; |
| 15690 | |
| 15691 | DISALLOW_COPY_AND_ASSIGN(FakeWebSocketBasicHandshakeStream); |
| 15692 | }; |
| 15693 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15694 | // TODO(yhirano): Split this class out into a net/websockets file, if it is |
| 15695 | // worth doing. |
| 15696 | class FakeWebSocketStreamCreateHelper : |
| 15697 | public WebSocketHandshakeStreamBase::CreateHelper { |
| 15698 | public: |
bnc | 615cf2f | 2017-05-19 18:53:26 | [diff] [blame] | 15699 | std::unique_ptr<WebSocketHandshakeStreamBase> CreateBasicStream( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15700 | std::unique_ptr<ClientSocketHandle> connection, |
mostynb | ba063d603 | 2014-10-09 11:01:13 | [diff] [blame] | 15701 | bool using_proxy) override { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15702 | return std::make_unique<FakeWebSocketBasicHandshakeStream>( |
bnc | 615cf2f | 2017-05-19 18:53:26 | [diff] [blame] | 15703 | std::move(connection), using_proxy); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15704 | } |
| 15705 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15706 | ~FakeWebSocketStreamCreateHelper() override {} |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15707 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15708 | virtual std::unique_ptr<WebSocketStream> Upgrade() { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15709 | NOTREACHED(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15710 | return std::unique_ptr<WebSocketStream>(); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15711 | } |
| 15712 | }; |
| 15713 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15714 | } // namespace |
| 15715 | |
| 15716 | // Make sure that HttpNetworkTransaction passes on its priority to its |
| 15717 | // stream request on start. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15718 | TEST_F(HttpNetworkTransactionTest, SetStreamRequestPriorityOnStart) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15719 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15720 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15721 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15722 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15723 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15724 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15725 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15726 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15727 | ASSERT_FALSE(fake_factory->last_stream_request()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15728 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15729 | TestCompletionCallback callback; |
| 15730 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15731 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15732 | |
| 15733 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 15734 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15735 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15736 | EXPECT_EQ(LOW, fake_request->priority()); |
| 15737 | } |
| 15738 | |
| 15739 | // Make sure that HttpNetworkTransaction passes on its priority |
| 15740 | // updates to its stream request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15741 | TEST_F(HttpNetworkTransactionTest, SetStreamRequestPriority) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15742 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15743 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15744 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15745 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15746 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15747 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15748 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15749 | |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15750 | TestCompletionCallback callback; |
| 15751 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15752 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15753 | |
| 15754 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 15755 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15756 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15757 | EXPECT_EQ(LOW, fake_request->priority()); |
| 15758 | |
| 15759 | trans.SetPriority(LOWEST); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15760 | ASSERT_TRUE(fake_request); |
[email protected] | bf82898 | 2013-08-14 18:01:47 | [diff] [blame] | 15761 | EXPECT_EQ(LOWEST, fake_request->priority()); |
| 15762 | } |
| 15763 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15764 | // Make sure that HttpNetworkTransaction passes on its priority |
| 15765 | // updates to its stream. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15766 | TEST_F(HttpNetworkTransactionTest, SetStreamPriority) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15767 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15768 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15769 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15770 | peer.SetHttpStreamFactory(std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15771 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15772 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15773 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15774 | |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15775 | TestCompletionCallback callback; |
| 15776 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15777 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15778 | |
| 15779 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 15780 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15781 | ASSERT_TRUE(fake_request); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15782 | base::WeakPtr<FakeStream> fake_stream = fake_request->FinishStreamRequest(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15783 | ASSERT_TRUE(fake_stream); |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 15784 | EXPECT_EQ(LOW, fake_stream->priority()); |
| 15785 | |
| 15786 | trans.SetPriority(LOWEST); |
| 15787 | EXPECT_EQ(LOWEST, fake_stream->priority()); |
| 15788 | } |
| 15789 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15790 | TEST_F(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) { |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15791 | // The same logic needs to be tested for both ws: and wss: schemes, but this |
| 15792 | // test is already parameterised on NextProto, so it uses a loop to verify |
| 15793 | // that the different schemes work. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15794 | std::string test_cases[] = {"ws://www.example.org/", |
| 15795 | "wss://www.example.org/"}; |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15796 | for (size_t i = 0; i < arraysize(test_cases); ++i) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15797 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 15798 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15799 | FakeStreamFactory* fake_factory = new FakeStreamFactory(); |
| 15800 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
[email protected] | 0191b51c | 2013-11-18 10:55:23 | [diff] [blame] | 15801 | peer.SetHttpStreamFactoryForWebSocket( |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15802 | std::unique_ptr<HttpStreamFactory>(fake_factory)); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15803 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15804 | HttpRequestInfo request; |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15805 | HttpNetworkTransaction trans(LOW, session.get()); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15806 | trans.SetWebSocketHandshakeStreamCreateHelper( |
| 15807 | &websocket_stream_create_helper); |
| 15808 | |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15809 | TestCompletionCallback callback; |
| 15810 | request.method = "GET"; |
| 15811 | request.url = GURL(test_cases[i]); |
| 15812 | |
| 15813 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15814 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15815 | |
| 15816 | base::WeakPtr<FakeStreamRequest> fake_request = |
| 15817 | fake_factory->last_stream_request(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15818 | ASSERT_TRUE(fake_request); |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 15819 | EXPECT_EQ(&websocket_stream_create_helper, |
| 15820 | fake_request->websocket_stream_create_helper()); |
| 15821 | } |
| 15822 | } |
| 15823 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15824 | // Tests that when a used socket is returned to the SSL socket pool, it's closed |
| 15825 | // if the transport socket pool is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15826 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15827 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 15828 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15829 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 15830 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15831 | |
| 15832 | // Set up SSL request. |
| 15833 | |
| 15834 | HttpRequestInfo ssl_request; |
| 15835 | ssl_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15836 | ssl_request.url = GURL("https://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15837 | |
| 15838 | MockWrite ssl_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15839 | MockWrite( |
| 15840 | "GET / HTTP/1.1\r\n" |
| 15841 | "Host: www.example.org\r\n" |
| 15842 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15843 | }; |
| 15844 | MockRead ssl_reads[] = { |
| 15845 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15846 | MockRead("Content-Length: 11\r\n\r\n"), |
| 15847 | MockRead("hello world"), |
| 15848 | MockRead(SYNCHRONOUS, OK), |
| 15849 | }; |
| 15850 | StaticSocketDataProvider ssl_data(ssl_reads, arraysize(ssl_reads), |
| 15851 | ssl_writes, arraysize(ssl_writes)); |
| 15852 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 15853 | |
| 15854 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 15855 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15856 | |
| 15857 | // Set up HTTP request. |
| 15858 | |
| 15859 | HttpRequestInfo http_request; |
| 15860 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15861 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15862 | |
| 15863 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15864 | MockWrite( |
| 15865 | "GET / HTTP/1.1\r\n" |
| 15866 | "Host: www.example.org\r\n" |
| 15867 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15868 | }; |
| 15869 | MockRead http_reads[] = { |
| 15870 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15871 | MockRead("Content-Length: 7\r\n\r\n"), |
| 15872 | MockRead("falafel"), |
| 15873 | MockRead(SYNCHRONOUS, OK), |
| 15874 | }; |
| 15875 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 15876 | http_writes, arraysize(http_writes)); |
| 15877 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 15878 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15879 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15880 | |
| 15881 | // Start the SSL request. |
| 15882 | TestCompletionCallback ssl_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15883 | HttpNetworkTransaction ssl_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15884 | ASSERT_EQ(ERR_IO_PENDING, |
| 15885 | ssl_trans.Start(&ssl_request, ssl_callback.callback(), |
| 15886 | NetLogWithSource())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15887 | |
| 15888 | // Start the HTTP request. Pool should stall. |
| 15889 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15890 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15891 | ASSERT_EQ(ERR_IO_PENDING, |
| 15892 | http_trans.Start(&http_request, http_callback.callback(), |
| 15893 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15894 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15895 | |
| 15896 | // Wait for response from SSL request. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15897 | ASSERT_THAT(ssl_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15898 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15899 | ASSERT_THAT(ReadTransaction(&ssl_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15900 | EXPECT_EQ("hello world", response_data); |
| 15901 | |
| 15902 | // The SSL socket should automatically be closed, so the HTTP request can |
| 15903 | // start. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15904 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 15905 | ASSERT_FALSE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15906 | |
| 15907 | // The HTTP request can now complete. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15908 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15909 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15910 | EXPECT_EQ("falafel", response_data); |
| 15911 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15912 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15913 | } |
| 15914 | |
| 15915 | // Tests that when a SSL connection is established but there's no corresponding |
| 15916 | // request that needs it, the new socket is closed if the transport socket pool |
| 15917 | // is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15918 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15919 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 15920 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15921 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 15922 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15923 | |
| 15924 | // Set up an ssl request. |
| 15925 | |
| 15926 | HttpRequestInfo ssl_request; |
| 15927 | ssl_request.method = "GET"; |
| 15928 | ssl_request.url = GURL("https://www.foopy.com/"); |
| 15929 | |
| 15930 | // No data will be sent on the SSL socket. |
| 15931 | StaticSocketDataProvider ssl_data; |
| 15932 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 15933 | |
| 15934 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 15935 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15936 | |
| 15937 | // Set up HTTP request. |
| 15938 | |
| 15939 | HttpRequestInfo http_request; |
| 15940 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15941 | http_request.url = GURL("http://www.example.org/"); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15942 | |
| 15943 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15944 | MockWrite( |
| 15945 | "GET / HTTP/1.1\r\n" |
| 15946 | "Host: www.example.org\r\n" |
| 15947 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15948 | }; |
| 15949 | MockRead http_reads[] = { |
| 15950 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15951 | MockRead("Content-Length: 7\r\n\r\n"), |
| 15952 | MockRead("falafel"), |
| 15953 | MockRead(SYNCHRONOUS, OK), |
| 15954 | }; |
| 15955 | StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
| 15956 | http_writes, arraysize(http_writes)); |
| 15957 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 15958 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15959 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15960 | |
| 15961 | // Preconnect an SSL socket. A preconnect is needed because connect jobs are |
| 15962 | // cancelled when a normal transaction is cancelled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15963 | HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 15964 | http_stream_factory->PreconnectStreams(1, ssl_request); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15965 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15966 | |
| 15967 | // Start the HTTP request. Pool should stall. |
| 15968 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15969 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15970 | ASSERT_EQ(ERR_IO_PENDING, |
| 15971 | http_trans.Start(&http_request, http_callback.callback(), |
| 15972 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15973 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15974 | |
| 15975 | // The SSL connection will automatically be closed once the connection is |
| 15976 | // established, to let the HTTP request start. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15977 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15978 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15979 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15980 | EXPECT_EQ("falafel", response_data); |
| 15981 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 15982 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 15983 | } |
| 15984 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15985 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15986 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15987 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15988 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 15989 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15990 | |
| 15991 | HttpRequestInfo request; |
| 15992 | request.method = "POST"; |
| 15993 | request.url = GURL("http://www.foo.com/"); |
| 15994 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15995 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15996 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15997 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 15998 | // Send headers successfully, but get an error while sending the body. |
| 15999 | MockWrite data_writes[] = { |
| 16000 | MockWrite("POST / HTTP/1.1\r\n" |
| 16001 | "Host: www.foo.com\r\n" |
| 16002 | "Connection: keep-alive\r\n" |
| 16003 | "Content-Length: 3\r\n\r\n"), |
| 16004 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16005 | }; |
| 16006 | |
| 16007 | MockRead data_reads[] = { |
| 16008 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 16009 | MockRead("hello world"), |
| 16010 | MockRead(SYNCHRONOUS, OK), |
| 16011 | }; |
| 16012 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16013 | arraysize(data_writes)); |
| 16014 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16015 | |
| 16016 | TestCompletionCallback callback; |
| 16017 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16018 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16019 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16020 | |
| 16021 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16022 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16023 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16024 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16025 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16026 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16027 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16028 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 16029 | |
| 16030 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16031 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16032 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16033 | EXPECT_EQ("hello world", response_data); |
| 16034 | } |
| 16035 | |
| 16036 | // This test makes sure the retry logic doesn't trigger when reading an error |
| 16037 | // response from a server that rejected a POST with a CONNECTION_RESET. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16038 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16039 | PostReadsErrorResponseAfterResetOnReusedSocket) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16040 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16041 | MockWrite data_writes[] = { |
| 16042 | MockWrite("GET / HTTP/1.1\r\n" |
| 16043 | "Host: www.foo.com\r\n" |
| 16044 | "Connection: keep-alive\r\n\r\n"), |
| 16045 | MockWrite("POST / HTTP/1.1\r\n" |
| 16046 | "Host: www.foo.com\r\n" |
| 16047 | "Connection: keep-alive\r\n" |
| 16048 | "Content-Length: 3\r\n\r\n"), |
| 16049 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16050 | }; |
| 16051 | |
| 16052 | MockRead data_reads[] = { |
| 16053 | MockRead("HTTP/1.1 200 Peachy\r\n" |
| 16054 | "Content-Length: 14\r\n\r\n"), |
| 16055 | MockRead("first response"), |
| 16056 | MockRead("HTTP/1.1 400 Not OK\r\n" |
| 16057 | "Content-Length: 15\r\n\r\n"), |
| 16058 | MockRead("second response"), |
| 16059 | MockRead(SYNCHRONOUS, OK), |
| 16060 | }; |
| 16061 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16062 | arraysize(data_writes)); |
| 16063 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16064 | |
| 16065 | TestCompletionCallback callback; |
| 16066 | HttpRequestInfo request1; |
| 16067 | request1.method = "GET"; |
| 16068 | request1.url = GURL("http://www.foo.com/"); |
| 16069 | request1.load_flags = 0; |
| 16070 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16071 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16072 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16073 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16074 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16075 | |
| 16076 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16077 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16078 | |
| 16079 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16080 | ASSERT_TRUE(response1); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16081 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16082 | EXPECT_TRUE(response1->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16083 | EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine()); |
| 16084 | |
| 16085 | std::string response_data1; |
| 16086 | rv = ReadTransaction(trans1.get(), &response_data1); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16087 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16088 | EXPECT_EQ("first response", response_data1); |
| 16089 | // Delete the transaction to release the socket back into the socket pool. |
| 16090 | trans1.reset(); |
| 16091 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16092 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16093 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16094 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16095 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16096 | |
| 16097 | HttpRequestInfo request2; |
| 16098 | request2.method = "POST"; |
| 16099 | request2.url = GURL("http://www.foo.com/"); |
| 16100 | request2.upload_data_stream = &upload_data_stream; |
| 16101 | request2.load_flags = 0; |
| 16102 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16103 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16104 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16105 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16106 | |
| 16107 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16108 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16109 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16110 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16111 | ASSERT_TRUE(response2); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16112 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16113 | EXPECT_TRUE(response2->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16114 | EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine()); |
| 16115 | |
| 16116 | std::string response_data2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16117 | rv = ReadTransaction(&trans2, &response_data2); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16118 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16119 | EXPECT_EQ("second response", response_data2); |
| 16120 | } |
| 16121 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16122 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16123 | PostReadsErrorResponseAfterResetPartialBodySent) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16124 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16125 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16126 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16127 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16128 | |
| 16129 | HttpRequestInfo request; |
| 16130 | request.method = "POST"; |
| 16131 | request.url = GURL("http://www.foo.com/"); |
| 16132 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16133 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16134 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16135 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16136 | // Send headers successfully, but get an error while sending the body. |
| 16137 | MockWrite data_writes[] = { |
| 16138 | MockWrite("POST / HTTP/1.1\r\n" |
| 16139 | "Host: www.foo.com\r\n" |
| 16140 | "Connection: keep-alive\r\n" |
| 16141 | "Content-Length: 3\r\n\r\n" |
| 16142 | "fo"), |
| 16143 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16144 | }; |
| 16145 | |
| 16146 | MockRead data_reads[] = { |
| 16147 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 16148 | MockRead("hello world"), |
| 16149 | MockRead(SYNCHRONOUS, OK), |
| 16150 | }; |
| 16151 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16152 | arraysize(data_writes)); |
| 16153 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16154 | |
| 16155 | TestCompletionCallback callback; |
| 16156 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16157 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16158 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16159 | |
| 16160 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16161 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16162 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16163 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16164 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16165 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16166 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16167 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 16168 | |
| 16169 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16170 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16171 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16172 | EXPECT_EQ("hello world", response_data); |
| 16173 | } |
| 16174 | |
| 16175 | // This tests the more common case than the previous test, where headers and |
| 16176 | // body are not merged into a single request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16177 | TEST_F(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) { |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 16178 | ChunkedUploadDataStream upload_data_stream(0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16179 | |
| 16180 | HttpRequestInfo request; |
| 16181 | request.method = "POST"; |
| 16182 | request.url = GURL("http://www.foo.com/"); |
| 16183 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16184 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16185 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16186 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16187 | // Send headers successfully, but get an error while sending the body. |
| 16188 | MockWrite data_writes[] = { |
| 16189 | MockWrite("POST / HTTP/1.1\r\n" |
| 16190 | "Host: www.foo.com\r\n" |
| 16191 | "Connection: keep-alive\r\n" |
| 16192 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 16193 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16194 | }; |
| 16195 | |
| 16196 | MockRead data_reads[] = { |
| 16197 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 16198 | MockRead("hello world"), |
| 16199 | MockRead(SYNCHRONOUS, OK), |
| 16200 | }; |
| 16201 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16202 | arraysize(data_writes)); |
| 16203 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16204 | |
| 16205 | TestCompletionCallback callback; |
| 16206 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16207 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16208 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16209 | // Make sure the headers are sent before adding a chunk. This ensures that |
| 16210 | // they can't be merged with the body in a single send. Not currently |
| 16211 | // necessary since a chunked body is never merged with headers, but this makes |
| 16212 | // the test more future proof. |
| 16213 | base::RunLoop().RunUntilIdle(); |
| 16214 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 16215 | upload_data_stream.AppendData("last chunk", 10, true); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16216 | |
| 16217 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16218 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16219 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16220 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16221 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16222 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16223 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16224 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 16225 | |
| 16226 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16227 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16228 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16229 | EXPECT_EQ("hello world", response_data); |
| 16230 | } |
| 16231 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16232 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16233 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16234 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16235 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16236 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16237 | |
| 16238 | HttpRequestInfo request; |
| 16239 | request.method = "POST"; |
| 16240 | request.url = GURL("http://www.foo.com/"); |
| 16241 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16242 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16243 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16244 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16245 | |
| 16246 | MockWrite data_writes[] = { |
| 16247 | MockWrite("POST / HTTP/1.1\r\n" |
| 16248 | "Host: www.foo.com\r\n" |
| 16249 | "Connection: keep-alive\r\n" |
| 16250 | "Content-Length: 3\r\n\r\n"), |
| 16251 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16252 | }; |
| 16253 | |
| 16254 | MockRead data_reads[] = { |
| 16255 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 16256 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 16257 | MockRead("hello world"), |
| 16258 | MockRead(SYNCHRONOUS, OK), |
| 16259 | }; |
| 16260 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16261 | arraysize(data_writes)); |
| 16262 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16263 | |
| 16264 | TestCompletionCallback callback; |
| 16265 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16266 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16267 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16268 | |
| 16269 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16270 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16271 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16272 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16273 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16274 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16275 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16276 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 16277 | |
| 16278 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16279 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16280 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16281 | EXPECT_EQ("hello world", response_data); |
| 16282 | } |
| 16283 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16284 | TEST_F(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16285 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16286 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16287 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16288 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16289 | |
| 16290 | HttpRequestInfo request; |
| 16291 | request.method = "POST"; |
| 16292 | request.url = GURL("http://www.foo.com/"); |
| 16293 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16294 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16295 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16296 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16297 | // Send headers successfully, but get an error while sending the body. |
| 16298 | MockWrite data_writes[] = { |
| 16299 | MockWrite("POST / HTTP/1.1\r\n" |
| 16300 | "Host: www.foo.com\r\n" |
| 16301 | "Connection: keep-alive\r\n" |
| 16302 | "Content-Length: 3\r\n\r\n"), |
| 16303 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16304 | }; |
| 16305 | |
| 16306 | MockRead data_reads[] = { |
| 16307 | MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"), |
| 16308 | MockRead("hello world"), |
| 16309 | MockRead(SYNCHRONOUS, OK), |
| 16310 | }; |
| 16311 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16312 | arraysize(data_writes)); |
| 16313 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16314 | |
| 16315 | TestCompletionCallback callback; |
| 16316 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16317 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16318 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16319 | |
| 16320 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16321 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16322 | } |
| 16323 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16324 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16325 | PostIgnoresNonErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16326 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16327 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16328 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16329 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16330 | |
| 16331 | HttpRequestInfo request; |
| 16332 | request.method = "POST"; |
| 16333 | request.url = GURL("http://www.foo.com/"); |
| 16334 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16335 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16336 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16337 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16338 | // Send headers successfully, but get an error while sending the body. |
| 16339 | MockWrite data_writes[] = { |
| 16340 | MockWrite("POST / HTTP/1.1\r\n" |
| 16341 | "Host: www.foo.com\r\n" |
| 16342 | "Connection: keep-alive\r\n" |
| 16343 | "Content-Length: 3\r\n\r\n"), |
| 16344 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16345 | }; |
| 16346 | |
| 16347 | MockRead data_reads[] = { |
| 16348 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 16349 | MockRead("HTTP/1.0 302 Redirect\r\n"), |
| 16350 | MockRead("Location: http://somewhere-else.com/\r\n"), |
| 16351 | MockRead("Content-Length: 0\r\n\r\n"), |
| 16352 | MockRead(SYNCHRONOUS, OK), |
| 16353 | }; |
| 16354 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16355 | arraysize(data_writes)); |
| 16356 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16357 | |
| 16358 | TestCompletionCallback callback; |
| 16359 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16360 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16361 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16362 | |
| 16363 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16364 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16365 | } |
| 16366 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16367 | TEST_F(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16368 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16369 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16370 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16371 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16372 | |
| 16373 | HttpRequestInfo request; |
| 16374 | request.method = "POST"; |
| 16375 | request.url = GURL("http://www.foo.com/"); |
| 16376 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16377 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16378 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16379 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16380 | // Send headers successfully, but get an error while sending the body. |
| 16381 | MockWrite data_writes[] = { |
| 16382 | MockWrite("POST / HTTP/1.1\r\n" |
| 16383 | "Host: www.foo.com\r\n" |
| 16384 | "Connection: keep-alive\r\n" |
| 16385 | "Content-Length: 3\r\n\r\n"), |
| 16386 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16387 | }; |
| 16388 | |
| 16389 | MockRead data_reads[] = { |
| 16390 | MockRead("HTTP 0.9 rocks!"), |
| 16391 | MockRead(SYNCHRONOUS, OK), |
| 16392 | }; |
| 16393 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16394 | arraysize(data_writes)); |
| 16395 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16396 | |
| 16397 | TestCompletionCallback callback; |
| 16398 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16399 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16400 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16401 | |
| 16402 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16403 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16404 | } |
| 16405 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16406 | TEST_F(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16407 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16408 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16409 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16410 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16411 | |
| 16412 | HttpRequestInfo request; |
| 16413 | request.method = "POST"; |
| 16414 | request.url = GURL("http://www.foo.com/"); |
| 16415 | request.upload_data_stream = &upload_data_stream; |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16416 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16417 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16418 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16419 | // Send headers successfully, but get an error while sending the body. |
| 16420 | MockWrite data_writes[] = { |
| 16421 | MockWrite("POST / HTTP/1.1\r\n" |
| 16422 | "Host: www.foo.com\r\n" |
| 16423 | "Connection: keep-alive\r\n" |
| 16424 | "Content-Length: 3\r\n\r\n"), |
| 16425 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16426 | }; |
| 16427 | |
| 16428 | MockRead data_reads[] = { |
| 16429 | MockRead("HTTP/1.0 400 Not a Full Response\r\n"), |
| 16430 | MockRead(SYNCHRONOUS, OK), |
| 16431 | }; |
| 16432 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16433 | arraysize(data_writes)); |
| 16434 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16435 | |
| 16436 | TestCompletionCallback callback; |
| 16437 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16438 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16439 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16440 | |
| 16441 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16442 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16443 | } |
| 16444 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16445 | // Verify that proxy headers are not sent to the destination server when |
| 16446 | // establishing a tunnel for a secure WebSocket connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16447 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWssTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16448 | HttpRequestInfo request; |
| 16449 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16450 | request.url = GURL("wss://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16451 | AddWebSocketHeaders(&request.extra_headers); |
| 16452 | |
| 16453 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 16454 | session_deps_.proxy_service = |
| 16455 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16456 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16457 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16458 | |
| 16459 | // Since a proxy is configured, try to establish a tunnel. |
| 16460 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16461 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 16462 | "Host: www.example.org:443\r\n" |
| 16463 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16464 | |
| 16465 | // After calling trans->RestartWithAuth(), this is the request we should |
| 16466 | // be issuing -- the final header line contains the credentials. |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16467 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 16468 | "Host: www.example.org:443\r\n" |
| 16469 | "Proxy-Connection: keep-alive\r\n" |
| 16470 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16471 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16472 | MockWrite("GET / HTTP/1.1\r\n" |
| 16473 | "Host: www.example.org\r\n" |
| 16474 | "Connection: Upgrade\r\n" |
| 16475 | "Upgrade: websocket\r\n" |
| 16476 | "Origin: http://www.example.org\r\n" |
| 16477 | "Sec-WebSocket-Version: 13\r\n" |
| 16478 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16479 | }; |
| 16480 | |
| 16481 | // The proxy responds to the connect with a 407, using a persistent |
| 16482 | // connection. |
| 16483 | MockRead data_reads[] = { |
| 16484 | // No credentials. |
| 16485 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 16486 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 16487 | MockRead("Content-Length: 0\r\n"), |
| 16488 | MockRead("Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16489 | |
| 16490 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 16491 | |
| 16492 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 16493 | MockRead("Upgrade: websocket\r\n"), |
| 16494 | MockRead("Connection: Upgrade\r\n"), |
| 16495 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 16496 | }; |
| 16497 | |
| 16498 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16499 | arraysize(data_writes)); |
| 16500 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16501 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 16502 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16503 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16504 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16505 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16506 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 16507 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 16508 | &websocket_stream_create_helper); |
| 16509 | |
| 16510 | { |
| 16511 | TestCompletionCallback callback; |
| 16512 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16513 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16514 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16515 | |
| 16516 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16517 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16518 | } |
| 16519 | |
| 16520 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 16521 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16522 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16523 | EXPECT_EQ(407, response->headers->response_code()); |
| 16524 | |
| 16525 | { |
| 16526 | TestCompletionCallback callback; |
| 16527 | |
| 16528 | int rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 16529 | callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16530 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16531 | |
| 16532 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16533 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16534 | } |
| 16535 | |
| 16536 | response = trans->GetResponseInfo(); |
| 16537 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16538 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16539 | |
| 16540 | EXPECT_EQ(101, response->headers->response_code()); |
| 16541 | |
| 16542 | trans.reset(); |
| 16543 | session->CloseAllConnections(); |
| 16544 | } |
| 16545 | |
| 16546 | // Verify that proxy headers are not sent to the destination server when |
| 16547 | // establishing a tunnel for an insecure WebSocket connection. |
| 16548 | // This requires the authentication info to be injected into the auth cache |
| 16549 | // due to crbug.com/395064 |
| 16550 | // TODO(ricea): Change to use a 407 response once issue 395064 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16551 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWsTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16552 | HttpRequestInfo request; |
| 16553 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16554 | request.url = GURL("ws://www.example.org/"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16555 | AddWebSocketHeaders(&request.extra_headers); |
| 16556 | |
| 16557 | // Configure against proxy server "myproxy:70". |
rdsmith | 82957ad | 2015-09-16 19:42:03 | [diff] [blame] | 16558 | session_deps_.proxy_service = |
| 16559 | ProxyService::CreateFixedFromPacResult("PROXY myproxy:70"); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16560 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16561 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16562 | |
| 16563 | MockWrite data_writes[] = { |
| 16564 | // Try to establish a tunnel for the WebSocket connection, with |
| 16565 | // credentials. Because WebSockets have a separate set of socket pools, |
| 16566 | // they cannot and will not use the same TCP/IP connection as the |
| 16567 | // preflight HTTP request. |
| 16568 | MockWrite( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16569 | "CONNECT www.example.org:80 HTTP/1.1\r\n" |
| 16570 | "Host: www.example.org:80\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16571 | "Proxy-Connection: keep-alive\r\n" |
| 16572 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 16573 | |
| 16574 | MockWrite( |
| 16575 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16576 | "Host: www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16577 | "Connection: Upgrade\r\n" |
| 16578 | "Upgrade: websocket\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16579 | "Origin: http://www.example.org\r\n" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16580 | "Sec-WebSocket-Version: 13\r\n" |
| 16581 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n\r\n"), |
| 16582 | }; |
| 16583 | |
| 16584 | MockRead data_reads[] = { |
| 16585 | // HTTP CONNECT with credentials. |
| 16586 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 16587 | |
| 16588 | // WebSocket connection established inside tunnel. |
| 16589 | MockRead("HTTP/1.1 101 Switching Protocols\r\n"), |
| 16590 | MockRead("Upgrade: websocket\r\n"), |
| 16591 | MockRead("Connection: Upgrade\r\n"), |
| 16592 | MockRead("Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n"), |
| 16593 | }; |
| 16594 | |
| 16595 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16596 | arraysize(data_writes)); |
| 16597 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16598 | |
| 16599 | session->http_auth_cache()->Add( |
| 16600 | GURL("http://myproxy:70/"), "MyRealm1", HttpAuth::AUTH_SCHEME_BASIC, |
| 16601 | "Basic realm=MyRealm1", AuthCredentials(kFoo, kBar), "/"); |
| 16602 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16603 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16604 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16605 | FakeWebSocketStreamCreateHelper websocket_stream_create_helper; |
| 16606 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 16607 | &websocket_stream_create_helper); |
| 16608 | |
| 16609 | TestCompletionCallback callback; |
| 16610 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16611 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16612 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16613 | |
| 16614 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16615 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16616 | |
| 16617 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 16618 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16619 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16620 | |
| 16621 | EXPECT_EQ(101, response->headers->response_code()); |
| 16622 | |
| 16623 | trans.reset(); |
| 16624 | session->CloseAllConnections(); |
| 16625 | } |
| 16626 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16627 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16628 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16629 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16630 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16631 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16632 | |
| 16633 | HttpRequestInfo request; |
| 16634 | request.method = "POST"; |
| 16635 | request.url = GURL("http://www.foo.com/"); |
| 16636 | request.upload_data_stream = &upload_data_stream; |
| 16637 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16638 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16639 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16640 | MockWrite data_writes[] = { |
| 16641 | MockWrite("POST / HTTP/1.1\r\n" |
| 16642 | "Host: www.foo.com\r\n" |
| 16643 | "Connection: keep-alive\r\n" |
| 16644 | "Content-Length: 3\r\n\r\n"), |
| 16645 | MockWrite("foo"), |
| 16646 | }; |
| 16647 | |
| 16648 | MockRead data_reads[] = { |
| 16649 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16650 | MockRead(SYNCHRONOUS, OK), |
| 16651 | }; |
| 16652 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16653 | arraysize(data_writes)); |
| 16654 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16655 | |
| 16656 | TestCompletionCallback callback; |
| 16657 | |
| 16658 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16659 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16660 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16661 | |
| 16662 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16663 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16664 | |
| 16665 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16666 | trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16667 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16668 | trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16669 | } |
| 16670 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16671 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost100Continue) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16672 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16673 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16674 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16675 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16676 | |
| 16677 | HttpRequestInfo request; |
| 16678 | request.method = "POST"; |
| 16679 | request.url = GURL("http://www.foo.com/"); |
| 16680 | request.upload_data_stream = &upload_data_stream; |
| 16681 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16682 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16683 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16684 | MockWrite data_writes[] = { |
| 16685 | MockWrite("POST / HTTP/1.1\r\n" |
| 16686 | "Host: www.foo.com\r\n" |
| 16687 | "Connection: keep-alive\r\n" |
| 16688 | "Content-Length: 3\r\n\r\n"), |
| 16689 | MockWrite("foo"), |
| 16690 | }; |
| 16691 | |
| 16692 | MockRead data_reads[] = { |
| 16693 | MockRead("HTTP/1.1 100 Continue\r\n\r\n"), |
| 16694 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16695 | MockRead(SYNCHRONOUS, OK), |
| 16696 | }; |
| 16697 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16698 | arraysize(data_writes)); |
| 16699 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16700 | |
| 16701 | TestCompletionCallback callback; |
| 16702 | |
| 16703 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16704 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16705 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16706 | |
| 16707 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16708 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16709 | |
| 16710 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16711 | trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16712 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16713 | trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16714 | } |
| 16715 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16716 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesChunkedPost) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16717 | ChunkedUploadDataStream upload_data_stream(0); |
| 16718 | |
| 16719 | HttpRequestInfo request; |
| 16720 | request.method = "POST"; |
| 16721 | request.url = GURL("http://www.foo.com/"); |
| 16722 | request.upload_data_stream = &upload_data_stream; |
| 16723 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16724 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16725 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16726 | // Send headers successfully, but get an error while sending the body. |
| 16727 | MockWrite data_writes[] = { |
| 16728 | MockWrite("POST / HTTP/1.1\r\n" |
| 16729 | "Host: www.foo.com\r\n" |
| 16730 | "Connection: keep-alive\r\n" |
| 16731 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 16732 | MockWrite("1\r\nf\r\n"), MockWrite("2\r\noo\r\n"), MockWrite("0\r\n\r\n"), |
| 16733 | }; |
| 16734 | |
| 16735 | MockRead data_reads[] = { |
| 16736 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16737 | MockRead(SYNCHRONOUS, OK), |
| 16738 | }; |
| 16739 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 16740 | arraysize(data_writes)); |
| 16741 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16742 | |
| 16743 | TestCompletionCallback callback; |
| 16744 | |
| 16745 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16746 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16747 | |
| 16748 | base::RunLoop().RunUntilIdle(); |
| 16749 | upload_data_stream.AppendData("f", 1, false); |
| 16750 | |
| 16751 | base::RunLoop().RunUntilIdle(); |
| 16752 | upload_data_stream.AppendData("oo", 2, true); |
| 16753 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16754 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16755 | |
| 16756 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16757 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16758 | |
| 16759 | EXPECT_EQ(CountWriteBytes(data_writes, arraysize(data_writes)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16760 | trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16761 | EXPECT_EQ(CountReadBytes(data_reads, arraysize(data_reads)), |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16762 | trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 16763 | } |
| 16764 | |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16765 | // Confirm that transactions whose throttle is created in (and stays in) |
| 16766 | // the unthrottled state are not blocked. |
| 16767 | TEST_F(HttpNetworkTransactionTest, ThrottlingUnthrottled) { |
| 16768 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16769 | std::unique_ptr<HttpNetworkSession> session( |
| 16770 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16771 | |
| 16772 | // Send a simple request and make sure it goes through. |
| 16773 | HttpRequestInfo request; |
| 16774 | request.method = "GET"; |
| 16775 | request.url = GURL("http://www.example.org/"); |
| 16776 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16777 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16778 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16779 | |
| 16780 | MockWrite data_writes[] = { |
| 16781 | MockWrite("GET / HTTP/1.1\r\n" |
| 16782 | "Host: www.example.org\r\n" |
| 16783 | "Connection: keep-alive\r\n\r\n"), |
| 16784 | }; |
| 16785 | MockRead data_reads[] = { |
| 16786 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16787 | MockRead(SYNCHRONOUS, OK), |
| 16788 | }; |
| 16789 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16790 | arraysize(data_writes)); |
| 16791 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16792 | |
| 16793 | TestCompletionCallback callback; |
| 16794 | trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16795 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 16796 | } |
| 16797 | |
| 16798 | // Confirm requests can be blocked by a throttler, and are resumed |
| 16799 | // when the throttle is unblocked. |
| 16800 | TEST_F(HttpNetworkTransactionTest, ThrottlingBasic) { |
| 16801 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16802 | std::unique_ptr<HttpNetworkSession> session( |
| 16803 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16804 | |
| 16805 | // Send a simple request and make sure it goes through. |
| 16806 | HttpRequestInfo request; |
| 16807 | request.method = "GET"; |
| 16808 | request.url = GURL("http://www.example.org/"); |
| 16809 | |
| 16810 | MockWrite data_writes[] = { |
| 16811 | MockWrite("GET / HTTP/1.1\r\n" |
| 16812 | "Host: www.example.org\r\n" |
| 16813 | "Connection: keep-alive\r\n\r\n"), |
| 16814 | }; |
| 16815 | MockRead data_reads[] = { |
| 16816 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16817 | MockRead(SYNCHRONOUS, OK), |
| 16818 | }; |
| 16819 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16820 | arraysize(data_writes)); |
| 16821 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16822 | |
| 16823 | // Start a request that will be throttled at start; confirm it |
| 16824 | // doesn't complete. |
| 16825 | throttler->set_throttle_new_requests(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16826 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16827 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16828 | |
| 16829 | TestCompletionCallback callback; |
| 16830 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16831 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16832 | |
| 16833 | base::RunLoop().RunUntilIdle(); |
| 16834 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 16835 | EXPECT_FALSE(callback.have_result()); |
| 16836 | |
| 16837 | // Confirm the request goes on to complete when unthrottled. |
| 16838 | throttler->UnthrottleAllRequests(); |
| 16839 | base::RunLoop().RunUntilIdle(); |
| 16840 | ASSERT_TRUE(callback.have_result()); |
| 16841 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 16842 | } |
| 16843 | |
| 16844 | // Destroy a request while it's throttled. |
| 16845 | TEST_F(HttpNetworkTransactionTest, ThrottlingDestruction) { |
| 16846 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16847 | std::unique_ptr<HttpNetworkSession> session( |
| 16848 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16849 | |
| 16850 | // Send a simple request and make sure it goes through. |
| 16851 | HttpRequestInfo request; |
| 16852 | request.method = "GET"; |
| 16853 | request.url = GURL("http://www.example.org/"); |
| 16854 | |
| 16855 | MockWrite data_writes[] = { |
| 16856 | MockWrite("GET / HTTP/1.1\r\n" |
| 16857 | "Host: www.example.org\r\n" |
| 16858 | "Connection: keep-alive\r\n\r\n"), |
| 16859 | }; |
| 16860 | MockRead data_reads[] = { |
| 16861 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16862 | MockRead(SYNCHRONOUS, OK), |
| 16863 | }; |
| 16864 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16865 | arraysize(data_writes)); |
| 16866 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16867 | |
| 16868 | // Start a request that will be throttled at start; confirm it |
| 16869 | // doesn't complete. |
| 16870 | throttler->set_throttle_new_requests(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16871 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16872 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16873 | |
| 16874 | TestCompletionCallback callback; |
| 16875 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16876 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16877 | |
| 16878 | base::RunLoop().RunUntilIdle(); |
| 16879 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 16880 | EXPECT_FALSE(callback.have_result()); |
| 16881 | |
| 16882 | EXPECT_EQ(1u, throttler->num_outstanding_requests()); |
| 16883 | trans.reset(); |
| 16884 | EXPECT_EQ(0u, throttler->num_outstanding_requests()); |
| 16885 | } |
| 16886 | |
| 16887 | // Confirm the throttler receives SetPriority calls. |
| 16888 | TEST_F(HttpNetworkTransactionTest, ThrottlingPrioritySet) { |
| 16889 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16890 | std::unique_ptr<HttpNetworkSession> session( |
| 16891 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16892 | |
| 16893 | // Send a simple request and make sure it goes through. |
| 16894 | HttpRequestInfo request; |
| 16895 | request.method = "GET"; |
| 16896 | request.url = GURL("http://www.example.org/"); |
| 16897 | |
| 16898 | MockWrite data_writes[] = { |
| 16899 | MockWrite("GET / HTTP/1.1\r\n" |
| 16900 | "Host: www.example.org\r\n" |
| 16901 | "Connection: keep-alive\r\n\r\n"), |
| 16902 | }; |
| 16903 | MockRead data_reads[] = { |
| 16904 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16905 | MockRead(SYNCHRONOUS, OK), |
| 16906 | }; |
| 16907 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16908 | arraysize(data_writes)); |
| 16909 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16910 | |
| 16911 | throttler->set_throttle_new_requests(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16912 | auto trans = std::make_unique<HttpNetworkTransaction>(IDLE, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16913 | // Start the transaction to associate a throttle with it. |
| 16914 | TestCompletionCallback callback; |
| 16915 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16916 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16917 | |
| 16918 | EXPECT_EQ(0, throttler->num_set_priority_calls()); |
| 16919 | trans->SetPriority(LOW); |
| 16920 | EXPECT_EQ(1, throttler->num_set_priority_calls()); |
| 16921 | EXPECT_EQ(LOW, throttler->last_priority_set()); |
| 16922 | |
| 16923 | throttler->UnthrottleAllRequests(); |
| 16924 | base::RunLoop().RunUntilIdle(); |
| 16925 | ASSERT_TRUE(callback.have_result()); |
| 16926 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 16927 | } |
| 16928 | |
| 16929 | // Confirm that unthrottling from a SetPriority call by the |
| 16930 | // throttler works properly. |
| 16931 | TEST_F(HttpNetworkTransactionTest, ThrottlingPrioritySetUnthrottle) { |
| 16932 | TestNetworkStreamThrottler* throttler(nullptr); |
| 16933 | std::unique_ptr<HttpNetworkSession> session( |
| 16934 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 16935 | |
| 16936 | // Send a simple request and make sure it goes through. |
| 16937 | HttpRequestInfo request; |
| 16938 | request.method = "GET"; |
| 16939 | request.url = GURL("http://www.example.org/"); |
| 16940 | |
| 16941 | MockWrite data_writes[] = { |
| 16942 | MockWrite("GET / HTTP/1.1\r\n" |
| 16943 | "Host: www.example.org\r\n" |
| 16944 | "Connection: keep-alive\r\n\r\n"), |
| 16945 | }; |
| 16946 | MockRead data_reads[] = { |
| 16947 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 16948 | MockRead(SYNCHRONOUS, OK), |
| 16949 | }; |
| 16950 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 16951 | arraysize(data_writes)); |
| 16952 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 16953 | |
| 16954 | StaticSocketDataProvider reads1(data_reads, arraysize(data_reads), |
| 16955 | data_writes, arraysize(data_writes)); |
| 16956 | session_deps_.socket_factory->AddSocketDataProvider(&reads1); |
| 16957 | |
| 16958 | // Start a request that will be throttled at start; confirm it |
| 16959 | // doesn't complete. |
| 16960 | throttler->set_throttle_new_requests(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16961 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16962 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16963 | |
| 16964 | TestCompletionCallback callback; |
| 16965 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 16966 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16967 | |
| 16968 | base::RunLoop().RunUntilIdle(); |
| 16969 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 16970 | EXPECT_FALSE(callback.have_result()); |
| 16971 | |
| 16972 | // Create a new request, call SetPriority on it to unthrottle, |
| 16973 | // and make sure that allows the original request to complete. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16974 | auto trans1 = std::make_unique<HttpNetworkTransaction>(LOW, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16975 | throttler->set_priority_change_closure( |
| 16976 | base::Bind(&TestNetworkStreamThrottler::UnthrottleAllRequests, |
| 16977 | base::Unretained(throttler))); |
| 16978 | |
| 16979 | // Start the transaction to associate a throttle with it. |
| 16980 | TestCompletionCallback callback1; |
| 16981 | rv = trans1->Start(&request, callback1.callback(), NetLogWithSource()); |
| 16982 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 16983 | |
| 16984 | trans1->SetPriority(IDLE); |
| 16985 | |
| 16986 | base::RunLoop().RunUntilIdle(); |
| 16987 | ASSERT_TRUE(callback.have_result()); |
| 16988 | EXPECT_EQ(OK, callback.WaitForResult()); |
| 16989 | ASSERT_TRUE(callback1.have_result()); |
| 16990 | EXPECT_EQ(OK, callback1.WaitForResult()); |
| 16991 | } |
| 16992 | |
| 16993 | // Transaction will be destroyed when the unique_ptr goes out of scope. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16994 | void DestroyTransaction(std::unique_ptr<HttpNetworkTransaction> transaction) {} |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 16995 | |
| 16996 | // Confirm that destroying a transaction from a SetPriority call by the |
| 16997 | // throttler works properly. |
| 16998 | TEST_F(HttpNetworkTransactionTest, ThrottlingPrioritySetDestroy) { |
| 16999 | TestNetworkStreamThrottler* throttler(nullptr); |
| 17000 | std::unique_ptr<HttpNetworkSession> session( |
| 17001 | CreateSessionWithThrottler(&session_deps_, &throttler)); |
| 17002 | |
| 17003 | // Send a simple request and make sure it goes through. |
| 17004 | HttpRequestInfo request; |
| 17005 | request.method = "GET"; |
| 17006 | request.url = GURL("http://www.example.org/"); |
| 17007 | |
| 17008 | MockWrite data_writes[] = { |
| 17009 | MockWrite("GET / HTTP/1.1\r\n" |
| 17010 | "Host: www.example.org\r\n" |
| 17011 | "Connection: keep-alive\r\n\r\n"), |
| 17012 | }; |
| 17013 | MockRead data_reads[] = { |
| 17014 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17015 | MockRead(SYNCHRONOUS, OK), |
| 17016 | }; |
| 17017 | StaticSocketDataProvider reads(data_reads, arraysize(data_reads), data_writes, |
| 17018 | arraysize(data_writes)); |
| 17019 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 17020 | |
| 17021 | StaticSocketDataProvider reads1(data_reads, arraysize(data_reads), |
| 17022 | data_writes, arraysize(data_writes)); |
| 17023 | session_deps_.socket_factory->AddSocketDataProvider(&reads1); |
| 17024 | |
| 17025 | // Start a request that will be throttled at start; confirm it |
| 17026 | // doesn't complete. |
| 17027 | throttler->set_throttle_new_requests(true); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17028 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17029 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17030 | |
| 17031 | TestCompletionCallback callback; |
| 17032 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 17033 | EXPECT_EQ(ERR_IO_PENDING, rv); |
| 17034 | |
| 17035 | base::RunLoop().RunUntilIdle(); |
| 17036 | EXPECT_EQ(LOAD_STATE_THROTTLED, trans->GetLoadState()); |
| 17037 | EXPECT_FALSE(callback.have_result()); |
| 17038 | |
| 17039 | // Arrange for the set priority call on the above transaction to delete |
| 17040 | // the transaction. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17041 | HttpNetworkTransaction* trans_ptr(trans.get()); |
rdsmith | 1d343be5 | 2016-10-21 20:37:50 | [diff] [blame] | 17042 | throttler->set_priority_change_closure( |
| 17043 | base::Bind(&DestroyTransaction, base::Passed(&trans))); |
| 17044 | |
| 17045 | // Call it and check results (partially a "doesn't crash" test). |
| 17046 | trans_ptr->SetPriority(IDLE); |
| 17047 | trans_ptr = nullptr; // No longer a valid pointer. |
| 17048 | |
| 17049 | base::RunLoop().RunUntilIdle(); |
| 17050 | ASSERT_FALSE(callback.have_result()); |
| 17051 | } |
| 17052 | |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17053 | #if !defined(OS_IOS) |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17054 | TEST_F(HttpNetworkTransactionTest, TokenBindingSpdy) { |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17055 | const std::string https_url = "https://www.example.com"; |
| 17056 | HttpRequestInfo request; |
| 17057 | request.url = GURL(https_url); |
| 17058 | request.method = "GET"; |
| 17059 | |
| 17060 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 17061 | ssl.token_binding_negotiated = true; |
| 17062 | ssl.token_binding_key_param = TB_PARAM_ECDSAP256; |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 17063 | ssl.next_proto = kProtoHTTP2; |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17064 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 17065 | |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 17066 | SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 17067 | SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 17068 | MockRead reads[] = {CreateMockRead(resp), CreateMockRead(body), |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17069 | MockRead(ASYNC, ERR_IO_PENDING)}; |
| 17070 | StaticSocketDataProvider data(reads, arraysize(reads), nullptr, 0); |
| 17071 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17072 | session_deps_.channel_id_service = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17073 | std::make_unique<ChannelIDService>(new DefaultChannelIDStore(nullptr)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17074 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17075 | |
| 17076 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17077 | TestCompletionCallback callback; |
| 17078 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17079 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
fdoray | f33fede | 2017-05-11 21:18:10 | [diff] [blame] | 17080 | |
| 17081 | NetTestSuite::GetScopedTaskEnvironment()->RunUntilIdle(); |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17082 | |
| 17083 | EXPECT_TRUE(trans.GetResponseInfo()->was_fetched_via_spdy); |
| 17084 | HttpRequestHeaders headers; |
| 17085 | ASSERT_TRUE(trans.GetFullRequestHeaders(&headers)); |
| 17086 | EXPECT_TRUE(headers.HasHeader(HttpRequestHeaders::kTokenBinding)); |
| 17087 | } |
| 17088 | #endif // !defined(OS_IOS) |
| 17089 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17090 | void CheckContentEncodingMatching(SpdySessionDependencies* session_deps, |
| 17091 | const std::string& accept_encoding, |
| 17092 | const std::string& content_encoding, |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17093 | const std::string& location, |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17094 | bool should_match) { |
| 17095 | HttpRequestInfo request; |
| 17096 | request.method = "GET"; |
| 17097 | request.url = GURL("http://www.foo.com/"); |
| 17098 | request.extra_headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, |
| 17099 | accept_encoding); |
| 17100 | |
| 17101 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps)); |
| 17102 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17103 | // Send headers successfully, but get an error while sending the body. |
| 17104 | MockWrite data_writes[] = { |
| 17105 | MockWrite("GET / HTTP/1.1\r\n" |
| 17106 | "Host: www.foo.com\r\n" |
| 17107 | "Connection: keep-alive\r\n" |
| 17108 | "Accept-Encoding: "), |
| 17109 | MockWrite(accept_encoding.data()), MockWrite("\r\n\r\n"), |
| 17110 | }; |
| 17111 | |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17112 | std::string response_code = "200 OK"; |
| 17113 | std::string extra; |
| 17114 | if (!location.empty()) { |
| 17115 | response_code = "301 Redirect\r\nLocation: "; |
| 17116 | response_code.append(location); |
| 17117 | } |
| 17118 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17119 | MockRead data_reads[] = { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17120 | MockRead("HTTP/1.0 "), |
| 17121 | MockRead(response_code.data()), |
| 17122 | MockRead("\r\nContent-Encoding: "), |
| 17123 | MockRead(content_encoding.data()), |
| 17124 | MockRead("\r\n\r\n"), |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17125 | MockRead(SYNCHRONOUS, OK), |
| 17126 | }; |
| 17127 | StaticSocketDataProvider data(data_reads, arraysize(data_reads), data_writes, |
| 17128 | arraysize(data_writes)); |
| 17129 | session_deps->socket_factory->AddSocketDataProvider(&data); |
| 17130 | |
| 17131 | TestCompletionCallback callback; |
| 17132 | |
| 17133 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17134 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17135 | |
| 17136 | rv = callback.WaitForResult(); |
| 17137 | if (should_match) { |
| 17138 | EXPECT_THAT(rv, IsOk()); |
| 17139 | } else { |
| 17140 | EXPECT_THAT(rv, IsError(ERR_CONTENT_DECODING_FAILED)); |
| 17141 | } |
| 17142 | } |
| 17143 | |
| 17144 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding1) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17145 | CheckContentEncodingMatching(&session_deps_, "gzip,sdch", "br", "", false); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17146 | } |
| 17147 | |
| 17148 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding2) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17149 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "", "", |
| 17150 | true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17151 | } |
| 17152 | |
| 17153 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding3) { |
| 17154 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17155 | "", false); |
| 17156 | } |
| 17157 | |
| 17158 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding4) { |
| 17159 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
| 17160 | "www.foo.com/other", true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17161 | } |
| 17162 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17163 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsSync) { |
| 17164 | ProxyConfig proxy_config; |
| 17165 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 17166 | proxy_config.set_pac_mandatory(true); |
| 17167 | MockAsyncProxyResolver resolver; |
| 17168 | session_deps_.proxy_service.reset(new ProxyService( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17169 | std::make_unique<ProxyConfigServiceFixed>(proxy_config), |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17170 | base::WrapUnique(new FailingProxyResolverFactory), nullptr)); |
| 17171 | |
| 17172 | HttpRequestInfo request; |
| 17173 | request.method = "GET"; |
| 17174 | request.url = GURL("http://www.example.org/"); |
| 17175 | |
| 17176 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 17177 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17178 | |
| 17179 | TestCompletionCallback callback; |
| 17180 | |
| 17181 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17182 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17183 | EXPECT_THAT(callback.WaitForResult(), |
| 17184 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 17185 | } |
| 17186 | |
| 17187 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsAsync) { |
| 17188 | ProxyConfig proxy_config; |
| 17189 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 17190 | proxy_config.set_pac_mandatory(true); |
| 17191 | MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 17192 | new MockAsyncProxyResolverFactory(false); |
| 17193 | MockAsyncProxyResolver resolver; |
| 17194 | session_deps_.proxy_service.reset( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17195 | new ProxyService(std::make_unique<ProxyConfigServiceFixed>(proxy_config), |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17196 | base::WrapUnique(proxy_resolver_factory), nullptr)); |
| 17197 | HttpRequestInfo request; |
| 17198 | request.method = "GET"; |
| 17199 | request.url = GURL("http://www.example.org/"); |
| 17200 | |
| 17201 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 17202 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17203 | |
| 17204 | TestCompletionCallback callback; |
| 17205 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17206 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17207 | |
| 17208 | proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder( |
| 17209 | ERR_FAILED, &resolver); |
| 17210 | EXPECT_THAT(callback.WaitForResult(), |
| 17211 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 17212 | } |
| 17213 | |
| 17214 | TEST_F(HttpNetworkTransactionTest, NoSupportedProxies) { |
| 17215 | session_deps_.proxy_service = |
| 17216 | ProxyService::CreateFixedFromPacResult("QUIC myproxy.org:443"); |
| 17217 | session_deps_.enable_quic = false; |
| 17218 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 17219 | |
| 17220 | HttpRequestInfo request; |
| 17221 | request.method = "GET"; |
| 17222 | request.url = GURL("http://www.example.org/"); |
| 17223 | |
| 17224 | TestCompletionCallback callback; |
| 17225 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17226 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17227 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17228 | |
| 17229 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_NO_SUPPORTED_PROXIES)); |
| 17230 | } |
| 17231 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 17232 | } // namespace net |